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> |
Dan Albert | 75ef63d | 2014-11-21 00:18:07 -0800 | [diff] [blame] | 33 | #include <machine/pthread_types.h> |
| 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 | |
Christopher Ferris | ea5248e | 2014-05-14 17:58:29 -0700 | [diff] [blame] | 39 | #if defined(__LP64__) |
Calin Juravle | b1cacd4 | 2014-04-23 17:35:04 +0100 | [diff] [blame] | 40 | #define __RESERVED_INITIALIZER , {0} |
| 41 | #else |
| 42 | #define __RESERVED_INITIALIZER |
| 43 | #endif |
| 44 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 45 | typedef struct { |
| 46 | int volatile value; |
Calin Juravle | b1cacd4 | 2014-04-23 17:35:04 +0100 | [diff] [blame] | 47 | #ifdef __LP64__ |
| 48 | char __reserved[36]; |
| 49 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 50 | } pthread_mutex_t; |
| 51 | |
David 'Digit' Turner | 9831ad3 | 2011-08-29 21:43:46 +0200 | [diff] [blame] | 52 | #define __PTHREAD_MUTEX_INIT_VALUE 0 |
| 53 | #define __PTHREAD_RECURSIVE_MUTEX_INIT_VALUE 0x4000 |
| 54 | #define __PTHREAD_ERRORCHECK_MUTEX_INIT_VALUE 0x8000 |
| 55 | |
Elliott Hughes | 212e0e3 | 2014-12-01 16:43:51 -0800 | [diff] [blame^] | 56 | #define PTHREAD_MUTEX_INITIALIZER {__PTHREAD_MUTEX_INIT_VALUE __RESERVED_INITIALIZER} |
| 57 | #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP {__PTHREAD_ERRORCHECK_MUTEX_INIT_VALUE __RESERVED_INITIALIZER} |
| 58 | #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP {__PTHREAD_RECURSIVE_MUTEX_INIT_VALUE __RESERVED_INITIALIZER} |
| 59 | |
| 60 | /* TODO: remove this namespace pollution. */ |
| 61 | #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP |
| 62 | #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 63 | |
| 64 | enum { |
| 65 | PTHREAD_MUTEX_NORMAL = 0, |
| 66 | PTHREAD_MUTEX_RECURSIVE = 1, |
| 67 | PTHREAD_MUTEX_ERRORCHECK = 2, |
| 68 | |
| 69 | PTHREAD_MUTEX_ERRORCHECK_NP = PTHREAD_MUTEX_ERRORCHECK, |
| 70 | PTHREAD_MUTEX_RECURSIVE_NP = PTHREAD_MUTEX_RECURSIVE, |
| 71 | |
| 72 | PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL |
| 73 | }; |
| 74 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 75 | typedef struct { |
| 76 | int volatile value; |
Calin Juravle | b1cacd4 | 2014-04-23 17:35:04 +0100 | [diff] [blame] | 77 | #ifdef __LP64__ |
| 78 | char __reserved[44]; |
| 79 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 80 | } pthread_cond_t; |
| 81 | |
Calin Juravle | b1cacd4 | 2014-04-23 17:35:04 +0100 | [diff] [blame] | 82 | #define PTHREAD_COND_INITIALIZER {0 __RESERVED_INITIALIZER} |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 83 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 84 | typedef long pthread_mutexattr_t; |
| 85 | typedef long pthread_condattr_t; |
| 86 | |
Calin Juravle | 7c435f2 | 2014-05-06 13:39:47 +0100 | [diff] [blame] | 87 | typedef long pthread_rwlockattr_t; |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 88 | |
| 89 | typedef struct { |
Calin Juravle | 92687e4 | 2014-05-22 19:21:22 +0100 | [diff] [blame] | 90 | #if !defined(__LP64__) |
Calin Juravle | 76f352e | 2014-05-19 13:41:10 +0100 | [diff] [blame] | 91 | pthread_mutex_t __unused_lock; |
| 92 | pthread_cond_t __unused_cond; |
Calin Juravle | 92687e4 | 2014-05-22 19:21:22 +0100 | [diff] [blame] | 93 | #endif |
Calin Juravle | 76f352e | 2014-05-19 13:41:10 +0100 | [diff] [blame] | 94 | volatile int32_t state; // 0=unlock, -1=writer lock, +n=reader lock |
Calin Juravle | 92687e4 | 2014-05-22 19:21:22 +0100 | [diff] [blame] | 95 | volatile int32_t writer_thread_id; |
| 96 | volatile int32_t pending_readers; |
| 97 | volatile int32_t pending_writers; |
Calin Juravle | 76f352e | 2014-05-19 13:41:10 +0100 | [diff] [blame] | 98 | int32_t attr; |
Calin Juravle | 92687e4 | 2014-05-22 19:21:22 +0100 | [diff] [blame] | 99 | #ifdef __LP64__ |
| 100 | char __reserved[36]; |
| 101 | #else |
| 102 | char __reserved[12]; |
| 103 | #endif |
| 104 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 105 | } pthread_rwlock_t; |
| 106 | |
Calin Juravle | 92687e4 | 2014-05-22 19:21:22 +0100 | [diff] [blame] | 107 | #ifdef __LP64__ |
| 108 | #define PTHREAD_RWLOCK_INITIALIZER { 0, 0, 0, 0, 0, { 0 } } |
| 109 | #else |
| 110 | #define PTHREAD_RWLOCK_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0, 0, 0, 0, { 0 } } |
| 111 | #endif |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 112 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 113 | typedef int pthread_key_t; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 114 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 115 | typedef volatile int pthread_once_t; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 116 | |
Calin Juravle | b1cacd4 | 2014-04-23 17:35:04 +0100 | [diff] [blame] | 117 | #define PTHREAD_ONCE_INIT 0 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 118 | |
Christopher Ferris | ea5248e | 2014-05-14 17:58:29 -0700 | [diff] [blame] | 119 | #if defined(__LP64__) |
| 120 | #define PTHREAD_STACK_MIN (4 * PAGE_SIZE) |
| 121 | #else |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 122 | #define PTHREAD_STACK_MIN (2 * PAGE_SIZE) |
Christopher Ferris | ea5248e | 2014-05-14 17:58:29 -0700 | [diff] [blame] | 123 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 124 | |
| 125 | #define PTHREAD_CREATE_DETACHED 0x00000001 |
| 126 | #define PTHREAD_CREATE_JOINABLE 0x00000000 |
| 127 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 128 | #define PTHREAD_PROCESS_PRIVATE 0 |
| 129 | #define PTHREAD_PROCESS_SHARED 1 |
| 130 | |
| 131 | #define PTHREAD_SCOPE_SYSTEM 0 |
| 132 | #define PTHREAD_SCOPE_PROCESS 1 |
| 133 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 134 | __BEGIN_DECLS |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 135 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 136 | int pthread_atfork(void (*)(void), void (*)(void), void(*)(void)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 137 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 138 | int pthread_attr_destroy(pthread_attr_t*) __nonnull((1)); |
| 139 | int pthread_attr_getdetachstate(const pthread_attr_t*, int*) __nonnull((1, 2)); |
| 140 | int pthread_attr_getguardsize(const pthread_attr_t*, size_t*) __nonnull((1, 2)); |
| 141 | int pthread_attr_getschedparam(const pthread_attr_t*, struct sched_param*) __nonnull((1, 2)); |
| 142 | int pthread_attr_getschedpolicy(const pthread_attr_t*, int*) __nonnull((1, 2)); |
| 143 | int pthread_attr_getscope(const pthread_attr_t*, int*) __nonnull((1, 2)); |
| 144 | int pthread_attr_getstack(const pthread_attr_t*, void**, size_t*) __nonnull((1, 2, 3)); |
| 145 | int pthread_attr_getstacksize(const pthread_attr_t*, size_t*) __nonnull((1, 2)); |
| 146 | int pthread_attr_init(pthread_attr_t*) __nonnull((1)); |
| 147 | int pthread_attr_setdetachstate(pthread_attr_t*, int) __nonnull((1)); |
| 148 | int pthread_attr_setguardsize(pthread_attr_t*, size_t) __nonnull((1)); |
| 149 | int pthread_attr_setschedparam(pthread_attr_t*, const struct sched_param*) __nonnull((1, 2)); |
| 150 | int pthread_attr_setschedpolicy(pthread_attr_t*, int) __nonnull((1)); |
| 151 | int pthread_attr_setscope(pthread_attr_t*, int) __nonnull((1)); |
| 152 | int pthread_attr_setstack(pthread_attr_t*, void*, size_t) __nonnull((1)); |
Narayan Kamath | 51e6cb3 | 2014-03-03 15:38:51 +0000 | [diff] [blame] | 153 | int pthread_attr_setstacksize(pthread_attr_t*, size_t stack_size) __nonnull((1)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 154 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 155 | int pthread_condattr_destroy(pthread_condattr_t*) __nonnull((1)); |
Narayan Kamath | 51e6cb3 | 2014-03-03 15:38:51 +0000 | [diff] [blame] | 156 | int pthread_condattr_getclock(const pthread_condattr_t*, clockid_t*) __nonnull((1, 2)); |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 157 | int pthread_condattr_getpshared(const pthread_condattr_t*, int*) __nonnull((1, 2)); |
| 158 | int pthread_condattr_init(pthread_condattr_t*) __nonnull((1)); |
Narayan Kamath | 51e6cb3 | 2014-03-03 15:38:51 +0000 | [diff] [blame] | 159 | int pthread_condattr_setclock(pthread_condattr_t*, clockid_t) __nonnull((1)); |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 160 | int pthread_condattr_setpshared(pthread_condattr_t*, int) __nonnull((1)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 161 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 162 | int pthread_cond_broadcast(pthread_cond_t*) __nonnull((1)); |
| 163 | int pthread_cond_destroy(pthread_cond_t*) __nonnull((1)); |
| 164 | int pthread_cond_init(pthread_cond_t*, const pthread_condattr_t*) __nonnull((1)); |
| 165 | int pthread_cond_signal(pthread_cond_t*) __nonnull((1)); |
| 166 | int pthread_cond_timedwait(pthread_cond_t*, pthread_mutex_t*, const struct timespec*) __nonnull((1, 2, 3)); |
| 167 | int pthread_cond_wait(pthread_cond_t*, pthread_mutex_t*) __nonnull((1, 2)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 168 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 169 | int pthread_create(pthread_t*, pthread_attr_t const*, void *(*)(void*), void*) __nonnull((1, 3)); |
| 170 | int pthread_detach(pthread_t); |
| 171 | void pthread_exit(void*) __noreturn; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 172 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 173 | int pthread_equal(pthread_t, pthread_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 174 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 175 | int pthread_getattr_np(pthread_t, pthread_attr_t*) __nonnull((2)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 176 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 177 | int pthread_getcpuclockid(pthread_t, clockid_t*) __nonnull((2)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 178 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 179 | int pthread_getschedparam(pthread_t, int*, struct sched_param*) __nonnull((2, 3)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 180 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 181 | void* pthread_getspecific(pthread_key_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 182 | |
Elliott Hughes | a4831cb | 2014-09-11 16:11:43 -0700 | [diff] [blame] | 183 | pid_t pthread_gettid_np(pthread_t); |
| 184 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 185 | int pthread_join(pthread_t, void**); |
| 186 | |
| 187 | int pthread_key_create(pthread_key_t*, void (*)(void*)) __nonnull((1)); |
| 188 | int pthread_key_delete(pthread_key_t); |
| 189 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 190 | int pthread_mutexattr_destroy(pthread_mutexattr_t*) __nonnull((1)); |
| 191 | int pthread_mutexattr_getpshared(const pthread_mutexattr_t*, int*) __nonnull((1, 2)); |
| 192 | int pthread_mutexattr_gettype(const pthread_mutexattr_t*, int*) __nonnull((1, 2)); |
| 193 | int pthread_mutexattr_init(pthread_mutexattr_t*) __nonnull((1)); |
| 194 | int pthread_mutexattr_setpshared(pthread_mutexattr_t*, int) __nonnull((1)); |
| 195 | int pthread_mutexattr_settype(pthread_mutexattr_t*, int) __nonnull((1)); |
| 196 | |
| 197 | int pthread_mutex_destroy(pthread_mutex_t*) __nonnull((1)); |
| 198 | int pthread_mutex_init(pthread_mutex_t*, const pthread_mutexattr_t*) __nonnull((1)); |
Elliott Hughes | 3d77327 | 2014-10-07 23:31:06 +0000 | [diff] [blame] | 199 | int pthread_mutex_lock(pthread_mutex_t*) __nonnull((1)); |
Elliott Hughes | 0e714a5 | 2014-03-03 16:42:47 -0800 | [diff] [blame] | 200 | int pthread_mutex_timedlock(pthread_mutex_t*, const struct timespec*) __nonnull((1, 2)); |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 201 | int pthread_mutex_trylock(pthread_mutex_t*) __nonnull((1)); |
Elliott Hughes | 3d77327 | 2014-10-07 23:31:06 +0000 | [diff] [blame] | 202 | int pthread_mutex_unlock(pthread_mutex_t*) __nonnull((1)); |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 203 | |
| 204 | int pthread_once(pthread_once_t*, void (*)(void)) __nonnull((1, 2)); |
| 205 | |
| 206 | int pthread_rwlockattr_destroy(pthread_rwlockattr_t*) __nonnull((1)); |
| 207 | int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t*, int*) __nonnull((1, 2)); |
| 208 | int pthread_rwlockattr_init(pthread_rwlockattr_t*) __nonnull((1)); |
| 209 | int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int) __nonnull((1)); |
| 210 | |
| 211 | int pthread_rwlock_destroy(pthread_rwlock_t*) __nonnull((1)); |
| 212 | int pthread_rwlock_init(pthread_rwlock_t*, const pthread_rwlockattr_t*) __nonnull((1)); |
| 213 | int pthread_rwlock_rdlock(pthread_rwlock_t*) __nonnull((1)); |
| 214 | int pthread_rwlock_timedrdlock(pthread_rwlock_t*, const struct timespec*) __nonnull((1, 2)); |
| 215 | int pthread_rwlock_timedwrlock(pthread_rwlock_t*, const struct timespec*) __nonnull((1, 2)); |
| 216 | int pthread_rwlock_tryrdlock(pthread_rwlock_t*) __nonnull((1)); |
| 217 | int pthread_rwlock_trywrlock(pthread_rwlock_t*) __nonnull((1)); |
| 218 | int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) __nonnull((1)); |
| 219 | int pthread_rwlock_wrlock(pthread_rwlock_t*) __nonnull((1)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 220 | |
Elliott Hughes | b27a840 | 2014-06-10 20:47:49 -0700 | [diff] [blame] | 221 | pthread_t pthread_self(void) __pure2; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 222 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 223 | int pthread_setname_np(pthread_t, const char*) __nonnull((2)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 224 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 225 | int pthread_setschedparam(pthread_t, int, const struct sched_param*) __nonnull((3)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 226 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 227 | int pthread_setspecific(pthread_key_t, const void*); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 228 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 229 | typedef void (*__pthread_cleanup_func_t)(void*); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 230 | |
| 231 | typedef struct __pthread_cleanup_t { |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 232 | struct __pthread_cleanup_t* __cleanup_prev; |
| 233 | __pthread_cleanup_func_t __cleanup_routine; |
| 234 | void* __cleanup_arg; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 235 | } __pthread_cleanup_t; |
| 236 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 237 | extern void __pthread_cleanup_push(__pthread_cleanup_t* c, __pthread_cleanup_func_t, void*); |
| 238 | extern void __pthread_cleanup_pop(__pthread_cleanup_t*, int); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 239 | |
| 240 | /* Believe or not, the definitions of pthread_cleanup_push and |
| 241 | * pthread_cleanup_pop below are correct. Posix states that these |
| 242 | * can be implemented as macros that might introduce opening and |
| 243 | * closing braces, and that using setjmp/longjmp/return/break/continue |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 244 | * between them results in undefined behavior. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 245 | */ |
| 246 | #define pthread_cleanup_push(routine, arg) \ |
| 247 | do { \ |
| 248 | __pthread_cleanup_t __cleanup; \ |
| 249 | __pthread_cleanup_push( &__cleanup, (routine), (arg) ); \ |
| 250 | |
| 251 | #define pthread_cleanup_pop(execute) \ |
| 252 | __pthread_cleanup_pop( &__cleanup, (execute)); \ |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 253 | } while (0); \ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 254 | |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 255 | |
| 256 | #if !defined(__LP64__) |
| 257 | |
Narayan Kamath | 51e6cb3 | 2014-03-03 15:38:51 +0000 | [diff] [blame] | 258 | // Bionic additions that are deprecated even in the 32-bit ABI. |
| 259 | // |
| 260 | // TODO: Remove them once chromium_org / NFC have switched over. |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 261 | int pthread_cond_timedwait_monotonic_np(pthread_cond_t*, pthread_mutex_t*, const struct timespec*); |
| 262 | int pthread_cond_timedwait_monotonic(pthread_cond_t*, pthread_mutex_t*, const struct timespec*); |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 263 | |
Elliott Hughes | 0e714a5 | 2014-03-03 16:42:47 -0800 | [diff] [blame] | 264 | int pthread_cond_timedwait_relative_np(pthread_cond_t*, pthread_mutex_t*, const struct timespec*) /* TODO: __attribute__((deprecated("use pthread_cond_timedwait instead")))*/; |
| 265 | #define HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE 1 /* TODO: stop defining this to push LP32 off this API sooner. */ |
| 266 | int pthread_cond_timeout_np(pthread_cond_t*, pthread_mutex_t*, unsigned) /* TODO: __attribute__((deprecated("use pthread_cond_timedwait instead")))*/; |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 267 | |
Elliott Hughes | 0e714a5 | 2014-03-03 16:42:47 -0800 | [diff] [blame] | 268 | int pthread_mutex_lock_timeout_np(pthread_mutex_t*, unsigned) __attribute__((deprecated("use pthread_mutex_timedlock instead"))); |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 269 | |
| 270 | #endif /* !defined(__LP64__) */ |
| 271 | |
| 272 | __END_DECLS |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 273 | |
David 'Digit' Turner | bd8d987 | 2010-09-26 23:00:36 +0200 | [diff] [blame] | 274 | #endif /* _PTHREAD_H_ */ |