xref: /aosp_15_r20/external/musl/include/pthread.h (revision c9945492fdd68bbe62686c5b452b4dc1be3f8453)
1*c9945492SAndroid Build Coastguard Worker #ifndef _PTHREAD_H
2*c9945492SAndroid Build Coastguard Worker #define _PTHREAD_H
3*c9945492SAndroid Build Coastguard Worker #ifdef __cplusplus
4*c9945492SAndroid Build Coastguard Worker extern "C" {
5*c9945492SAndroid Build Coastguard Worker #endif
6*c9945492SAndroid Build Coastguard Worker 
7*c9945492SAndroid Build Coastguard Worker #include <features.h>
8*c9945492SAndroid Build Coastguard Worker 
9*c9945492SAndroid Build Coastguard Worker #define __NEED_time_t
10*c9945492SAndroid Build Coastguard Worker #define __NEED_clockid_t
11*c9945492SAndroid Build Coastguard Worker #define __NEED_struct_timespec
12*c9945492SAndroid Build Coastguard Worker #define __NEED_sigset_t
13*c9945492SAndroid Build Coastguard Worker #define __NEED_pthread_t
14*c9945492SAndroid Build Coastguard Worker #define __NEED_pthread_attr_t
15*c9945492SAndroid Build Coastguard Worker #define __NEED_pthread_mutexattr_t
16*c9945492SAndroid Build Coastguard Worker #define __NEED_pthread_condattr_t
17*c9945492SAndroid Build Coastguard Worker #define __NEED_pthread_rwlockattr_t
18*c9945492SAndroid Build Coastguard Worker #define __NEED_pthread_barrierattr_t
19*c9945492SAndroid Build Coastguard Worker #define __NEED_pthread_mutex_t
20*c9945492SAndroid Build Coastguard Worker #define __NEED_pthread_cond_t
21*c9945492SAndroid Build Coastguard Worker #define __NEED_pthread_rwlock_t
22*c9945492SAndroid Build Coastguard Worker #define __NEED_pthread_barrier_t
23*c9945492SAndroid Build Coastguard Worker #define __NEED_pthread_spinlock_t
24*c9945492SAndroid Build Coastguard Worker #define __NEED_pthread_key_t
25*c9945492SAndroid Build Coastguard Worker #define __NEED_pthread_once_t
26*c9945492SAndroid Build Coastguard Worker #define __NEED_size_t
27*c9945492SAndroid Build Coastguard Worker 
28*c9945492SAndroid Build Coastguard Worker #include <bits/alltypes.h>
29*c9945492SAndroid Build Coastguard Worker 
30*c9945492SAndroid Build Coastguard Worker #include <sched.h>
31*c9945492SAndroid Build Coastguard Worker #include <time.h>
32*c9945492SAndroid Build Coastguard Worker 
33*c9945492SAndroid Build Coastguard Worker #define PTHREAD_CREATE_JOINABLE 0
34*c9945492SAndroid Build Coastguard Worker #define PTHREAD_CREATE_DETACHED 1
35*c9945492SAndroid Build Coastguard Worker 
36*c9945492SAndroid Build Coastguard Worker #define PTHREAD_MUTEX_NORMAL 0
37*c9945492SAndroid Build Coastguard Worker #define PTHREAD_MUTEX_DEFAULT 0
38*c9945492SAndroid Build Coastguard Worker #define PTHREAD_MUTEX_RECURSIVE 1
39*c9945492SAndroid Build Coastguard Worker #define PTHREAD_MUTEX_ERRORCHECK 2
40*c9945492SAndroid Build Coastguard Worker 
41*c9945492SAndroid Build Coastguard Worker #define PTHREAD_MUTEX_STALLED 0
42*c9945492SAndroid Build Coastguard Worker #define PTHREAD_MUTEX_ROBUST 1
43*c9945492SAndroid Build Coastguard Worker 
44*c9945492SAndroid Build Coastguard Worker #define PTHREAD_PRIO_NONE 0
45*c9945492SAndroid Build Coastguard Worker #define PTHREAD_PRIO_INHERIT 1
46*c9945492SAndroid Build Coastguard Worker #define PTHREAD_PRIO_PROTECT 2
47*c9945492SAndroid Build Coastguard Worker 
48*c9945492SAndroid Build Coastguard Worker #define PTHREAD_INHERIT_SCHED 0
49*c9945492SAndroid Build Coastguard Worker #define PTHREAD_EXPLICIT_SCHED 1
50*c9945492SAndroid Build Coastguard Worker 
51*c9945492SAndroid Build Coastguard Worker #define PTHREAD_SCOPE_SYSTEM 0
52*c9945492SAndroid Build Coastguard Worker #define PTHREAD_SCOPE_PROCESS 1
53*c9945492SAndroid Build Coastguard Worker 
54*c9945492SAndroid Build Coastguard Worker #define PTHREAD_PROCESS_PRIVATE 0
55*c9945492SAndroid Build Coastguard Worker #define PTHREAD_PROCESS_SHARED 1
56*c9945492SAndroid Build Coastguard Worker 
57*c9945492SAndroid Build Coastguard Worker 
58*c9945492SAndroid Build Coastguard Worker #define PTHREAD_MUTEX_INITIALIZER {{{0}}}
59*c9945492SAndroid Build Coastguard Worker #define PTHREAD_RWLOCK_INITIALIZER {{{0}}}
60*c9945492SAndroid Build Coastguard Worker #define PTHREAD_COND_INITIALIZER {{{0}}}
61*c9945492SAndroid Build Coastguard Worker #define PTHREAD_ONCE_INIT 0
62*c9945492SAndroid Build Coastguard Worker 
63*c9945492SAndroid Build Coastguard Worker 
64*c9945492SAndroid Build Coastguard Worker #define PTHREAD_CANCEL_ENABLE 0
65*c9945492SAndroid Build Coastguard Worker #define PTHREAD_CANCEL_DISABLE 1
66*c9945492SAndroid Build Coastguard Worker #define PTHREAD_CANCEL_MASKED 2
67*c9945492SAndroid Build Coastguard Worker 
68*c9945492SAndroid Build Coastguard Worker #define PTHREAD_CANCEL_DEFERRED 0
69*c9945492SAndroid Build Coastguard Worker #define PTHREAD_CANCEL_ASYNCHRONOUS 1
70*c9945492SAndroid Build Coastguard Worker 
71*c9945492SAndroid Build Coastguard Worker #define PTHREAD_CANCELED ((void *)-1)
72*c9945492SAndroid Build Coastguard Worker 
73*c9945492SAndroid Build Coastguard Worker 
74*c9945492SAndroid Build Coastguard Worker #define PTHREAD_BARRIER_SERIAL_THREAD (-1)
75*c9945492SAndroid Build Coastguard Worker 
76*c9945492SAndroid Build Coastguard Worker 
77*c9945492SAndroid Build Coastguard Worker #define PTHREAD_NULL ((pthread_t)0)
78*c9945492SAndroid Build Coastguard Worker 
79*c9945492SAndroid Build Coastguard Worker 
80*c9945492SAndroid Build Coastguard Worker int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict);
81*c9945492SAndroid Build Coastguard Worker int pthread_detach(pthread_t);
82*c9945492SAndroid Build Coastguard Worker _Noreturn void pthread_exit(void *);
83*c9945492SAndroid Build Coastguard Worker int pthread_join(pthread_t, void **);
84*c9945492SAndroid Build Coastguard Worker 
85*c9945492SAndroid Build Coastguard Worker #ifdef __GNUC__
86*c9945492SAndroid Build Coastguard Worker __attribute__((const))
87*c9945492SAndroid Build Coastguard Worker #endif
88*c9945492SAndroid Build Coastguard Worker pthread_t pthread_self(void);
89*c9945492SAndroid Build Coastguard Worker 
90*c9945492SAndroid Build Coastguard Worker int pthread_equal(pthread_t, pthread_t);
91*c9945492SAndroid Build Coastguard Worker #ifndef __cplusplus
92*c9945492SAndroid Build Coastguard Worker #define pthread_equal(x,y) ((x)==(y))
93*c9945492SAndroid Build Coastguard Worker #endif
94*c9945492SAndroid Build Coastguard Worker 
95*c9945492SAndroid Build Coastguard Worker int pthread_setcancelstate(int, int *);
96*c9945492SAndroid Build Coastguard Worker int pthread_setcanceltype(int, int *);
97*c9945492SAndroid Build Coastguard Worker void pthread_testcancel(void);
98*c9945492SAndroid Build Coastguard Worker int pthread_cancel(pthread_t);
99*c9945492SAndroid Build Coastguard Worker 
100*c9945492SAndroid Build Coastguard Worker int pthread_getschedparam(pthread_t, int *__restrict, struct sched_param *__restrict);
101*c9945492SAndroid Build Coastguard Worker int pthread_setschedparam(pthread_t, int, const struct sched_param *);
102*c9945492SAndroid Build Coastguard Worker int pthread_setschedprio(pthread_t, int);
103*c9945492SAndroid Build Coastguard Worker 
104*c9945492SAndroid Build Coastguard Worker int pthread_once(pthread_once_t *, void (*)(void));
105*c9945492SAndroid Build Coastguard Worker 
106*c9945492SAndroid Build Coastguard Worker int pthread_mutex_init(pthread_mutex_t *__restrict, const pthread_mutexattr_t *__restrict);
107*c9945492SAndroid Build Coastguard Worker int pthread_mutex_lock(pthread_mutex_t *);
108*c9945492SAndroid Build Coastguard Worker int pthread_mutex_unlock(pthread_mutex_t *);
109*c9945492SAndroid Build Coastguard Worker int pthread_mutex_trylock(pthread_mutex_t *);
110*c9945492SAndroid Build Coastguard Worker int pthread_mutex_timedlock(pthread_mutex_t *__restrict, const struct timespec *__restrict);
111*c9945492SAndroid Build Coastguard Worker int pthread_mutex_destroy(pthread_mutex_t *);
112*c9945492SAndroid Build Coastguard Worker int pthread_mutex_consistent(pthread_mutex_t *);
113*c9945492SAndroid Build Coastguard Worker 
114*c9945492SAndroid Build Coastguard Worker int pthread_mutex_getprioceiling(const pthread_mutex_t *__restrict, int *__restrict);
115*c9945492SAndroid Build Coastguard Worker int pthread_mutex_setprioceiling(pthread_mutex_t *__restrict, int, int *__restrict);
116*c9945492SAndroid Build Coastguard Worker 
117*c9945492SAndroid Build Coastguard Worker int pthread_cond_init(pthread_cond_t *__restrict, const pthread_condattr_t *__restrict);
118*c9945492SAndroid Build Coastguard Worker int pthread_cond_destroy(pthread_cond_t *);
119*c9945492SAndroid Build Coastguard Worker int pthread_cond_wait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict);
120*c9945492SAndroid Build Coastguard Worker int pthread_cond_timedwait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict, const struct timespec *__restrict);
121*c9945492SAndroid Build Coastguard Worker int pthread_cond_broadcast(pthread_cond_t *);
122*c9945492SAndroid Build Coastguard Worker int pthread_cond_signal(pthread_cond_t *);
123*c9945492SAndroid Build Coastguard Worker 
124*c9945492SAndroid Build Coastguard Worker int pthread_rwlock_init(pthread_rwlock_t *__restrict, const pthread_rwlockattr_t *__restrict);
125*c9945492SAndroid Build Coastguard Worker int pthread_rwlock_destroy(pthread_rwlock_t *);
126*c9945492SAndroid Build Coastguard Worker int pthread_rwlock_rdlock(pthread_rwlock_t *);
127*c9945492SAndroid Build Coastguard Worker int pthread_rwlock_tryrdlock(pthread_rwlock_t *);
128*c9945492SAndroid Build Coastguard Worker int pthread_rwlock_timedrdlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict);
129*c9945492SAndroid Build Coastguard Worker int pthread_rwlock_wrlock(pthread_rwlock_t *);
130*c9945492SAndroid Build Coastguard Worker int pthread_rwlock_trywrlock(pthread_rwlock_t *);
131*c9945492SAndroid Build Coastguard Worker int pthread_rwlock_timedwrlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict);
132*c9945492SAndroid Build Coastguard Worker int pthread_rwlock_unlock(pthread_rwlock_t *);
133*c9945492SAndroid Build Coastguard Worker 
134*c9945492SAndroid Build Coastguard Worker int pthread_spin_init(pthread_spinlock_t *, int);
135*c9945492SAndroid Build Coastguard Worker int pthread_spin_destroy(pthread_spinlock_t *);
136*c9945492SAndroid Build Coastguard Worker int pthread_spin_lock(pthread_spinlock_t *);
137*c9945492SAndroid Build Coastguard Worker int pthread_spin_trylock(pthread_spinlock_t *);
138*c9945492SAndroid Build Coastguard Worker int pthread_spin_unlock(pthread_spinlock_t *);
139*c9945492SAndroid Build Coastguard Worker 
140*c9945492SAndroid Build Coastguard Worker int pthread_barrier_init(pthread_barrier_t *__restrict, const pthread_barrierattr_t *__restrict, unsigned);
141*c9945492SAndroid Build Coastguard Worker int pthread_barrier_destroy(pthread_barrier_t *);
142*c9945492SAndroid Build Coastguard Worker int pthread_barrier_wait(pthread_barrier_t *);
143*c9945492SAndroid Build Coastguard Worker 
144*c9945492SAndroid Build Coastguard Worker int pthread_key_create(pthread_key_t *, void (*)(void *));
145*c9945492SAndroid Build Coastguard Worker int pthread_key_delete(pthread_key_t);
146*c9945492SAndroid Build Coastguard Worker void *pthread_getspecific(pthread_key_t);
147*c9945492SAndroid Build Coastguard Worker int pthread_setspecific(pthread_key_t, const void *);
148*c9945492SAndroid Build Coastguard Worker 
149*c9945492SAndroid Build Coastguard Worker int pthread_attr_init(pthread_attr_t *);
150*c9945492SAndroid Build Coastguard Worker int pthread_attr_destroy(pthread_attr_t *);
151*c9945492SAndroid Build Coastguard Worker 
152*c9945492SAndroid Build Coastguard Worker int pthread_attr_getguardsize(const pthread_attr_t *__restrict, size_t *__restrict);
153*c9945492SAndroid Build Coastguard Worker int pthread_attr_setguardsize(pthread_attr_t *, size_t);
154*c9945492SAndroid Build Coastguard Worker int pthread_attr_getstacksize(const pthread_attr_t *__restrict, size_t *__restrict);
155*c9945492SAndroid Build Coastguard Worker int pthread_attr_setstacksize(pthread_attr_t *, size_t);
156*c9945492SAndroid Build Coastguard Worker int pthread_attr_getdetachstate(const pthread_attr_t *, int *);
157*c9945492SAndroid Build Coastguard Worker int pthread_attr_setdetachstate(pthread_attr_t *, int);
158*c9945492SAndroid Build Coastguard Worker int pthread_attr_getstack(const pthread_attr_t *__restrict, void **__restrict, size_t *__restrict);
159*c9945492SAndroid Build Coastguard Worker int pthread_attr_setstack(pthread_attr_t *, void *, size_t);
160*c9945492SAndroid Build Coastguard Worker int pthread_attr_getscope(const pthread_attr_t *__restrict, int *__restrict);
161*c9945492SAndroid Build Coastguard Worker int pthread_attr_setscope(pthread_attr_t *, int);
162*c9945492SAndroid Build Coastguard Worker int pthread_attr_getschedpolicy(const pthread_attr_t *__restrict, int *__restrict);
163*c9945492SAndroid Build Coastguard Worker int pthread_attr_setschedpolicy(pthread_attr_t *, int);
164*c9945492SAndroid Build Coastguard Worker int pthread_attr_getschedparam(const pthread_attr_t *__restrict, struct sched_param *__restrict);
165*c9945492SAndroid Build Coastguard Worker int pthread_attr_setschedparam(pthread_attr_t *__restrict, const struct sched_param *__restrict);
166*c9945492SAndroid Build Coastguard Worker int pthread_attr_getinheritsched(const pthread_attr_t *__restrict, int *__restrict);
167*c9945492SAndroid Build Coastguard Worker int pthread_attr_setinheritsched(pthread_attr_t *, int);
168*c9945492SAndroid Build Coastguard Worker 
169*c9945492SAndroid Build Coastguard Worker int pthread_mutexattr_destroy(pthread_mutexattr_t *);
170*c9945492SAndroid Build Coastguard Worker int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *__restrict, int *__restrict);
171*c9945492SAndroid Build Coastguard Worker int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *__restrict, int *__restrict);
172*c9945492SAndroid Build Coastguard Worker int pthread_mutexattr_getpshared(const pthread_mutexattr_t *__restrict, int *__restrict);
173*c9945492SAndroid Build Coastguard Worker int pthread_mutexattr_getrobust(const pthread_mutexattr_t *__restrict, int *__restrict);
174*c9945492SAndroid Build Coastguard Worker int pthread_mutexattr_gettype(const pthread_mutexattr_t *__restrict, int *__restrict);
175*c9945492SAndroid Build Coastguard Worker int pthread_mutexattr_init(pthread_mutexattr_t *);
176*c9945492SAndroid Build Coastguard Worker int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int);
177*c9945492SAndroid Build Coastguard Worker int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int);
178*c9945492SAndroid Build Coastguard Worker int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
179*c9945492SAndroid Build Coastguard Worker int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int);
180*c9945492SAndroid Build Coastguard Worker int pthread_mutexattr_settype(pthread_mutexattr_t *, int);
181*c9945492SAndroid Build Coastguard Worker 
182*c9945492SAndroid Build Coastguard Worker int pthread_condattr_init(pthread_condattr_t *);
183*c9945492SAndroid Build Coastguard Worker int pthread_condattr_destroy(pthread_condattr_t *);
184*c9945492SAndroid Build Coastguard Worker int pthread_condattr_setclock(pthread_condattr_t *, clockid_t);
185*c9945492SAndroid Build Coastguard Worker int pthread_condattr_setpshared(pthread_condattr_t *, int);
186*c9945492SAndroid Build Coastguard Worker int pthread_condattr_getclock(const pthread_condattr_t *__restrict, clockid_t *__restrict);
187*c9945492SAndroid Build Coastguard Worker int pthread_condattr_getpshared(const pthread_condattr_t *__restrict, int *__restrict);
188*c9945492SAndroid Build Coastguard Worker 
189*c9945492SAndroid Build Coastguard Worker int pthread_rwlockattr_init(pthread_rwlockattr_t *);
190*c9945492SAndroid Build Coastguard Worker int pthread_rwlockattr_destroy(pthread_rwlockattr_t *);
191*c9945492SAndroid Build Coastguard Worker int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int);
192*c9945492SAndroid Build Coastguard Worker int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *__restrict, int *__restrict);
193*c9945492SAndroid Build Coastguard Worker 
194*c9945492SAndroid Build Coastguard Worker int pthread_barrierattr_destroy(pthread_barrierattr_t *);
195*c9945492SAndroid Build Coastguard Worker int pthread_barrierattr_getpshared(const pthread_barrierattr_t *__restrict, int *__restrict);
196*c9945492SAndroid Build Coastguard Worker int pthread_barrierattr_init(pthread_barrierattr_t *);
197*c9945492SAndroid Build Coastguard Worker int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int);
198*c9945492SAndroid Build Coastguard Worker 
199*c9945492SAndroid Build Coastguard Worker int pthread_atfork(void (*)(void), void (*)(void), void (*)(void));
200*c9945492SAndroid Build Coastguard Worker 
201*c9945492SAndroid Build Coastguard Worker int pthread_getconcurrency(void);
202*c9945492SAndroid Build Coastguard Worker int pthread_setconcurrency(int);
203*c9945492SAndroid Build Coastguard Worker 
204*c9945492SAndroid Build Coastguard Worker int pthread_getcpuclockid(pthread_t, clockid_t *);
205*c9945492SAndroid Build Coastguard Worker 
206*c9945492SAndroid Build Coastguard Worker struct __ptcb {
207*c9945492SAndroid Build Coastguard Worker 	void (*__f)(void *);
208*c9945492SAndroid Build Coastguard Worker 	void *__x;
209*c9945492SAndroid Build Coastguard Worker 	struct __ptcb *__next;
210*c9945492SAndroid Build Coastguard Worker };
211*c9945492SAndroid Build Coastguard Worker 
212*c9945492SAndroid Build Coastguard Worker void _pthread_cleanup_push(struct __ptcb *, void (*)(void *), void *);
213*c9945492SAndroid Build Coastguard Worker void _pthread_cleanup_pop(struct __ptcb *, int);
214*c9945492SAndroid Build Coastguard Worker 
215*c9945492SAndroid Build Coastguard Worker #define pthread_cleanup_push(f, x) do { struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x);
216*c9945492SAndroid Build Coastguard Worker #define pthread_cleanup_pop(r) _pthread_cleanup_pop(&__cb, (r)); } while(0)
217*c9945492SAndroid Build Coastguard Worker 
218*c9945492SAndroid Build Coastguard Worker #ifdef _GNU_SOURCE
219*c9945492SAndroid Build Coastguard Worker struct cpu_set_t;
220*c9945492SAndroid Build Coastguard Worker int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *);
221*c9945492SAndroid Build Coastguard Worker int pthread_setaffinity_np(pthread_t, size_t, const struct cpu_set_t *);
222*c9945492SAndroid Build Coastguard Worker int pthread_getattr_np(pthread_t, pthread_attr_t *);
223*c9945492SAndroid Build Coastguard Worker int pthread_setname_np(pthread_t, const char *);
224*c9945492SAndroid Build Coastguard Worker int pthread_getname_np(pthread_t, char *, size_t);
225*c9945492SAndroid Build Coastguard Worker int pthread_getattr_default_np(pthread_attr_t *);
226*c9945492SAndroid Build Coastguard Worker int pthread_setattr_default_np(const pthread_attr_t *);
227*c9945492SAndroid Build Coastguard Worker int pthread_tryjoin_np(pthread_t, void **);
228*c9945492SAndroid Build Coastguard Worker int pthread_timedjoin_np(pthread_t, void **, const struct timespec *);
229*c9945492SAndroid Build Coastguard Worker #endif
230*c9945492SAndroid Build Coastguard Worker 
231*c9945492SAndroid Build Coastguard Worker #if _REDIR_TIME64
232*c9945492SAndroid Build Coastguard Worker __REDIR(pthread_mutex_timedlock, __pthread_mutex_timedlock_time64);
233*c9945492SAndroid Build Coastguard Worker __REDIR(pthread_cond_timedwait, __pthread_cond_timedwait_time64);
234*c9945492SAndroid Build Coastguard Worker __REDIR(pthread_rwlock_timedrdlock, __pthread_rwlock_timedrdlock_time64);
235*c9945492SAndroid Build Coastguard Worker __REDIR(pthread_rwlock_timedwrlock, __pthread_rwlock_timedwrlock_time64);
236*c9945492SAndroid Build Coastguard Worker #ifdef _GNU_SOURCE
237*c9945492SAndroid Build Coastguard Worker __REDIR(pthread_timedjoin_np, __pthread_timedjoin_np_time64);
238*c9945492SAndroid Build Coastguard Worker #endif
239*c9945492SAndroid Build Coastguard Worker #endif
240*c9945492SAndroid Build Coastguard Worker 
241*c9945492SAndroid Build Coastguard Worker #ifdef __cplusplus
242*c9945492SAndroid Build Coastguard Worker }
243*c9945492SAndroid Build Coastguard Worker #endif
244*c9945492SAndroid Build Coastguard Worker #endif
245