-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththread_struct.h
72 lines (54 loc) · 1.58 KB
/
thread_struct.h
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef THREAD_STRUCT_H
#define THREAD_STRUCT_H
#include<setjmp.h>
#include<time.h>
#include<sys/time.h>
#define STACK_SIZE 65536
enum thread_state {RUNNING ,READY , SUSPENDED, FINISHED , CREATED, SLEEPING, BLOCKED_JOIN};
typedef struct statistics
{
//1. thread id
//2. state (running, ready, sleeping, suspended).
//3. number of bursts (none if the thread never ran).
//4. total execution time in msec(N/A if thread never ran).
//5. total requested sleeping time in msec (N/A if thread never slept).
//6. average execution time quantum in msec (N/A if thread never ran).
//7. average waiting time (status = READY) (N/A if thread never ran).
int *thread_id;
enum thread_state *state;
unsigned long long no_of_bursts;
unsigned long long total_exec_time;
unsigned long long total_wait_time;
unsigned long long total_sleep_time;
unsigned long long avg_execution_time ;
unsigned long long avg_waiting_time ;
}statistics;
typedef struct mythread{
int hasContext ;
void (*f) ();
void * (*funcWitharg)(void *);
void * funcArg;
void * retVal;
int hasArgs;
enum thread_state state;
int thread_id;
time_t waketime;
statistics stat;
int blocked_join_on_tid;
struct timeval execution_start_time;
struct timeval wait_start_time;
//char stack[STACK_SIZE];
}mythread;
void init_stats ( mythread * tp ) {
statistics sp;
sp.thread_id = &(tp -> thread_id);
sp.state = &(tp -> state);
sp.no_of_bursts = 0;
sp.total_exec_time = 0;
sp.total_sleep_time = 0 ;
sp.avg_execution_time = 0 ;
sp.avg_waiting_time = 0 ;
sp.total_wait_time =0;
tp -> stat = sp;
}
#endif