-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgtthread.h
More file actions
79 lines (61 loc) · 2.31 KB
/
Copy pathgtthread.h
File metadata and controls
79 lines (61 loc) · 2.31 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
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
#ifndef __GTTHREAD_H
#define __GTTHREAD_H
#define gtthread_t unsigned long int
#define STACKSIZELIMIT 40000
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <ucontext.h>
#include <unistd.h>
#include <sys/time.h>
#include <malloc.h>
#include <stdbool.h>
typedef struct gtthread_mutex_t {
long lock;
gtthread_t owner;
} gtthread_mutex_t;
struct gtthread {
int status; /*running = 2, complete = 1, exited = 0, cancel = -1, default = 9*/
gtthread_t tID;
ucontext_t context;
void *retval;
struct gtthread *next;
};
void queue_thread (struct gtthread * t_new);
struct gtthread * unqueue_thread (void);
static void signal_handler (int sig_id);
static void schedule_thread(void *thread_function(), void *arg);
static void run_thread ();
/* 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);
/* 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 */
#endif /* __GTTHREAD_H */