-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtthread.h
82 lines (61 loc) · 2.25 KB
/
gtthread.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
73
74
75
76
77
78
79
80
81
82
#ifndef __GTTHREAD_H
#define __GTTHREAD_H
#include "steque.h"
#include <ucontext.h>
/* Must be called before any of the below functions. Failure to do so may
* result in undefined behavior. 'period' is the scheduling quantum (interval)
* in microseconds (i.e., 1/1000000 sec.). */
void gtthread_init(long period);
typedef unsigned long int gtthread_t;
typedef struct gtthread_mutex_t {
long mutex_lock;
gtthread_t mutex_owner;
} gtthread_mutex_t;
/* see man pthread_create(3); the attr parameter is omitted, and this should
* behave as if attr was NULL (i.e., default attributes) */
int gtthread_create(gtthread_t *thread,
void *(*start_routine)(void *),
void *arg);
/* see man pthread_join(3) */
int gtthread_join(gtthread_t thread, void **status);
/* gtthread_detach() does not need to be implemented; all threads should be
* joinable */
/* see man pthread_exit(3) */
void gtthread_exit(void *retval);
/* see man sched_yield(2) */
int gtthread_yield(void);
/* see man pthread_equal(3) */
int gtthread_equal(gtthread_t t1, gtthread_t t2);
/* see man pthread_cancel(3); but deferred cancelation does not need to be
* implemented; all threads are canceled immediately */
int gtthread_cancel(gtthread_t thread);
/* see man pthread_self(3) */
gtthread_t gtthread_self(void);
/* see man pthread_mutex(3); except init does not have the mutexattr parameter,
* and should behave as if mutexattr is NULL (i.e., default attributes); also,
* static initializers do not need to be implemented */
/*int gtthread_mutex_init(gtthread_mutex_t *mutex);
int gtthread_mutex_lock(gtthread_mutex_t *mutex);
int gtthread_mutex_unlock(gtthread_mutex_t *mutex);
*/
/* gtthread_mutex_destroy() and gtthread_mutex_trylock() do not need to be
* implemented */
int gtthread_mutex_init(gtthread_mutex_t *mutex);
int gtthread_mutex_lock(gtthread_mutex_t *mutex);
int gtthread_mutex_unlock(gtthread_mutex_t *mutex);
int gtthread_mutex_destroy(gtthread_mutex_t *mutex);
typedef struct context_node
{
int thread_id;
ucontext_t context;
void * retval;
// int status;
int running;
int completed;
int exited;
int canceled;
}context_node;
extern context_node * current_context;
void blockTmer(void);
void unblockTimer(void);
#endif // __GTTHREAD_H