2 * Copyright (C) 2008 The Android Open Source Project
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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
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
35 #include <sys/types.h>
45 #define PTHREAD_MUTEX_INITIALIZER {0}
46 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER {0x4000}
47 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER {0x8000}
50 PTHREAD_MUTEX_NORMAL = 0,
51 PTHREAD_MUTEX_RECURSIVE = 1,
52 PTHREAD_MUTEX_ERRORCHECK = 2,
54 PTHREAD_MUTEX_ERRORCHECK_NP = PTHREAD_MUTEX_ERRORCHECK,
55 PTHREAD_MUTEX_RECURSIVE_NP = PTHREAD_MUTEX_RECURSIVE,
57 PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
74 int32_t sched_priority;
77 typedef long pthread_mutexattr_t;
78 typedef long pthread_condattr_t;
80 typedef int pthread_key_t;
81 typedef long pthread_t;
83 typedef volatile int pthread_once_t;
88 #define PTHREAD_COND_INITIALIZER {0}
90 #define PTHREAD_STACK_MIN (2 * PAGE_SIZE)
92 #define PTHREAD_CREATE_DETACHED 0x00000001
93 #define PTHREAD_CREATE_JOINABLE 0x00000000
95 #define PTHREAD_ONCE_INIT 0
97 #define PTHREAD_PROCESS_PRIVATE 0
98 #define PTHREAD_PROCESS_SHARED 1
100 #define PTHREAD_SCOPE_SYSTEM 0
101 #define PTHREAD_SCOPE_PROCESS 1
110 int pthread_attr_init(pthread_attr_t * attr);
111 int pthread_attr_destroy(pthread_attr_t * attr);
113 int pthread_attr_setdetachstate(pthread_attr_t * attr, int state);
114 int pthread_attr_getdetachstate(pthread_attr_t const * attr, int * state);
116 int pthread_attr_setschedpolicy(pthread_attr_t * attr, int policy);
117 int pthread_attr_getschedpolicy(pthread_attr_t const * attr, int * policy);
119 int pthread_attr_setschedparam(pthread_attr_t * attr, struct sched_param const * param);
120 int pthread_attr_getschedparam(pthread_attr_t const * attr, struct sched_param * param);
122 int pthread_attr_setstacksize(pthread_attr_t * attr, size_t stack_size);
123 int pthread_attr_getstacksize(pthread_attr_t const * attr, size_t * stack_size);
125 int pthread_attr_setstackaddr(pthread_attr_t * attr, void * stackaddr);
126 int pthread_attr_getstackaddr(pthread_attr_t const * attr, void ** stackaddr);
128 int pthread_attr_setstack(pthread_attr_t * attr, void * stackaddr, size_t stack_size);
129 int pthread_attr_getstack(pthread_attr_t const * attr, void ** stackaddr, size_t * stack_size);
131 int pthread_attr_setguardsize(pthread_attr_t * attr, size_t guard_size);
132 int pthread_attr_getguardsize(pthread_attr_t const * attr, size_t * guard_size);
134 int pthread_attr_setscope(pthread_attr_t *attr, int scope);
135 int pthread_attr_getscope(pthread_attr_t const *attr);
137 int pthread_getattr_np(pthread_t thid, pthread_attr_t * attr);
139 int pthread_create(pthread_t *thread, pthread_attr_t const * attr,
140 void *(*start_routine)(void *), void * arg);
141 void pthread_exit(void * retval);
142 int pthread_join(pthread_t thid, void ** ret_val);
143 int pthread_detach(pthread_t thid);
145 pthread_t pthread_self(void);
146 int pthread_equal(pthread_t one, pthread_t two);
148 int pthread_getschedparam(pthread_t thid, int * policy,
149 struct sched_param * param);
150 int pthread_setschedparam(pthread_t thid, int poilcy,
151 struct sched_param const * param);
153 int pthread_mutexattr_init(pthread_mutexattr_t *attr);
154 int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
155 int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type);
156 int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
157 int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared);
158 int pthread_mutexattr_getpshared(pthread_mutexattr_t *attr, int *pshared);
160 int pthread_mutex_init(pthread_mutex_t *mutex,
161 const pthread_mutexattr_t *attr);
162 int pthread_mutex_destroy(pthread_mutex_t *mutex);
163 int pthread_mutex_lock(pthread_mutex_t *mutex);
164 int pthread_mutex_unlock(pthread_mutex_t *mutex);
165 int pthread_mutex_trylock(pthread_mutex_t *mutex);
166 int pthread_mutex_timedlock(pthread_mutex_t *mutex, struct timespec* ts);
168 int pthread_condattr_init(pthread_condattr_t *attr);
169 int pthread_condattr_getpshared(pthread_condattr_t *attr, int *pshared);
170 int pthread_condattr_setpshared(pthread_condattr_t* attr, int pshared);
171 int pthread_condattr_destroy(pthread_condattr_t *attr);
173 int pthread_cond_init(pthread_cond_t *cond,
174 const pthread_condattr_t *attr);
175 int pthread_cond_destroy(pthread_cond_t *cond);
176 int pthread_cond_broadcast(pthread_cond_t *cond);
177 int pthread_cond_signal(pthread_cond_t *cond);
178 int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
179 int pthread_cond_timedwait(pthread_cond_t *cond,
180 pthread_mutex_t * mutex,
181 const struct timespec *abstime);
183 /* BIONIC: same as pthread_cond_timedwait, except the 'abstime' given refers
184 * to the CLOCK_MONOTONIC clock instead, to avoid any problems when
185 * the wall-clock time is changed brutally
187 int pthread_cond_timedwait_monotonic_np(pthread_cond_t *cond,
188 pthread_mutex_t *mutex,
189 const struct timespec *abstime);
191 /* BIONIC: DEPRECATED. same as pthread_cond_timedwait_monotonic_np()
192 * unfortunately pthread_cond_timedwait_monotonic has shipped already
194 int pthread_cond_timedwait_monotonic(pthread_cond_t *cond,
195 pthread_mutex_t *mutex,
196 const struct timespec *abstime);
198 #define HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC 1
200 /* BIONIC: same as pthread_cond_timedwait, except the 'reltime' given refers
201 * is relative to the current time.
203 int pthread_cond_timedwait_relative_np(pthread_cond_t *cond,
204 pthread_mutex_t *mutex,
205 const struct timespec *reltime);
207 #define HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE 1
211 int pthread_cond_timeout_np(pthread_cond_t *cond,
212 pthread_mutex_t * mutex,
215 /* same as pthread_mutex_lock(), but will wait up to 'msecs' milli-seconds
216 * before returning. same return values than pthread_mutex_trylock though, i.e.
217 * returns EBUSY if the lock could not be acquired after the timeout
220 int pthread_mutex_lock_timeout_np(pthread_mutex_t *mutex, unsigned msecs);
222 int pthread_key_create(pthread_key_t *key, void (*destructor_function)(void *));
223 int pthread_key_delete (pthread_key_t);
224 int pthread_setspecific(pthread_key_t key, const void *value);
225 void *pthread_getspecific(pthread_key_t key);
227 int pthread_kill(pthread_t tid, int sig);
228 int pthread_sigmask(int how, const sigset_t *set, sigset_t *oset);
230 int pthread_getcpuclockid(pthread_t tid, clockid_t *clockid);
232 int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));
234 typedef void (*__pthread_cleanup_func_t)(void*);
236 typedef struct __pthread_cleanup_t {
237 struct __pthread_cleanup_t* __cleanup_prev;
238 __pthread_cleanup_func_t __cleanup_routine;
240 } __pthread_cleanup_t;
242 extern void __pthread_cleanup_push(__pthread_cleanup_t* c,
243 __pthread_cleanup_func_t routine,
246 extern void __pthread_cleanup_pop(__pthread_cleanup_t* c,
249 /* Believe or not, the definitions of pthread_cleanup_push and
250 * pthread_cleanup_pop below are correct. Posix states that these
251 * can be implemented as macros that might introduce opening and
252 * closing braces, and that using setjmp/longjmp/return/break/continue
253 * between them results in undefined behaviour.
255 * And indeed, GLibc and other C libraries use a similar definition
257 #define pthread_cleanup_push(routine, arg) \
259 __pthread_cleanup_t __cleanup; \
260 __pthread_cleanup_push( &__cleanup, (routine), (arg) ); \
262 #define pthread_cleanup_pop(execute) \
263 __pthread_cleanup_pop( &__cleanup, (execute)); \
270 /************ TO FIX ************/
272 #define LONG_LONG_MAX __LONG_LONG_MAX__
273 #define LONG_LONG_MIN (-__LONG_LONG_MAX__ - 1)
275 #endif // _PTHREAD_H_