SYS_notify and SYS_self_notify
[akaros.git] / user / include / pthread.h
1 #ifndef _PTHREAD_H
2 #define _PTHREAD_H
3
4 #include <hart.h>
5
6 #ifdef __cplusplus
7   extern "C" {
8 #endif
9
10 /* Detach state.  */
11 enum
12 {
13   PTHREAD_CREATE_JOINABLE,
14 #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
15   PTHREAD_CREATE_DETACHED
16 #define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
17 };
18
19 struct pthread_wqt
20 {
21   void* (*start_routine)(void*);
22   void* arg;
23   int finished;
24   int detached;
25   struct pthread_wqt* next;
26 };
27
28 typedef struct
29 {
30   int type;
31 } pthread_mutexattr_t;
32
33 typedef struct
34 {
35   const pthread_mutexattr_t* attr;
36   int lock;
37 } pthread_mutex_t;
38
39 typedef struct
40 {
41   int local_sense[32*HART_MAX_MAX_HARTS];
42   volatile int sense;
43   int count;
44   int nprocs;
45   hart_lock_t lock;
46 } pthread_barrier_t;
47
48 typedef struct
49 {
50   int pshared;
51 } pthread_condattr_t;
52
53 typedef struct
54 {
55   const pthread_condattr_t* attr;
56   int waiters[HART_MAX_MAX_HARTS];
57 } pthread_cond_t;
58
59 typedef struct pthread_wqt work_queue_t;
60 typedef work_queue_t* pthread_t;
61 typedef int pthread_attr_t;
62 typedef int pthread_barrierattr_t;
63 typedef int pthread_once_t;
64 typedef void** pthread_key_t;
65
66 #define PTHREAD_ONCE_INIT 0
67 #define PTHREAD_BARRIER_SERIAL_THREAD 12345
68 #define PTHREAD_MUTEX_INITIALIZER {0}
69 #define PTHREAD_MUTEX_NORMAL 0
70 #define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
71 #define PTHREAD_COND_INITIALIZER {0}
72 #define PTHREAD_PROCESS_PRIVATE 0
73
74 int pthread_attr_init(pthread_attr_t *);
75 int pthread_attr_destroy(pthread_attr_t *);
76 int pthread_create(pthread_t *, const pthread_attr_t *,
77                    void *(*)(void *), void *);
78 int pthread_join(pthread_t, void **);
79
80 int pthread_attr_setdetachstate(pthread_attr_t *__attr,int __detachstate);
81
82 int pthread_mutex_destroy(pthread_mutex_t *);
83 int pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *);
84 int pthread_mutex_lock(pthread_mutex_t *);
85 int pthread_mutex_trylock(pthread_mutex_t *);
86 int pthread_mutex_unlock(pthread_mutex_t *);
87 int pthread_mutex_destroy(pthread_mutex_t *);
88
89 int pthread_mutexattr_init(pthread_mutexattr_t *);
90 int pthread_mutexattr_destroy(pthread_mutexattr_t *);
91 int pthread_mutexattr_gettype(const pthread_mutexattr_t *, int *);
92 int pthread_mutexattr_settype(pthread_mutexattr_t *, int);
93
94 int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *);
95 int pthread_cond_destroy(pthread_cond_t *);
96 int pthread_cond_broadcast(pthread_cond_t *);
97 int pthread_cond_signal(pthread_cond_t *);
98 int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
99
100 int pthread_condattr_init(pthread_condattr_t *);
101 int pthread_condattr_destroy(pthread_condattr_t *);
102 int pthread_condattr_setpshared(pthread_condattr_t *, int);
103 int pthread_condattr_getpshared(pthread_condattr_t *, int *);
104
105 #define pthread_rwlock_t pthread_mutex_t
106 #define pthread_rwlockattr_t pthread_mutexattr_t
107 #define pthread_rwlock_destroy pthread_mutex_destroy
108 #define pthread_rwlock_init pthread_mutex_init
109 #define pthread_rwlock_unlock pthread_mutex_unlock
110 #define pthread_rwlock_rdlock pthread_mutex_lock
111 #define pthread_rwlock_wrlock pthread_mutex_lock
112 #define pthread_rwlock_tryrdlock pthread_mutex_trylock
113 #define pthread_rwlock_trywrlock pthread_mutex_trylock
114
115 pthread_t pthread_self();
116 int pthread_equal(pthread_t t1, pthread_t t2);
117 void pthread_exit(void* ret);
118 int pthread_once(pthread_once_t* once_control, void (*init_routine)(void));
119
120 int pthread_barrier_init(pthread_barrier_t* b, const pthread_barrierattr_t* a, int count);
121 int pthread_barrier_wait(pthread_barrier_t* b);
122 int pthread_barrier_destroy(pthread_barrier_t* b);
123
124 #ifdef __cplusplus
125   }
126 #endif
127
128 #endif