extensive header cleanup for standards conformance & correctness
[musl] / include / pthread.h
1 #ifndef _PTHREAD_H
2 #define _PTHREAD_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6
7 #define __NEED_time_t
8 #define __NEED_struct_timespec
9 #define __NEED_sigset_t
10 #define __NEED_pthread_t
11 #define __NEED_size_t
12
13 #include <bits/alltypes.h>
14
15 struct sched_param;
16
17 typedef int pthread_once_t, pthread_key_t, pthread_spinlock_t;
18 typedef int pthread_mutexattr_t, pthread_condattr_t, pthread_barrierattr_t;
19
20 typedef struct {
21         size_t __guardsize;
22         size_t __stacksize;
23         unsigned __detach : 1;
24         unsigned __pad : 31;
25         int __attr[6];
26 } pthread_attr_t;
27
28 typedef struct {
29         int __attr[2];
30 } pthread_rwlockattr_t;
31
32 typedef struct {
33         int __type;
34         int __lock;
35         pthread_t __owner;
36         int __pad2;
37         int __waiters;
38         int __pad;
39 } pthread_mutex_t;
40
41 typedef struct {
42         int __block;
43         int __pad[11];
44 } pthread_cond_t;
45
46 typedef struct {
47         int __wrlock;
48         int __readers;
49         int __waiters;
50         int __owner;
51         int __pad[4];
52 } pthread_rwlock_t;
53
54 typedef struct {
55         int __count;
56         int __limit;
57         int __left;
58         int __waiters;
59         int __barrier[1];
60 } pthread_barrier_t;
61
62 #define PTHREAD_CREATE_JOINABLE 0
63 #define PTHREAD_CREATE_DETACHED 1
64
65 #define PTHREAD_MUTEX_NORMAL 0
66 #define PTHREAD_MUTEX_DEFAULT 0
67 #define PTHREAD_MUTEX_RECURSIVE 1
68 #define PTHREAD_MUTEX_ERRORCHECK 2
69
70 #define PTHREAD_MUTEX_STALLED 0
71 #define PTHREAD_MUTEX_ROBUST 1
72
73 #define PTHREAD_PRIO_NONE 0
74 #define PTHREAD_PRIO_INHERIT 1
75 #define PTHREAD_PRIO_PROTECT 2
76
77 #define PTHREAD_INHERIT_SCHED 0
78 #define PTHREAD_EXPLICIT_SCHED 1
79
80 #define PTHREAD_SCOPE_SYSTEM 0
81 #define PTHREAD_SCOPE_PROCESS 1
82
83 #define PTHREAD_PROCESS_PRIVATE 0
84 #define PTHREAD_PROCESS_SHARED 1
85
86
87 #define PTHREAD_MUTEX_INITIALIZER {0}
88 #define PTHREAD_RWLOCK_INITIALIZER {0}
89 #define PTHREAD_COND_INITIALIZER {0}
90 #define PTHREAD_ONCE_INIT 0
91
92
93 #define PTHREAD_CANCEL_ENABLE 0
94 #define PTHREAD_CANCEL_DISABLE 1
95
96 #define PTHREAD_CANCEL_DEFERRED 0
97 #define PTHREAD_CANCEL_ASYNCHRONOUS 1
98
99 #define PTHREAD_CANCELLED ((void *)-1)
100
101
102 #define PTHREAD_BARRIER_SERIAL_THREAD (-1)
103
104
105 int pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *);
106 int pthread_detach(pthread_t);
107 void pthread_exit(void *);
108 int pthread_join(pthread_t, void **);
109
110 pthread_t pthread_self(void);
111 int pthread_equal(pthread_t, pthread_t);
112
113 int pthread_setcancelstate(int, int *);
114 int pthread_setcanceltype(int, int *);
115 void pthread_testcancel(void);
116 int pthread_cancel(pthread_t);
117
118 int pthread_once(pthread_once_t *, void (*)(void));
119
120 int pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *);
121 int pthread_mutex_lock(pthread_mutex_t *);
122 int pthread_mutex_unlock(pthread_mutex_t *);
123 int pthread_mutex_trylock(pthread_mutex_t *);
124 int pthread_mutex_destroy(pthread_mutex_t *);
125
126 int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *);
127 int pthread_cond_destroy(pthread_cond_t *);
128 int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
129 int pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *, const struct timespec *);
130 int pthread_cond_broadcast(pthread_cond_t *);
131 int pthread_cond_signal(pthread_cond_t *);
132
133 int pthread_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *);
134 int pthread_rwlock_destroy(pthread_rwlock_t *);
135 int pthread_rwlock_rdlock(pthread_rwlock_t *);
136 int pthread_rwlock_tryrdlock(pthread_rwlock_t *);
137 int pthread_rwlock_timedrdlock(pthread_rwlock_t *, const struct timespec *);
138 int pthread_rwlock_wrlock(pthread_rwlock_t *);
139 int pthread_rwlock_trywrlock(pthread_rwlock_t *);
140 int pthread_rwlock_timedwrlock(pthread_rwlock_t *, const struct timespec *);
141 int pthread_rwlock_unlock(pthread_rwlock_t *);
142
143 int pthread_spin_init(pthread_spinlock_t *, int);
144 int pthread_spin_destroy(pthread_spinlock_t *);
145 int pthread_spin_lock(pthread_spinlock_t *);
146 int pthread_spin_trylock(pthread_spinlock_t *);
147 int pthread_spin_unlock(pthread_spinlock_t *);
148
149 int pthread_barrier_init(pthread_barrier_t *, const pthread_barrierattr_t *, unsigned);
150 int pthread_barrier_destroy(pthread_barrier_t *);
151 int pthread_barrier_wait(pthread_barrier_t *);
152
153 int pthread_key_create(pthread_key_t *, void (*)(void *));
154 int pthread_key_delete(pthread_key_t);
155 void *pthread_getspecific(pthread_key_t);
156 int pthread_setspecific(pthread_key_t, const void *);
157
158 int pthread_attr_init(pthread_attr_t *);
159 int pthread_attr_destroy(pthread_attr_t *);
160
161 int pthread_attr_getguardsize(pthread_attr_t *, size_t *);
162 int pthread_attr_setguardsize(pthread_attr_t *, size_t);
163 int pthread_attr_getstacksize(pthread_attr_t *, size_t *);
164 int pthread_attr_setstacksize(pthread_attr_t *, size_t);
165 int pthread_attr_getdetachstate(pthread_attr_t *, int *);
166 int pthread_attr_setdetachstate(pthread_attr_t *, int);
167 int pthread_attr_getstack(pthread_attr_t *, void **, size_t *);
168 int pthread_attr_setstack(pthread_attr_t *, void *, size_t);
169 int pthread_attr_getscope(pthread_attr_t *, int *);
170 int pthread_attr_setscope(pthread_attr_t *, int);
171 int pthread_attr_getschedpolicy(pthread_attr_t *, int *);
172 int pthread_attr_setschedpolicy(pthread_attr_t *, int);
173 int pthread_attr_getschedparam(pthread_attr_t *, struct sched_param *);
174 int pthread_attr_setschedparam(pthread_attr_t *, const struct sched_param *);
175 int pthread_attr_getinheritsched(pthread_attr_t *, int *);
176 int pthread_attr_setinheritsched(pthread_attr_t *, int);
177
178 int pthread_mutexattr_destroy(pthread_mutexattr_t *);
179 int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *, int *);
180 int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *, int *);
181 int pthread_mutexattr_getpshared(const pthread_mutexattr_t *, int *);
182 int pthread_mutexattr_getrobust(const pthread_mutexattr_t *, int *);
183 int pthread_mutexattr_gettype(const pthread_mutexattr_t *, int *);
184 int pthread_mutexattr_init(pthread_mutexattr_t *);
185 int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int);
186 int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int);
187 int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
188 int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int);
189 int pthread_mutexattr_settype(pthread_mutexattr_t *, int);
190
191 int pthread_barrierattr_destroy(pthread_barrierattr_t *);
192 int pthread_barrierattr_getpshared(const pthread_barrierattr_t *, int *);
193 int pthread_barrierattr_init(pthread_barrierattr_t *);
194 int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int);
195
196 #include <bits/pthread.h>
197
198 int __setjmp(void *);
199 void __pthread_register_cancel(struct __ptcb *);
200 void __pthread_unregister_cancel(struct __ptcb *);
201 void __pthread_unwind_next(struct __ptcb *);
202
203 #define pthread_cleanup_push(f, x) \
204 do { struct __ptcb __cb; void (*__f)(void *) = (f); void *__x = (x); \
205 if (__setjmp(__cb.__jb)) __f(__x), __pthread_unwind_next(&__cb); \
206 __pthread_register_cancel(&__cb); {
207
208 #define pthread_cleanup_pop(r) ; } \
209 __pthread_unregister_cancel(&__cb); \
210 if (r) __f(__x); } while (0)
211
212
213 #ifdef __cplusplus
214 }
215 #endif
216 #endif