forked from YogeshJangir/token-bucket
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken-monitor.c
More file actions
49 lines (47 loc) · 1.54 KB
/
Copy pathtoken-monitor.c
File metadata and controls
49 lines (47 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// warmup2-monitor.c
// Warmup2-new
//
// Created by Abhishek Trigunayat on 6/14/14.
// Copyright (c) 2014 Abhishek Trigunayat. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "mylist.h"
#include <sys/time.h>
#include <unistd.h>
#include <errno.h>
#include "token.h"
#include <signal.h>
#include <math.h>
void * monitor(void * args){
sigwait(&set);
pthread_mutex_lock(&mutex);
struct timeval current_time;
while(!My402ListEmpty(&Q1)){
My402ListElem * temp_element = My402ListLast(&Q1);
My402ListUnlink(&Q1,temp_element);
struct packet * temp_packet = (struct packet *)(temp_element->obj);
gettimeofday(¤t_time, NULL);
printf("%012.3fms: packet p%ld removed from Q1\n",calculate_time_difference(current_time,emulation_start_time),temp_packet->id);
free(temp_packet);
temp_element = NULL;
temp_packet = NULL;
}
while(!My402ListEmpty(&Q2)){
My402ListElem * temp_element = My402ListLast(&Q2);
My402ListUnlink(&Q2,temp_element);
struct packet * temp_packet = (struct packet *)(temp_element->obj);
gettimeofday(¤t_time, NULL);
printf("%012.3fms: packet p%ld removed from Q2\n",calculate_time_difference(current_time,emulation_start_time),temp_packet->id);
free(temp_packet);
temp_element = NULL;
temp_packet = NULL;
}
cntrl_c_signal = 1;
pthread_cond_broadcast(&condition_variable);
pthread_mutex_unlock(&mutex);
return NULL;
}