blob: 48b2bca2d42fa099c8c51eb428762786dcc12d3a [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
Elliott Hughesc3f11402013-10-30 14:40:09 -070028
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080029#ifndef _PTHREAD_H_
30#define _PTHREAD_H_
31
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080032#include <limits.h>
Dan Albert75ef63d2014-11-21 00:18:07 -080033#include <machine/pthread_types.h>
34#include <sched.h>
35#include <sys/cdefs.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080036#include <sys/types.h>
Dan Albert75ef63d2014-11-21 00:18:07 -080037#include <time.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080038
Elliott Hughesc3f11402013-10-30 14:40:09 -070039typedef struct {
Yabin Cui17393b02015-03-21 15:08:25 -070040#if defined(__LP64__)
41 int32_t __private[10];
42#else
43 int32_t __private[1];
Calin Juravleb1cacd42014-04-23 17:35:04 +010044#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080045} pthread_mutex_t;
46
Yabin Cui17393b02015-03-21 15:08:25 -070047typedef long pthread_mutexattr_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080048
49enum {
50 PTHREAD_MUTEX_NORMAL = 0,
51 PTHREAD_MUTEX_RECURSIVE = 1,
52 PTHREAD_MUTEX_ERRORCHECK = 2,
53
54 PTHREAD_MUTEX_ERRORCHECK_NP = PTHREAD_MUTEX_ERRORCHECK,
55 PTHREAD_MUTEX_RECURSIVE_NP = PTHREAD_MUTEX_RECURSIVE,
56
57 PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
58};
59
Yabin Cui17393b02015-03-21 15:08:25 -070060#define PTHREAD_MUTEX_INITIALIZER { { ((PTHREAD_MUTEX_NORMAL & 3) << 14) } }
61#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP { { ((PTHREAD_MUTEX_RECURSIVE & 3) << 14) } }
62#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP { { ((PTHREAD_MUTEX_ERRORCHECK & 3) << 14) } }
63
Elliott Hughesc3f11402013-10-30 14:40:09 -070064typedef struct {
Yabin Cui32651b82015-03-13 20:30:00 -070065#if defined(__LP64__)
Yabin Cui17393b02015-03-21 15:08:25 -070066 int32_t __private[12];
Yabin Cui32651b82015-03-13 20:30:00 -070067#else
Yabin Cui17393b02015-03-21 15:08:25 -070068 int32_t __private[1];
Calin Juravleb1cacd42014-04-23 17:35:04 +010069#endif
Yabin Cui17393b02015-03-21 15:08:25 -070070} pthread_cond_t;
71
72typedef long pthread_condattr_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080073
Yabin Cui32651b82015-03-13 20:30:00 -070074#define PTHREAD_COND_INITIALIZER { { 0 } }
Elliott Hughesc3f11402013-10-30 14:40:09 -070075
Elliott Hughesc3f11402013-10-30 14:40:09 -070076typedef struct {
Yabin Cui2fabea42015-03-13 14:22:05 -070077#if defined(__LP64__)
Yabin Cui17393b02015-03-21 15:08:25 -070078 int32_t __private[14];
Calin Juravle92687e42014-05-22 19:21:22 +010079#else
Yabin Cui17393b02015-03-21 15:08:25 -070080 int32_t __private[10];
Calin Juravle92687e42014-05-22 19:21:22 +010081#endif
Yabin Cui17393b02015-03-21 15:08:25 -070082} pthread_rwlock_t;
83
84typedef long pthread_rwlockattr_t;
Elliott Hughesc3f11402013-10-30 14:40:09 -070085
Yabin Cui2fabea42015-03-13 14:22:05 -070086#define PTHREAD_RWLOCK_INITIALIZER { { 0 } }
Elliott Hughesc3f11402013-10-30 14:40:09 -070087
Yabin Cui76615da2015-03-17 14:22:09 -070088enum {
89 PTHREAD_RWLOCK_PREFER_READER_NP = 0,
90 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP = 1,
91};
92
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080093typedef int pthread_key_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080094
Yabin Cui80e6d6d2015-01-23 18:21:46 -080095typedef int pthread_once_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080096
Calin Juravleb1cacd42014-04-23 17:35:04 +010097#define PTHREAD_ONCE_INIT 0
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080098
Yabin Cuie7c2fff2015-11-05 22:06:09 -080099typedef struct {
100#if defined(__LP64__)
101 int64_t __private[4];
102#else
103 int32_t __private[8];
104#endif
105} pthread_barrier_t;
106
107typedef int pthread_barrierattr_t;
108
109#define PTHREAD_BARRIER_SERIAL_THREAD -1
110
Christopher Ferrisea5248e2014-05-14 17:58:29 -0700111#if defined(__LP64__)
112#define PTHREAD_STACK_MIN (4 * PAGE_SIZE)
113#else
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800114#define PTHREAD_STACK_MIN (2 * PAGE_SIZE)
Christopher Ferrisea5248e2014-05-14 17:58:29 -0700115#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800116
117#define PTHREAD_CREATE_DETACHED 0x00000001
118#define PTHREAD_CREATE_JOINABLE 0x00000000
119
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800120#define PTHREAD_PROCESS_PRIVATE 0
121#define PTHREAD_PROCESS_SHARED 1
122
123#define PTHREAD_SCOPE_SYSTEM 0
124#define PTHREAD_SCOPE_PROCESS 1
125
Elliott Hughesc3f11402013-10-30 14:40:09 -0700126__BEGIN_DECLS
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800127
Elliott Hughesc3f11402013-10-30 14:40:09 -0700128int pthread_atfork(void (*)(void), void (*)(void), void(*)(void));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800129
Elliott Hughesc3f11402013-10-30 14:40:09 -0700130int pthread_attr_destroy(pthread_attr_t*) __nonnull((1));
131int pthread_attr_getdetachstate(const pthread_attr_t*, int*) __nonnull((1, 2));
132int pthread_attr_getguardsize(const pthread_attr_t*, size_t*) __nonnull((1, 2));
133int pthread_attr_getschedparam(const pthread_attr_t*, struct sched_param*) __nonnull((1, 2));
134int pthread_attr_getschedpolicy(const pthread_attr_t*, int*) __nonnull((1, 2));
135int pthread_attr_getscope(const pthread_attr_t*, int*) __nonnull((1, 2));
136int pthread_attr_getstack(const pthread_attr_t*, void**, size_t*) __nonnull((1, 2, 3));
137int pthread_attr_getstacksize(const pthread_attr_t*, size_t*) __nonnull((1, 2));
138int pthread_attr_init(pthread_attr_t*) __nonnull((1));
139int pthread_attr_setdetachstate(pthread_attr_t*, int) __nonnull((1));
140int pthread_attr_setguardsize(pthread_attr_t*, size_t) __nonnull((1));
141int pthread_attr_setschedparam(pthread_attr_t*, const struct sched_param*) __nonnull((1, 2));
142int pthread_attr_setschedpolicy(pthread_attr_t*, int) __nonnull((1));
143int pthread_attr_setscope(pthread_attr_t*, int) __nonnull((1));
144int pthread_attr_setstack(pthread_attr_t*, void*, size_t) __nonnull((1));
Yabin Cuie7c2fff2015-11-05 22:06:09 -0800145int pthread_attr_setstacksize(pthread_attr_t*, size_t) __nonnull((1));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800146
Elliott Hughesc3f11402013-10-30 14:40:09 -0700147int pthread_condattr_destroy(pthread_condattr_t*) __nonnull((1));
Narayan Kamath51e6cb32014-03-03 15:38:51 +0000148int pthread_condattr_getclock(const pthread_condattr_t*, clockid_t*) __nonnull((1, 2));
Elliott Hughesc3f11402013-10-30 14:40:09 -0700149int pthread_condattr_getpshared(const pthread_condattr_t*, int*) __nonnull((1, 2));
150int pthread_condattr_init(pthread_condattr_t*) __nonnull((1));
Narayan Kamath51e6cb32014-03-03 15:38:51 +0000151int pthread_condattr_setclock(pthread_condattr_t*, clockid_t) __nonnull((1));
Elliott Hughesc3f11402013-10-30 14:40:09 -0700152int pthread_condattr_setpshared(pthread_condattr_t*, int) __nonnull((1));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800153
Elliott Hughesc3f11402013-10-30 14:40:09 -0700154int pthread_cond_broadcast(pthread_cond_t*) __nonnull((1));
155int pthread_cond_destroy(pthread_cond_t*) __nonnull((1));
156int pthread_cond_init(pthread_cond_t*, const pthread_condattr_t*) __nonnull((1));
157int pthread_cond_signal(pthread_cond_t*) __nonnull((1));
158int pthread_cond_timedwait(pthread_cond_t*, pthread_mutex_t*, const struct timespec*) __nonnull((1, 2, 3));
159int pthread_cond_wait(pthread_cond_t*, pthread_mutex_t*) __nonnull((1, 2));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800160
Elliott Hughesc3f11402013-10-30 14:40:09 -0700161int pthread_create(pthread_t*, pthread_attr_t const*, void *(*)(void*), void*) __nonnull((1, 3));
162int pthread_detach(pthread_t);
163void pthread_exit(void*) __noreturn;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800164
Elliott Hughesc3f11402013-10-30 14:40:09 -0700165int pthread_equal(pthread_t, pthread_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800166
Elliott Hughesc3f11402013-10-30 14:40:09 -0700167int pthread_getattr_np(pthread_t, pthread_attr_t*) __nonnull((2));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800168
Elliott Hughesc3f11402013-10-30 14:40:09 -0700169int pthread_getcpuclockid(pthread_t, clockid_t*) __nonnull((2));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800170
Elliott Hughesc3f11402013-10-30 14:40:09 -0700171int pthread_getschedparam(pthread_t, int*, struct sched_param*) __nonnull((2, 3));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800172
Elliott Hughesc3f11402013-10-30 14:40:09 -0700173void* pthread_getspecific(pthread_key_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800174
Elliott Hughesa4831cb2014-09-11 16:11:43 -0700175pid_t pthread_gettid_np(pthread_t);
176
Elliott Hughesc3f11402013-10-30 14:40:09 -0700177int pthread_join(pthread_t, void**);
178
179int pthread_key_create(pthread_key_t*, void (*)(void*)) __nonnull((1));
180int pthread_key_delete(pthread_key_t);
181
Elliott Hughesc3f11402013-10-30 14:40:09 -0700182int pthread_mutexattr_destroy(pthread_mutexattr_t*) __nonnull((1));
183int pthread_mutexattr_getpshared(const pthread_mutexattr_t*, int*) __nonnull((1, 2));
184int pthread_mutexattr_gettype(const pthread_mutexattr_t*, int*) __nonnull((1, 2));
185int pthread_mutexattr_init(pthread_mutexattr_t*) __nonnull((1));
186int pthread_mutexattr_setpshared(pthread_mutexattr_t*, int) __nonnull((1));
187int pthread_mutexattr_settype(pthread_mutexattr_t*, int) __nonnull((1));
188
189int pthread_mutex_destroy(pthread_mutex_t*) __nonnull((1));
190int pthread_mutex_init(pthread_mutex_t*, const pthread_mutexattr_t*) __nonnull((1));
Christopher Ferris511cfd92015-06-09 18:46:15 -0700191#if !defined(__LP64__)
192int pthread_mutex_lock(pthread_mutex_t*) /* __nonnull((1)) */;
193#else
Elliott Hughes3d773272014-10-07 23:31:06 +0000194int pthread_mutex_lock(pthread_mutex_t*) __nonnull((1));
Christopher Ferris511cfd92015-06-09 18:46:15 -0700195#endif
Elliott Hughes0e714a52014-03-03 16:42:47 -0800196int pthread_mutex_timedlock(pthread_mutex_t*, const struct timespec*) __nonnull((1, 2));
Elliott Hughesc3f11402013-10-30 14:40:09 -0700197int pthread_mutex_trylock(pthread_mutex_t*) __nonnull((1));
Christopher Ferris511cfd92015-06-09 18:46:15 -0700198#if !defined(__LP4__)
199int pthread_mutex_unlock(pthread_mutex_t*) /* __nonnull((1)) */;
200#else
Elliott Hughes3d773272014-10-07 23:31:06 +0000201int pthread_mutex_unlock(pthread_mutex_t*) __nonnull((1));
Christopher Ferris511cfd92015-06-09 18:46:15 -0700202#endif
Elliott Hughesc3f11402013-10-30 14:40:09 -0700203
204int pthread_once(pthread_once_t*, void (*)(void)) __nonnull((1, 2));
205
Yabin Cui76615da2015-03-17 14:22:09 -0700206int pthread_rwlockattr_init(pthread_rwlockattr_t*) __nonnull((1));
Elliott Hughesc3f11402013-10-30 14:40:09 -0700207int pthread_rwlockattr_destroy(pthread_rwlockattr_t*) __nonnull((1));
208int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t*, int*) __nonnull((1, 2));
Elliott Hughesc3f11402013-10-30 14:40:09 -0700209int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int) __nonnull((1));
Yabin Cui76615da2015-03-17 14:22:09 -0700210int pthread_rwlockattr_getkind_np(const pthread_rwlockattr_t*, int*) __nonnull((1, 2));
211int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t*, int) __nonnull((1));
Elliott Hughesc3f11402013-10-30 14:40:09 -0700212
213int pthread_rwlock_destroy(pthread_rwlock_t*) __nonnull((1));
214int pthread_rwlock_init(pthread_rwlock_t*, const pthread_rwlockattr_t*) __nonnull((1));
215int pthread_rwlock_rdlock(pthread_rwlock_t*) __nonnull((1));
216int pthread_rwlock_timedrdlock(pthread_rwlock_t*, const struct timespec*) __nonnull((1, 2));
217int pthread_rwlock_timedwrlock(pthread_rwlock_t*, const struct timespec*) __nonnull((1, 2));
218int pthread_rwlock_tryrdlock(pthread_rwlock_t*) __nonnull((1));
219int pthread_rwlock_trywrlock(pthread_rwlock_t*) __nonnull((1));
Yabin Cuie7c2fff2015-11-05 22:06:09 -0800220int pthread_rwlock_unlock(pthread_rwlock_t *) __nonnull((1));
Elliott Hughesc3f11402013-10-30 14:40:09 -0700221int pthread_rwlock_wrlock(pthread_rwlock_t*) __nonnull((1));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800222
Yabin Cuie7c2fff2015-11-05 22:06:09 -0800223int pthread_barrierattr_init(pthread_barrierattr_t* attr) __nonnull((1));
224int pthread_barrierattr_destroy(pthread_barrierattr_t* attr) __nonnull((1));
225int pthread_barrierattr_getpshared(pthread_barrierattr_t* attr, int* pshared) __nonnull((1, 2));
226int pthread_barrierattr_setpshared(pthread_barrierattr_t* attr, int pshared) __nonnull((1));
227
228int pthread_barrier_init(pthread_barrier_t*, const pthread_barrierattr_t*, unsigned) __nonnull((1));
229int pthread_barrier_destroy(pthread_barrier_t*) __nonnull((1));
230int pthread_barrier_wait(pthread_barrier_t*) __nonnull((1));
231
Elliott Hughesb27a8402014-06-10 20:47:49 -0700232pthread_t pthread_self(void) __pure2;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800233
Elliott Hughesc3f11402013-10-30 14:40:09 -0700234int pthread_setname_np(pthread_t, const char*) __nonnull((2));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800235
Elliott Hughesc3f11402013-10-30 14:40:09 -0700236int pthread_setschedparam(pthread_t, int, const struct sched_param*) __nonnull((3));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800237
Elliott Hughesc3f11402013-10-30 14:40:09 -0700238int pthread_setspecific(pthread_key_t, const void*);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800239
Elliott Hughesc3f11402013-10-30 14:40:09 -0700240typedef void (*__pthread_cleanup_func_t)(void*);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800241
242typedef struct __pthread_cleanup_t {
Elliott Hughesc3f11402013-10-30 14:40:09 -0700243 struct __pthread_cleanup_t* __cleanup_prev;
244 __pthread_cleanup_func_t __cleanup_routine;
245 void* __cleanup_arg;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800246} __pthread_cleanup_t;
247
Elliott Hughesc3f11402013-10-30 14:40:09 -0700248extern void __pthread_cleanup_push(__pthread_cleanup_t* c, __pthread_cleanup_func_t, void*);
249extern void __pthread_cleanup_pop(__pthread_cleanup_t*, int);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800250
251/* Believe or not, the definitions of pthread_cleanup_push and
252 * pthread_cleanup_pop below are correct. Posix states that these
253 * can be implemented as macros that might introduce opening and
254 * closing braces, and that using setjmp/longjmp/return/break/continue
Elliott Hughesc3f11402013-10-30 14:40:09 -0700255 * between them results in undefined behavior.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800256 */
257#define pthread_cleanup_push(routine, arg) \
258 do { \
259 __pthread_cleanup_t __cleanup; \
260 __pthread_cleanup_push( &__cleanup, (routine), (arg) ); \
261
262#define pthread_cleanup_pop(execute) \
263 __pthread_cleanup_pop( &__cleanup, (execute)); \
Elliott Hughesc3f11402013-10-30 14:40:09 -0700264 } while (0); \
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800265
Elliott Hughesc3f11402013-10-30 14:40:09 -0700266
267#if !defined(__LP64__)
268
Narayan Kamath51e6cb32014-03-03 15:38:51 +0000269// Bionic additions that are deprecated even in the 32-bit ABI.
270//
271// TODO: Remove them once chromium_org / NFC have switched over.
Elliott Hughesc3f11402013-10-30 14:40:09 -0700272int pthread_cond_timedwait_monotonic_np(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);
273int pthread_cond_timedwait_monotonic(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);
Elliott Hughesc3f11402013-10-30 14:40:09 -0700274
Elliott Hughes0e714a52014-03-03 16:42:47 -0800275int pthread_cond_timedwait_relative_np(pthread_cond_t*, pthread_mutex_t*, const struct timespec*) /* TODO: __attribute__((deprecated("use pthread_cond_timedwait instead")))*/;
276#define HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE 1 /* TODO: stop defining this to push LP32 off this API sooner. */
277int pthread_cond_timeout_np(pthread_cond_t*, pthread_mutex_t*, unsigned) /* TODO: __attribute__((deprecated("use pthread_cond_timedwait instead")))*/;
Elliott Hughesc3f11402013-10-30 14:40:09 -0700278
Elliott Hughes0e714a52014-03-03 16:42:47 -0800279int pthread_mutex_lock_timeout_np(pthread_mutex_t*, unsigned) __attribute__((deprecated("use pthread_mutex_timedlock instead")));
Elliott Hughesc3f11402013-10-30 14:40:09 -0700280
281#endif /* !defined(__LP64__) */
282
283__END_DECLS
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800284
David 'Digit' Turnerbd8d9872010-09-26 23:00:36 +0200285#endif /* _PTHREAD_H_ */