| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* | 
|  | 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 Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 28 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 29 | #ifndef _PTHREAD_H_ | 
|  | 30 | #define _PTHREAD_H_ | 
|  | 31 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 32 | #include <limits.h> | 
| Elliott Hughes | 5704c42 | 2016-01-25 18:06:24 -0800 | [diff] [blame] | 33 | #include <bits/pthread_types.h> | 
| Dan Albert | 75ef63d | 2014-11-21 00:18:07 -0800 | [diff] [blame] | 34 | #include <sched.h> | 
|  | 35 | #include <sys/cdefs.h> | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 36 | #include <sys/types.h> | 
| Dan Albert | 75ef63d | 2014-11-21 00:18:07 -0800 | [diff] [blame] | 37 | #include <time.h> | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 38 |  | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 39 | __BEGIN_DECLS | 
|  | 40 |  | 
|  | 41 | #if defined(__clang__) | 
|  | 42 | #pragma clang diagnostic push | 
|  | 43 | #pragma clang diagnostic ignored "-Wnullability-completeness" | 
|  | 44 | #endif | 
|  | 45 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 46 | enum { | 
|  | 47 | PTHREAD_MUTEX_NORMAL = 0, | 
|  | 48 | PTHREAD_MUTEX_RECURSIVE = 1, | 
|  | 49 | PTHREAD_MUTEX_ERRORCHECK = 2, | 
|  | 50 |  | 
|  | 51 | PTHREAD_MUTEX_ERRORCHECK_NP = PTHREAD_MUTEX_ERRORCHECK, | 
|  | 52 | PTHREAD_MUTEX_RECURSIVE_NP  = PTHREAD_MUTEX_RECURSIVE, | 
|  | 53 |  | 
|  | 54 | PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL | 
|  | 55 | }; | 
|  | 56 |  | 
| Yabin Cui | 17393b0 | 2015-03-21 15:08:25 -0700 | [diff] [blame] | 57 | #define PTHREAD_MUTEX_INITIALIZER { { ((PTHREAD_MUTEX_NORMAL & 3) << 14) } } | 
|  | 58 | #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP { { ((PTHREAD_MUTEX_RECURSIVE & 3) << 14) } } | 
|  | 59 | #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP { { ((PTHREAD_MUTEX_ERRORCHECK & 3) << 14) } } | 
|  | 60 |  | 
| Yabin Cui | 32651b8 | 2015-03-13 20:30:00 -0700 | [diff] [blame] | 61 | #define PTHREAD_COND_INITIALIZER  { { 0 } } | 
| Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 62 |  | 
| Yabin Cui | 2fabea4 | 2015-03-13 14:22:05 -0700 | [diff] [blame] | 63 | #define PTHREAD_RWLOCK_INITIALIZER  { { 0 } } | 
| Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 64 |  | 
| Yabin Cui | 76615da | 2015-03-17 14:22:09 -0700 | [diff] [blame] | 65 | enum { | 
|  | 66 | PTHREAD_RWLOCK_PREFER_READER_NP = 0, | 
|  | 67 | PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP = 1, | 
|  | 68 | }; | 
|  | 69 |  | 
| Calin Juravle | b1cacd4 | 2014-04-23 17:35:04 +0100 | [diff] [blame] | 70 | #define PTHREAD_ONCE_INIT 0 | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 71 |  | 
| Elliott Hughes | 468a5d2 | 2017-03-21 09:39:56 -0700 | [diff] [blame] | 72 | #if __ANDROID_API__ >= __ANDROID_API_N__ | 
| Yabin Cui | e7c2fff | 2015-11-05 22:06:09 -0800 | [diff] [blame] | 73 | #define PTHREAD_BARRIER_SERIAL_THREAD -1 | 
| Elliott Hughes | 468a5d2 | 2017-03-21 09:39:56 -0700 | [diff] [blame] | 74 | #endif | 
| Yabin Cui | e7c2fff | 2015-11-05 22:06:09 -0800 | [diff] [blame] | 75 |  | 
| Christopher Ferris | ea5248e | 2014-05-14 17:58:29 -0700 | [diff] [blame] | 76 | #if defined(__LP64__) | 
|  | 77 | #define PTHREAD_STACK_MIN (4 * PAGE_SIZE) | 
|  | 78 | #else | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 79 | #define PTHREAD_STACK_MIN (2 * PAGE_SIZE) | 
| Christopher Ferris | ea5248e | 2014-05-14 17:58:29 -0700 | [diff] [blame] | 80 | #endif | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 81 |  | 
|  | 82 | #define PTHREAD_CREATE_DETACHED  0x00000001 | 
|  | 83 | #define PTHREAD_CREATE_JOINABLE  0x00000000 | 
|  | 84 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 85 | #define PTHREAD_PROCESS_PRIVATE  0 | 
|  | 86 | #define PTHREAD_PROCESS_SHARED   1 | 
|  | 87 |  | 
|  | 88 | #define PTHREAD_SCOPE_SYSTEM     0 | 
|  | 89 | #define PTHREAD_SCOPE_PROCESS    1 | 
|  | 90 |  | 
| Josh Gao | 46b4416 | 2016-05-27 11:14:16 -0700 | [diff] [blame] | 91 | int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)) __INTRODUCED_IN(12); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 92 |  | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 93 | int pthread_attr_destroy(pthread_attr_t* _Nonnull); | 
|  | 94 | int pthread_attr_getdetachstate(const pthread_attr_t* _Nonnull, int* _Nonnull); | 
|  | 95 | int pthread_attr_getguardsize(const pthread_attr_t* _Nonnull, size_t* _Nonnull); | 
|  | 96 | int pthread_attr_getschedparam(const pthread_attr_t* _Nonnull, struct sched_param* _Nonnull); | 
|  | 97 | int pthread_attr_getschedpolicy(const pthread_attr_t* _Nonnull, int* _Nonnull); | 
|  | 98 | int pthread_attr_getscope(const pthread_attr_t* _Nonnull, int* _Nonnull); | 
|  | 99 | int pthread_attr_getstack(const pthread_attr_t* _Nonnull, void** _Nonnull, size_t* _Nonnull); | 
|  | 100 | int pthread_attr_getstacksize(const pthread_attr_t* _Nonnull, size_t* _Nonnull); | 
|  | 101 | int pthread_attr_init(pthread_attr_t* _Nonnull); | 
|  | 102 | int pthread_attr_setdetachstate(pthread_attr_t* _Nonnull, int); | 
|  | 103 | int pthread_attr_setguardsize(pthread_attr_t* _Nonnull, size_t); | 
|  | 104 | int pthread_attr_setschedparam(pthread_attr_t* _Nonnull, const struct sched_param* _Nonnull); | 
|  | 105 | int pthread_attr_setschedpolicy(pthread_attr_t* _Nonnull, int); | 
|  | 106 | int pthread_attr_setscope(pthread_attr_t* _Nonnull, int); | 
|  | 107 | int pthread_attr_setstack(pthread_attr_t* _Nonnull, void*, size_t); | 
|  | 108 | int pthread_attr_setstacksize(pthread_attr_t* _Nonnull, size_t); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 109 |  | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 110 | int pthread_condattr_destroy(pthread_condattr_t* _Nonnull); | 
|  | 111 | int pthread_condattr_getclock(const pthread_condattr_t* _Nonnull, clockid_t* _Nonnull) | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 112 | __INTRODUCED_IN(21); | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 113 | int pthread_condattr_getpshared(const pthread_condattr_t* _Nonnull, int* _Nonnull); | 
|  | 114 | int pthread_condattr_init(pthread_condattr_t* _Nonnull); | 
|  | 115 | int pthread_condattr_setclock(pthread_condattr_t* _Nonnull, clockid_t) __INTRODUCED_IN(21); | 
|  | 116 | int pthread_condattr_setpshared(pthread_condattr_t* _Nonnull, int); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 117 |  | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 118 | int pthread_cond_broadcast(pthread_cond_t* _Nonnull); | 
|  | 119 | int pthread_cond_destroy(pthread_cond_t* _Nonnull); | 
|  | 120 | int pthread_cond_init(pthread_cond_t* _Nonnull, const pthread_condattr_t*); | 
|  | 121 | int pthread_cond_signal(pthread_cond_t* _Nonnull); | 
|  | 122 | int pthread_cond_timedwait(pthread_cond_t* _Nonnull, pthread_mutex_t* _Nonnull, | 
|  | 123 | const struct timespec* _Nonnull); | 
|  | 124 | int pthread_cond_wait(pthread_cond_t* _Nonnull, pthread_mutex_t* _Nonnull); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 125 |  | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 126 | int pthread_create(pthread_t* _Nonnull, pthread_attr_t const*, | 
|  | 127 | void* (* _Nonnull start_routine)(void*), void*); | 
| Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 128 | int pthread_detach(pthread_t); | 
|  | 129 | void pthread_exit(void*) __noreturn; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 130 |  | 
| Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 131 | int pthread_equal(pthread_t, pthread_t); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 132 |  | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 133 | int pthread_getattr_np(pthread_t, pthread_attr_t* _Nonnull); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 134 |  | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 135 | int pthread_getcpuclockid(pthread_t, clockid_t* _Nonnull); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 136 |  | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 137 | int pthread_getschedparam(pthread_t, int* _Nonnull, struct sched_param* _Nonnull); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 138 |  | 
| Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 139 | void* pthread_getspecific(pthread_key_t); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 140 |  | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 141 | pid_t pthread_gettid_np(pthread_t) __INTRODUCED_IN(21); | 
| Elliott Hughes | a4831cb | 2014-09-11 16:11:43 -0700 | [diff] [blame] | 142 |  | 
| Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 143 | int pthread_join(pthread_t, void**); | 
|  | 144 |  | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 145 | int pthread_key_create(pthread_key_t* _Nonnull, void (*)(void*)); | 
| Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 146 | int pthread_key_delete(pthread_key_t); | 
|  | 147 |  | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 148 | int pthread_mutexattr_destroy(pthread_mutexattr_t* _Nonnull); | 
|  | 149 | int pthread_mutexattr_getpshared(const pthread_mutexattr_t* _Nonnull, int* _Nonnull); | 
|  | 150 | int pthread_mutexattr_gettype(const pthread_mutexattr_t* _Nonnull, int* _Nonnull); | 
|  | 151 | int pthread_mutexattr_init(pthread_mutexattr_t* _Nonnull); | 
|  | 152 | int pthread_mutexattr_setpshared(pthread_mutexattr_t* _Nonnull, int); | 
|  | 153 | int pthread_mutexattr_settype(pthread_mutexattr_t* _Nonnull, int); | 
| Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 154 |  | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 155 | int pthread_mutex_destroy(pthread_mutex_t* _Nonnull); | 
|  | 156 | int pthread_mutex_init(pthread_mutex_t* _Nonnull, const pthread_mutexattr_t*); | 
|  | 157 | int pthread_mutex_lock(pthread_mutex_t* _Nonnull); | 
|  | 158 | int pthread_mutex_timedlock(pthread_mutex_t* _Nonnull, const struct timespec* _Nonnull) | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 159 | __INTRODUCED_IN(21); | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 160 | int pthread_mutex_trylock(pthread_mutex_t* _Nonnull); | 
|  | 161 | int pthread_mutex_unlock(pthread_mutex_t* _Nonnull); | 
| Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 162 |  | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 163 | int pthread_once(pthread_once_t* _Nonnull, void (* _Nonnull init_routine)(void)); | 
| Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 164 |  | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 165 | int pthread_rwlockattr_init(pthread_rwlockattr_t* _Nonnull); | 
|  | 166 | int pthread_rwlockattr_destroy(pthread_rwlockattr_t* _Nonnull); | 
|  | 167 | int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t* _Nonnull, int* _Nonnull); | 
|  | 168 | int pthread_rwlockattr_setpshared(pthread_rwlockattr_t* _Nonnull, int); | 
|  | 169 | int pthread_rwlockattr_getkind_np(const pthread_rwlockattr_t* _Nonnull, int* _Nonnull) | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 170 | __INTRODUCED_IN(23); | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 171 | int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t* _Nonnull, int) __INTRODUCED_IN(23); | 
| Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 172 |  | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 173 | int pthread_rwlock_destroy(pthread_rwlock_t* _Nonnull); | 
|  | 174 | int pthread_rwlock_init(pthread_rwlock_t* _Nonnull, const pthread_rwlockattr_t*); | 
|  | 175 | int pthread_rwlock_rdlock(pthread_rwlock_t* _Nonnull); | 
|  | 176 | int pthread_rwlock_timedrdlock(pthread_rwlock_t* _Nonnull, const struct timespec* _Nonnull); | 
|  | 177 | int pthread_rwlock_timedwrlock(pthread_rwlock_t* _Nonnull, const struct timespec* _Nonnull); | 
|  | 178 | int pthread_rwlock_tryrdlock(pthread_rwlock_t* _Nonnull); | 
|  | 179 | int pthread_rwlock_trywrlock(pthread_rwlock_t* _Nonnull); | 
|  | 180 | int pthread_rwlock_unlock(pthread_rwlock_t* _Nonnull); | 
|  | 181 | int pthread_rwlock_wrlock(pthread_rwlock_t* _Nonnull); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 182 |  | 
| Elliott Hughes | 468a5d2 | 2017-03-21 09:39:56 -0700 | [diff] [blame] | 183 | #if __ANDROID_API__ >= __ANDROID_API_N__ | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 184 | int pthread_barrierattr_init(pthread_barrierattr_t* _Nonnull attr) __INTRODUCED_IN(24); | 
|  | 185 | int pthread_barrierattr_destroy(pthread_barrierattr_t* _Nonnull attr) __INTRODUCED_IN(24); | 
| Elliott Hughes | 02ac028 | 2016-08-11 23:18:13 -0700 | [diff] [blame] | 186 | int pthread_barrierattr_getpshared(const pthread_barrierattr_t* _Nonnull attr, | 
|  | 187 | int* _Nonnull pshared) __INTRODUCED_IN(24); | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 188 | int pthread_barrierattr_setpshared(pthread_barrierattr_t* _Nonnull attr, int pshared) | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 189 | __INTRODUCED_IN(24); | 
| Elliott Hughes | 468a5d2 | 2017-03-21 09:39:56 -0700 | [diff] [blame] | 190 | #endif | 
| Yabin Cui | e7c2fff | 2015-11-05 22:06:09 -0800 | [diff] [blame] | 191 |  | 
| Elliott Hughes | 468a5d2 | 2017-03-21 09:39:56 -0700 | [diff] [blame] | 192 | #if __ANDROID_API__ >= __ANDROID_API_N__ | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 193 | int pthread_barrier_init(pthread_barrier_t* _Nonnull, const pthread_barrierattr_t*, unsigned) | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 194 | __INTRODUCED_IN(24); | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 195 | int pthread_barrier_destroy(pthread_barrier_t* _Nonnull) __INTRODUCED_IN(24); | 
|  | 196 | int pthread_barrier_wait(pthread_barrier_t* _Nonnull) __INTRODUCED_IN(24); | 
| Elliott Hughes | 468a5d2 | 2017-03-21 09:39:56 -0700 | [diff] [blame] | 197 | #endif | 
| Yabin Cui | e7c2fff | 2015-11-05 22:06:09 -0800 | [diff] [blame] | 198 |  | 
| Elliott Hughes | 468a5d2 | 2017-03-21 09:39:56 -0700 | [diff] [blame] | 199 | #if __ANDROID_API__ >= __ANDROID_API_N__ | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 200 | int pthread_spin_destroy(pthread_spinlock_t* _Nonnull) __INTRODUCED_IN(24); | 
|  | 201 | int pthread_spin_init(pthread_spinlock_t* _Nonnull, int) __INTRODUCED_IN(24); | 
|  | 202 | int pthread_spin_lock(pthread_spinlock_t* _Nonnull) __INTRODUCED_IN(24); | 
|  | 203 | int pthread_spin_trylock(pthread_spinlock_t* _Nonnull) __INTRODUCED_IN(24); | 
|  | 204 | int pthread_spin_unlock(pthread_spinlock_t* _Nonnull) __INTRODUCED_IN(24); | 
| Elliott Hughes | 468a5d2 | 2017-03-21 09:39:56 -0700 | [diff] [blame] | 205 | #endif | 
| Yabin Cui | fe3a83a | 2015-11-17 16:03:18 -0800 | [diff] [blame] | 206 |  | 
| Elliott Hughes | 95fa061 | 2016-09-28 12:29:52 -0700 | [diff] [blame] | 207 | pthread_t pthread_self(void) __attribute_const__; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 208 |  | 
| Elliott Hughes | 725b2a9 | 2016-03-23 11:20:47 -0700 | [diff] [blame] | 209 | #if defined(__USE_GNU) | 
| Josh Gao | cb302f9 | 2017-04-20 12:58:31 -0700 | [diff] [blame] | 210 | int pthread_getname_np(pthread_t, char* _Nonnull, size_t) __INTRODUCED_IN(26); | 
| Elliott Hughes | 725b2a9 | 2016-03-23 11:20:47 -0700 | [diff] [blame] | 211 | #endif | 
| Elliott Hughes | cc78b25 | 2016-03-23 20:26:35 -0700 | [diff] [blame] | 212 | /* TODO: this should be __USE_GNU too. */ | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 213 | int pthread_setname_np(pthread_t, const char* _Nonnull); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 214 |  | 
| Dan Albert | baa2a97 | 2015-08-13 16:58:50 -0700 | [diff] [blame] | 215 | int pthread_setschedparam(pthread_t, int, const struct sched_param* _Nonnull); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 216 |  | 
| Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 217 | int pthread_setspecific(pthread_key_t, const void*); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 218 |  | 
| Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 219 | typedef void (*__pthread_cleanup_func_t)(void*); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 220 |  | 
|  | 221 | typedef struct __pthread_cleanup_t { | 
| Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 222 | struct __pthread_cleanup_t*   __cleanup_prev; | 
|  | 223 | __pthread_cleanup_func_t      __cleanup_routine; | 
|  | 224 | void*                         __cleanup_arg; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 225 | } __pthread_cleanup_t; | 
|  | 226 |  | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 227 | void __pthread_cleanup_push(__pthread_cleanup_t* c, __pthread_cleanup_func_t, void*); | 
|  | 228 | void __pthread_cleanup_pop(__pthread_cleanup_t*, int); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 229 |  | 
|  | 230 | /* Believe or not, the definitions of pthread_cleanup_push and | 
|  | 231 | * pthread_cleanup_pop below are correct. Posix states that these | 
|  | 232 | * can be implemented as macros that might introduce opening and | 
|  | 233 | * closing braces, and that using setjmp/longjmp/return/break/continue | 
| Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 234 | * between them results in undefined behavior. | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 235 | */ | 
|  | 236 | #define  pthread_cleanup_push(routine, arg)                      \ | 
|  | 237 | do {                                                         \ | 
|  | 238 | __pthread_cleanup_t  __cleanup;                          \ | 
|  | 239 | __pthread_cleanup_push( &__cleanup, (routine), (arg) );  \ | 
|  | 240 |  | 
|  | 241 | #define  pthread_cleanup_pop(execute)                  \ | 
|  | 242 | __pthread_cleanup_pop( &__cleanup, (execute)); \ | 
| Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 243 | } while (0);                                       \ | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 244 |  | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 245 | #if defined(__clang__) | 
|  | 246 | #pragma clang diagnostic pop | 
|  | 247 | #endif | 
|  | 248 |  | 
| Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 249 | __END_DECLS | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 250 |  | 
| David 'Digit' Turner | bd8d987 | 2010-09-26 23:00:36 +0200 | [diff] [blame] | 251 | #endif /* _PTHREAD_H_ */ |