Fixes mmap assertion check
[akaros.git] / user / parlib / include / bthread.h
1 #ifndef _BTHREAD_H
2 #define _BTHREAD_H
3
4 #include <vcore.h>
5 #include <mcs.h>
6
7 #ifdef __cplusplus
8   extern "C" {
9 #endif
10
11 /* Detach state.  */
12 enum
13 {
14   BTHREAD_CREATE_JOINABLE,
15 #define BTHREAD_CREATE_JOINABLE BTHREAD_CREATE_JOINABLE
16   BTHREAD_CREATE_DETACHED
17 #define BTHREAD_CREATE_DETACHED BTHREAD_CREATE_DETACHED
18 };
19
20 struct bthread_wqt
21 {
22   void* (*start_routine)(void*);
23   void* arg;
24   int finished;
25   int detached;
26   struct bthread_wqt* next;
27 };
28
29 typedef struct
30 {
31   int type;
32 } bthread_mutexattr_t;
33
34 typedef struct
35 {
36   const bthread_mutexattr_t* attr;
37   atomic_t lock;
38 } bthread_mutex_t;
39
40 typedef struct
41 {
42   int local_sense[32*MAX_VCORES];
43   volatile int sense;
44   int count;
45   int nprocs;
46   mcs_lock_t lock;
47 } bthread_barrier_t;
48
49 typedef struct
50 {
51   int pshared;
52 } bthread_condattr_t;
53
54 typedef struct
55 {
56   const bthread_condattr_t* attr;
57   uint32_t waiters[MAX_VCORES];
58 } bthread_cond_t;
59
60 typedef struct bthread_wqt work_queue_t;
61 typedef work_queue_t* bthread_t;
62 typedef int bthread_attr_t;
63 typedef int bthread_barrierattr_t;
64 typedef int bthread_once_t;
65 typedef void** bthread_key_t;
66
67 #define BTHREAD_ONCE_INIT 0
68 #define BTHREAD_BARRIER_SERIAL_THREAD 12345
69 #define BTHREAD_MUTEX_INITIALIZER {0}
70 #define BTHREAD_MUTEX_NORMAL 0
71 #define BTHREAD_MUTEX_DEFAULT BTHREAD_MUTEX_NORMAL
72 #define BTHREAD_COND_INITIALIZER {0}
73 #define BTHREAD_PROCESS_PRIVATE 0
74
75 int bthread_attr_init(bthread_attr_t *);
76 int bthread_attr_destroy(bthread_attr_t *);
77 int bthread_create(bthread_t *, const bthread_attr_t *,
78                    void *(*)(void *), void *);
79 int bthread_join(bthread_t, void **);
80
81 int bthread_attr_setdetachstate(bthread_attr_t *__attr,int __detachstate);
82
83 int bthread_mutex_destroy(bthread_mutex_t *);
84 int bthread_mutex_init(bthread_mutex_t *, const bthread_mutexattr_t *);
85 int bthread_mutex_lock(bthread_mutex_t *);
86 int bthread_mutex_trylock(bthread_mutex_t *);
87 int bthread_mutex_unlock(bthread_mutex_t *);
88 int bthread_mutex_destroy(bthread_mutex_t *);
89
90 int bthread_mutexattr_init(bthread_mutexattr_t *);
91 int bthread_mutexattr_destroy(bthread_mutexattr_t *);
92 int bthread_mutexattr_gettype(const bthread_mutexattr_t *, int *);
93 int bthread_mutexattr_settype(bthread_mutexattr_t *, int);
94
95 int bthread_cond_init(bthread_cond_t *, const bthread_condattr_t *);
96 int bthread_cond_destroy(bthread_cond_t *);
97 int bthread_cond_broadcast(bthread_cond_t *);
98 int bthread_cond_signal(bthread_cond_t *);
99 int bthread_cond_wait(bthread_cond_t *, bthread_mutex_t *);
100
101 int bthread_condattr_init(bthread_condattr_t *);
102 int bthread_condattr_destroy(bthread_condattr_t *);
103 int bthread_condattr_setpshared(bthread_condattr_t *, int);
104 int bthread_condattr_getpshared(bthread_condattr_t *, int *);
105
106 #define bthread_rwlock_t bthread_mutex_t
107 #define bthread_rwlockattr_t bthread_mutexattr_t
108 #define bthread_rwlock_destroy bthread_mutex_destroy
109 #define bthread_rwlock_init bthread_mutex_init
110 #define bthread_rwlock_unlock bthread_mutex_unlock
111 #define bthread_rwlock_rdlock bthread_mutex_lock
112 #define bthread_rwlock_wrlock bthread_mutex_lock
113 #define bthread_rwlock_tryrdlock bthread_mutex_trylock
114 #define bthread_rwlock_trywrlock bthread_mutex_trylock
115
116 bthread_t bthread_self();
117 int bthread_equal(bthread_t t1, bthread_t t2);
118 void bthread_exit(void* ret);
119 int bthread_once(bthread_once_t* once_control, void (*init_routine)(void));
120
121 int bthread_barrier_init(bthread_barrier_t* b, const bthread_barrierattr_t* a, int count);
122 int bthread_barrier_wait(bthread_barrier_t* b);
123 int bthread_barrier_destroy(bthread_barrier_t* b);
124
125 #ifdef __cplusplus
126   }
127 #endif
128
129 #endif