1d19d7d58SLionel Sambuc /* This file is automatically generated. DO NOT EDIT! */
2*0a6a1f1dSLionel Sambuc /* Generated from: NetBSD: mknative-gcc,v 1.70 2013/05/05 07:11:34 skrll Exp */
3*0a6a1f1dSLionel Sambuc /* Generated from: NetBSD: mknative.common,v 1.8 2006/05/26 19:17:21 mrg Exp */
4d19d7d58SLionel Sambuc
5d19d7d58SLionel Sambuc /* Threads compatibility routines for libgcc2 and libobjc. */
6d19d7d58SLionel Sambuc /* Compile this one with gcc. */
7*0a6a1f1dSLionel Sambuc /* Copyright (C) 1997-2013 Free Software Foundation, Inc.
8d19d7d58SLionel Sambuc
9d19d7d58SLionel Sambuc This file is part of GCC.
10d19d7d58SLionel Sambuc
11d19d7d58SLionel Sambuc GCC is free software; you can redistribute it and/or modify it under
12d19d7d58SLionel Sambuc the terms of the GNU General Public License as published by the Free
13d19d7d58SLionel Sambuc Software Foundation; either version 3, or (at your option) any later
14d19d7d58SLionel Sambuc version.
15d19d7d58SLionel Sambuc
16d19d7d58SLionel Sambuc GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17d19d7d58SLionel Sambuc WARRANTY; without even the implied warranty of MERCHANTABILITY or
18d19d7d58SLionel Sambuc FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19d19d7d58SLionel Sambuc for more details.
20d19d7d58SLionel Sambuc
21d19d7d58SLionel Sambuc Under Section 7 of GPL version 3, you are granted additional
22d19d7d58SLionel Sambuc permissions described in the GCC Runtime Library Exception, version
23d19d7d58SLionel Sambuc 3.1, as published by the Free Software Foundation.
24d19d7d58SLionel Sambuc
25d19d7d58SLionel Sambuc You should have received a copy of the GNU General Public License and
26d19d7d58SLionel Sambuc a copy of the GCC Runtime Library Exception along with this program;
27d19d7d58SLionel Sambuc see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
28d19d7d58SLionel Sambuc <http://www.gnu.org/licenses/>. */
29d19d7d58SLionel Sambuc
30d19d7d58SLionel Sambuc #ifndef _GLIBCXX_GCC_GTHR_POSIX_H
31d19d7d58SLionel Sambuc #define _GLIBCXX_GCC_GTHR_POSIX_H
32d19d7d58SLionel Sambuc
33d19d7d58SLionel Sambuc /* POSIX threads specific definitions.
34d19d7d58SLionel Sambuc Easy, since the interface is just one-to-one mapping. */
35d19d7d58SLionel Sambuc
36d19d7d58SLionel Sambuc #define __GTHREADS 1
37d19d7d58SLionel Sambuc #define __GTHREADS_CXX0X 1
38d19d7d58SLionel Sambuc
39d19d7d58SLionel Sambuc #include <pthread.h>
40*0a6a1f1dSLionel Sambuc
41*0a6a1f1dSLionel Sambuc #if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \
42*0a6a1f1dSLionel Sambuc || !defined(_GTHREAD_USE_MUTEX_TIMEDLOCK))
43d19d7d58SLionel Sambuc # include <unistd.h>
44*0a6a1f1dSLionel Sambuc # if defined(_POSIX_TIMEOUTS) && _POSIX_TIMEOUTS >= 0
45*0a6a1f1dSLionel Sambuc # define _GTHREAD_USE_MUTEX_TIMEDLOCK 1
46*0a6a1f1dSLionel Sambuc # else
47*0a6a1f1dSLionel Sambuc # define _GTHREAD_USE_MUTEX_TIMEDLOCK 0
48*0a6a1f1dSLionel Sambuc # endif
49*0a6a1f1dSLionel Sambuc #endif
50d19d7d58SLionel Sambuc
51d19d7d58SLionel Sambuc typedef pthread_t __gthread_t;
52d19d7d58SLionel Sambuc typedef pthread_key_t __gthread_key_t;
53d19d7d58SLionel Sambuc typedef pthread_once_t __gthread_once_t;
54d19d7d58SLionel Sambuc typedef pthread_mutex_t __gthread_mutex_t;
55d19d7d58SLionel Sambuc typedef pthread_mutex_t __gthread_recursive_mutex_t;
56d19d7d58SLionel Sambuc typedef pthread_cond_t __gthread_cond_t;
57d19d7d58SLionel Sambuc typedef struct timespec __gthread_time_t;
58d19d7d58SLionel Sambuc
59d19d7d58SLionel Sambuc /* POSIX like conditional variables are supported. Please look at comments
60d19d7d58SLionel Sambuc in gthr.h for details. */
61d19d7d58SLionel Sambuc #define __GTHREAD_HAS_COND 1
62d19d7d58SLionel Sambuc
63d19d7d58SLionel Sambuc #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
64*0a6a1f1dSLionel Sambuc #define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
65d19d7d58SLionel Sambuc #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
66d19d7d58SLionel Sambuc #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
67d19d7d58SLionel Sambuc #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
68d19d7d58SLionel Sambuc #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
69d19d7d58SLionel Sambuc #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
70d19d7d58SLionel Sambuc #else
71d19d7d58SLionel Sambuc #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
72d19d7d58SLionel Sambuc #endif
73d19d7d58SLionel Sambuc #define __GTHREAD_COND_INIT PTHREAD_COND_INITIALIZER
74d19d7d58SLionel Sambuc #define __GTHREAD_TIME_INIT {0,0}
75d19d7d58SLionel Sambuc
76*0a6a1f1dSLionel Sambuc #ifdef _GTHREAD_USE_MUTEX_INIT_FUNC
77*0a6a1f1dSLionel Sambuc # undef __GTHREAD_MUTEX_INIT
78*0a6a1f1dSLionel Sambuc #endif
79*0a6a1f1dSLionel Sambuc #ifdef _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC
80*0a6a1f1dSLionel Sambuc # undef __GTHREAD_RECURSIVE_MUTEX_INIT
81*0a6a1f1dSLionel Sambuc # undef __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION
82*0a6a1f1dSLionel Sambuc # define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
83*0a6a1f1dSLionel Sambuc #endif
84*0a6a1f1dSLionel Sambuc #ifdef _GTHREAD_USE_COND_INIT_FUNC
85*0a6a1f1dSLionel Sambuc # undef __GTHREAD_COND_INIT
86*0a6a1f1dSLionel Sambuc # define __GTHREAD_COND_INIT_FUNCTION __gthread_cond_init_function
87*0a6a1f1dSLionel Sambuc #endif
88*0a6a1f1dSLionel Sambuc
89d19d7d58SLionel Sambuc #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
90d19d7d58SLionel Sambuc # ifndef __gthrw_pragma
91d19d7d58SLionel Sambuc # define __gthrw_pragma(pragma)
92d19d7d58SLionel Sambuc # endif
93d19d7d58SLionel Sambuc # define __gthrw2(name,name2,type) \
94d19d7d58SLionel Sambuc static __typeof(type) name __attribute__ ((__weakref__(#name2))); \
95d19d7d58SLionel Sambuc __gthrw_pragma(weak type)
96d19d7d58SLionel Sambuc # define __gthrw_(name) __gthrw_ ## name
97d19d7d58SLionel Sambuc #else
98d19d7d58SLionel Sambuc # define __gthrw2(name,name2,type)
99d19d7d58SLionel Sambuc # define __gthrw_(name) name
100d19d7d58SLionel Sambuc #endif
101d19d7d58SLionel Sambuc
102d19d7d58SLionel Sambuc /* Typically, __gthrw_foo is a weak reference to symbol foo. */
103d19d7d58SLionel Sambuc #define __gthrw(name) __gthrw2(__gthrw_ ## name,name,name)
104d19d7d58SLionel Sambuc
105d19d7d58SLionel Sambuc __gthrw(pthread_once)
106d19d7d58SLionel Sambuc __gthrw(pthread_getspecific)
107d19d7d58SLionel Sambuc __gthrw(pthread_setspecific)
108d19d7d58SLionel Sambuc
109d19d7d58SLionel Sambuc __gthrw(pthread_create)
110d19d7d58SLionel Sambuc __gthrw(pthread_join)
111d19d7d58SLionel Sambuc __gthrw(pthread_equal)
112d19d7d58SLionel Sambuc __gthrw(pthread_self)
113d19d7d58SLionel Sambuc __gthrw(pthread_detach)
114*0a6a1f1dSLionel Sambuc #ifndef __BIONIC__
115d19d7d58SLionel Sambuc __gthrw(pthread_cancel)
116*0a6a1f1dSLionel Sambuc #endif
117d19d7d58SLionel Sambuc __gthrw(sched_yield)
118d19d7d58SLionel Sambuc
119d19d7d58SLionel Sambuc __gthrw(pthread_mutex_lock)
120d19d7d58SLionel Sambuc __gthrw(pthread_mutex_trylock)
121*0a6a1f1dSLionel Sambuc #if _GTHREAD_USE_MUTEX_TIMEDLOCK
122d19d7d58SLionel Sambuc __gthrw(pthread_mutex_timedlock)
123d19d7d58SLionel Sambuc #endif
124d19d7d58SLionel Sambuc __gthrw(pthread_mutex_unlock)
125d19d7d58SLionel Sambuc __gthrw(pthread_mutex_init)
126d19d7d58SLionel Sambuc __gthrw(pthread_mutex_destroy)
127d19d7d58SLionel Sambuc
128*0a6a1f1dSLionel Sambuc __gthrw(pthread_cond_init)
129d19d7d58SLionel Sambuc __gthrw(pthread_cond_broadcast)
130d19d7d58SLionel Sambuc __gthrw(pthread_cond_signal)
131d19d7d58SLionel Sambuc __gthrw(pthread_cond_wait)
132d19d7d58SLionel Sambuc __gthrw(pthread_cond_timedwait)
133d19d7d58SLionel Sambuc __gthrw(pthread_cond_destroy)
134d19d7d58SLionel Sambuc
135d19d7d58SLionel Sambuc __gthrw(pthread_key_create)
136d19d7d58SLionel Sambuc __gthrw(pthread_key_delete)
137d19d7d58SLionel Sambuc __gthrw(pthread_mutexattr_init)
138d19d7d58SLionel Sambuc __gthrw(pthread_mutexattr_settype)
139d19d7d58SLionel Sambuc __gthrw(pthread_mutexattr_destroy)
140d19d7d58SLionel Sambuc
141d19d7d58SLionel Sambuc
142d19d7d58SLionel Sambuc #if defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)
143d19d7d58SLionel Sambuc /* Objective-C. */
144d19d7d58SLionel Sambuc __gthrw(pthread_exit)
145d19d7d58SLionel Sambuc #ifdef _POSIX_PRIORITY_SCHEDULING
146d19d7d58SLionel Sambuc #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
147d19d7d58SLionel Sambuc __gthrw(sched_get_priority_max)
148d19d7d58SLionel Sambuc __gthrw(sched_get_priority_min)
149d19d7d58SLionel Sambuc #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
150d19d7d58SLionel Sambuc #endif /* _POSIX_PRIORITY_SCHEDULING */
151d19d7d58SLionel Sambuc __gthrw(pthread_attr_destroy)
152d19d7d58SLionel Sambuc __gthrw(pthread_attr_init)
153d19d7d58SLionel Sambuc __gthrw(pthread_attr_setdetachstate)
154d19d7d58SLionel Sambuc #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
155d19d7d58SLionel Sambuc __gthrw(pthread_getschedparam)
156d19d7d58SLionel Sambuc __gthrw(pthread_setschedparam)
157d19d7d58SLionel Sambuc #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
158d19d7d58SLionel Sambuc #endif /* _LIBOBJC || _LIBOBJC_WEAK */
159d19d7d58SLionel Sambuc
160d19d7d58SLionel Sambuc #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
161d19d7d58SLionel Sambuc
162d19d7d58SLionel Sambuc /* On Solaris 2.6 up to 9, the libc exposes a POSIX threads interface even if
163d19d7d58SLionel Sambuc -pthreads is not specified. The functions are dummies and most return an
164d19d7d58SLionel Sambuc error value. However pthread_once returns 0 without invoking the routine
165d19d7d58SLionel Sambuc it is passed so we cannot pretend that the interface is active if -pthreads
166d19d7d58SLionel Sambuc is not specified. On Solaris 2.5.1, the interface is not exposed at all so
167d19d7d58SLionel Sambuc we need to play the usual game with weak symbols. On Solaris 10 and up, a
168d19d7d58SLionel Sambuc working interface is always exposed. On FreeBSD 6 and later, libc also
169d19d7d58SLionel Sambuc exposes a dummy POSIX threads interface, similar to what Solaris 2.6 up
170d19d7d58SLionel Sambuc to 9 does. FreeBSD >= 700014 even provides a pthread_cancel stub in libc,
171d19d7d58SLionel Sambuc which means the alternate __gthread_active_p below cannot be used there. */
172d19d7d58SLionel Sambuc
173d19d7d58SLionel Sambuc #if defined(__FreeBSD__) || (defined(__sun) && defined(__svr4__))
174d19d7d58SLionel Sambuc
175d19d7d58SLionel Sambuc static volatile int __gthread_active = -1;
176d19d7d58SLionel Sambuc
177d19d7d58SLionel Sambuc static void
__gthread_trigger(void)178d19d7d58SLionel Sambuc __gthread_trigger (void)
179d19d7d58SLionel Sambuc {
180d19d7d58SLionel Sambuc __gthread_active = 1;
181d19d7d58SLionel Sambuc }
182d19d7d58SLionel Sambuc
183d19d7d58SLionel Sambuc static inline int
__gthread_active_p(void)184d19d7d58SLionel Sambuc __gthread_active_p (void)
185d19d7d58SLionel Sambuc {
186d19d7d58SLionel Sambuc static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
187d19d7d58SLionel Sambuc static pthread_once_t __gthread_active_once = PTHREAD_ONCE_INIT;
188d19d7d58SLionel Sambuc
189d19d7d58SLionel Sambuc /* Avoid reading __gthread_active twice on the main code path. */
190d19d7d58SLionel Sambuc int __gthread_active_latest_value = __gthread_active;
191d19d7d58SLionel Sambuc
192d19d7d58SLionel Sambuc /* This test is not protected to avoid taking a lock on the main code
193d19d7d58SLionel Sambuc path so every update of __gthread_active in a threaded program must
194d19d7d58SLionel Sambuc be atomic with regard to the result of the test. */
195d19d7d58SLionel Sambuc if (__builtin_expect (__gthread_active_latest_value < 0, 0))
196d19d7d58SLionel Sambuc {
197d19d7d58SLionel Sambuc if (__gthrw_(pthread_once))
198d19d7d58SLionel Sambuc {
199d19d7d58SLionel Sambuc /* If this really is a threaded program, then we must ensure that
200d19d7d58SLionel Sambuc __gthread_active has been set to 1 before exiting this block. */
201d19d7d58SLionel Sambuc __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex);
202d19d7d58SLionel Sambuc __gthrw_(pthread_once) (&__gthread_active_once, __gthread_trigger);
203d19d7d58SLionel Sambuc __gthrw_(pthread_mutex_unlock) (&__gthread_active_mutex);
204d19d7d58SLionel Sambuc }
205d19d7d58SLionel Sambuc
206d19d7d58SLionel Sambuc /* Make sure we'll never enter this block again. */
207d19d7d58SLionel Sambuc if (__gthread_active < 0)
208d19d7d58SLionel Sambuc __gthread_active = 0;
209d19d7d58SLionel Sambuc
210d19d7d58SLionel Sambuc __gthread_active_latest_value = __gthread_active;
211d19d7d58SLionel Sambuc }
212d19d7d58SLionel Sambuc
213d19d7d58SLionel Sambuc return __gthread_active_latest_value != 0;
214d19d7d58SLionel Sambuc }
215d19d7d58SLionel Sambuc
216d19d7d58SLionel Sambuc #else /* neither FreeBSD nor Solaris */
217d19d7d58SLionel Sambuc
218*0a6a1f1dSLionel Sambuc /* For a program to be multi-threaded the only thing that it certainly must
219*0a6a1f1dSLionel Sambuc be using is pthread_create. However, there may be other libraries that
220*0a6a1f1dSLionel Sambuc intercept pthread_create with their own definitions to wrap pthreads
221*0a6a1f1dSLionel Sambuc functionality for some purpose. In those cases, pthread_create being
222*0a6a1f1dSLionel Sambuc defined might not necessarily mean that libpthread is actually linked
223*0a6a1f1dSLionel Sambuc in.
224*0a6a1f1dSLionel Sambuc
225*0a6a1f1dSLionel Sambuc For the GNU C library, we can use a known internal name. This is always
226*0a6a1f1dSLionel Sambuc available in the ABI, but no other library would define it. That is
227*0a6a1f1dSLionel Sambuc ideal, since any public pthread function might be intercepted just as
228*0a6a1f1dSLionel Sambuc pthread_create might be. __pthread_key_create is an "internal"
229*0a6a1f1dSLionel Sambuc implementation symbol, but it is part of the public exported ABI. Also,
230*0a6a1f1dSLionel Sambuc it's among the symbols that the static libpthread.a always links in
231*0a6a1f1dSLionel Sambuc whenever pthread_create is used, so there is no danger of a false
232*0a6a1f1dSLionel Sambuc negative result in any statically-linked, multi-threaded program.
233*0a6a1f1dSLionel Sambuc
234*0a6a1f1dSLionel Sambuc For others, we choose pthread_cancel as a function that seems unlikely
235*0a6a1f1dSLionel Sambuc to be redefined by an interceptor library. The bionic (Android) C
236*0a6a1f1dSLionel Sambuc library does not provide pthread_cancel, so we do use pthread_create
237*0a6a1f1dSLionel Sambuc there (and interceptor libraries lose). */
238*0a6a1f1dSLionel Sambuc
239*0a6a1f1dSLionel Sambuc #ifdef __GLIBC__
240*0a6a1f1dSLionel Sambuc __gthrw2(__gthrw_(__pthread_key_create),
241*0a6a1f1dSLionel Sambuc __pthread_key_create,
242*0a6a1f1dSLionel Sambuc pthread_key_create)
243*0a6a1f1dSLionel Sambuc # define GTHR_ACTIVE_PROXY __gthrw_(__pthread_key_create)
244*0a6a1f1dSLionel Sambuc #elif defined (__BIONIC__)
245*0a6a1f1dSLionel Sambuc # define GTHR_ACTIVE_PROXY __gthrw_(pthread_create)
246*0a6a1f1dSLionel Sambuc #else
247*0a6a1f1dSLionel Sambuc # define GTHR_ACTIVE_PROXY __gthrw_(pthread_cancel)
248*0a6a1f1dSLionel Sambuc #endif
249*0a6a1f1dSLionel Sambuc
250d19d7d58SLionel Sambuc static inline int
251d19d7d58SLionel Sambuc __gthread_active_p (void)
252d19d7d58SLionel Sambuc {
253d19d7d58SLionel Sambuc static void *const __gthread_active_ptr
254*0a6a1f1dSLionel Sambuc = __extension__ (void *) >HR_ACTIVE_PROXY;
255d19d7d58SLionel Sambuc return __gthread_active_ptr != 0;
256d19d7d58SLionel Sambuc }
257d19d7d58SLionel Sambuc
258d19d7d58SLionel Sambuc #endif /* FreeBSD or Solaris */
259d19d7d58SLionel Sambuc
260d19d7d58SLionel Sambuc #else /* not __GXX_WEAK__ */
261d19d7d58SLionel Sambuc
262d19d7d58SLionel Sambuc /* Similar to Solaris, HP-UX 11 for PA-RISC provides stubs for pthread
263d19d7d58SLionel Sambuc calls in shared flavors of the HP-UX C library. Most of the stubs
264d19d7d58SLionel Sambuc have no functionality. The details are described in the "libc cumulative
265d19d7d58SLionel Sambuc patch" for each subversion of HP-UX 11. There are two special interfaces
266d19d7d58SLionel Sambuc provided for checking whether an application is linked to a shared pthread
267d19d7d58SLionel Sambuc library or not. However, these interfaces aren't available in early
268d19d7d58SLionel Sambuc libpthread libraries. We also need a test that works for archive
269d19d7d58SLionel Sambuc libraries. We can't use pthread_once as some libc versions call the
270d19d7d58SLionel Sambuc init function. We also can't use pthread_create or pthread_attr_init
271d19d7d58SLionel Sambuc as these create a thread and thereby prevent changing the default stack
272d19d7d58SLionel Sambuc size. The function pthread_default_stacksize_np is available in both
273d19d7d58SLionel Sambuc the archive and shared versions of libpthread. It can be used to
274d19d7d58SLionel Sambuc determine the default pthread stack size. There is a stub in some
275d19d7d58SLionel Sambuc shared libc versions which returns a zero size if pthreads are not
276d19d7d58SLionel Sambuc active. We provide an equivalent stub to handle cases where libc
277d19d7d58SLionel Sambuc doesn't provide one. */
278d19d7d58SLionel Sambuc
279d19d7d58SLionel Sambuc #if defined(__hppa__) && defined(__hpux__)
280d19d7d58SLionel Sambuc
281d19d7d58SLionel Sambuc static volatile int __gthread_active = -1;
282d19d7d58SLionel Sambuc
283d19d7d58SLionel Sambuc static inline int
284d19d7d58SLionel Sambuc __gthread_active_p (void)
285d19d7d58SLionel Sambuc {
286d19d7d58SLionel Sambuc /* Avoid reading __gthread_active twice on the main code path. */
287d19d7d58SLionel Sambuc int __gthread_active_latest_value = __gthread_active;
288d19d7d58SLionel Sambuc size_t __s;
289d19d7d58SLionel Sambuc
290d19d7d58SLionel Sambuc if (__builtin_expect (__gthread_active_latest_value < 0, 0))
291d19d7d58SLionel Sambuc {
292d19d7d58SLionel Sambuc pthread_default_stacksize_np (0, &__s);
293d19d7d58SLionel Sambuc __gthread_active = __s ? 1 : 0;
294d19d7d58SLionel Sambuc __gthread_active_latest_value = __gthread_active;
295d19d7d58SLionel Sambuc }
296d19d7d58SLionel Sambuc
297d19d7d58SLionel Sambuc return __gthread_active_latest_value != 0;
298d19d7d58SLionel Sambuc }
299d19d7d58SLionel Sambuc
300d19d7d58SLionel Sambuc #else /* not hppa-hpux */
301d19d7d58SLionel Sambuc
302d19d7d58SLionel Sambuc static inline int
303d19d7d58SLionel Sambuc __gthread_active_p (void)
304d19d7d58SLionel Sambuc {
305d19d7d58SLionel Sambuc return 1;
306d19d7d58SLionel Sambuc }
307d19d7d58SLionel Sambuc
308d19d7d58SLionel Sambuc #endif /* hppa-hpux */
309d19d7d58SLionel Sambuc
310d19d7d58SLionel Sambuc #endif /* __GXX_WEAK__ */
311d19d7d58SLionel Sambuc
312d19d7d58SLionel Sambuc #ifdef _LIBOBJC
313d19d7d58SLionel Sambuc
314d19d7d58SLionel Sambuc /* This is the config.h file in libobjc/ */
315d19d7d58SLionel Sambuc #include <config.h>
316d19d7d58SLionel Sambuc
317d19d7d58SLionel Sambuc #ifdef HAVE_SCHED_H
318d19d7d58SLionel Sambuc # include <sched.h>
319d19d7d58SLionel Sambuc #endif
320d19d7d58SLionel Sambuc
321d19d7d58SLionel Sambuc /* Key structure for maintaining thread specific storage */
322d19d7d58SLionel Sambuc static pthread_key_t _objc_thread_storage;
323d19d7d58SLionel Sambuc static pthread_attr_t _objc_thread_attribs;
324d19d7d58SLionel Sambuc
325d19d7d58SLionel Sambuc /* Thread local storage for a single thread */
326d19d7d58SLionel Sambuc static void *thread_local_storage = NULL;
327d19d7d58SLionel Sambuc
328d19d7d58SLionel Sambuc /* Backend initialization functions */
329d19d7d58SLionel Sambuc
330d19d7d58SLionel Sambuc /* Initialize the threads subsystem. */
331d19d7d58SLionel Sambuc static inline int
__gthread_objc_init_thread_system(void)332d19d7d58SLionel Sambuc __gthread_objc_init_thread_system (void)
333d19d7d58SLionel Sambuc {
334d19d7d58SLionel Sambuc if (__gthread_active_p ())
335d19d7d58SLionel Sambuc {
336d19d7d58SLionel Sambuc /* Initialize the thread storage key. */
337d19d7d58SLionel Sambuc if (__gthrw_(pthread_key_create) (&_objc_thread_storage, NULL) == 0)
338d19d7d58SLionel Sambuc {
339d19d7d58SLionel Sambuc /* The normal default detach state for threads is
340d19d7d58SLionel Sambuc * PTHREAD_CREATE_JOINABLE which causes threads to not die
341d19d7d58SLionel Sambuc * when you think they should. */
342d19d7d58SLionel Sambuc if (__gthrw_(pthread_attr_init) (&_objc_thread_attribs) == 0
343d19d7d58SLionel Sambuc && __gthrw_(pthread_attr_setdetachstate) (&_objc_thread_attribs,
344d19d7d58SLionel Sambuc PTHREAD_CREATE_DETACHED) == 0)
345d19d7d58SLionel Sambuc return 0;
346d19d7d58SLionel Sambuc }
347d19d7d58SLionel Sambuc }
348d19d7d58SLionel Sambuc
349d19d7d58SLionel Sambuc return -1;
350d19d7d58SLionel Sambuc }
351d19d7d58SLionel Sambuc
352d19d7d58SLionel Sambuc /* Close the threads subsystem. */
353d19d7d58SLionel Sambuc static inline int
__gthread_objc_close_thread_system(void)354d19d7d58SLionel Sambuc __gthread_objc_close_thread_system (void)
355d19d7d58SLionel Sambuc {
356d19d7d58SLionel Sambuc if (__gthread_active_p ()
357d19d7d58SLionel Sambuc && __gthrw_(pthread_key_delete) (_objc_thread_storage) == 0
358d19d7d58SLionel Sambuc && __gthrw_(pthread_attr_destroy) (&_objc_thread_attribs) == 0)
359d19d7d58SLionel Sambuc return 0;
360d19d7d58SLionel Sambuc
361d19d7d58SLionel Sambuc return -1;
362d19d7d58SLionel Sambuc }
363d19d7d58SLionel Sambuc
364d19d7d58SLionel Sambuc /* Backend thread functions */
365d19d7d58SLionel Sambuc
366d19d7d58SLionel Sambuc /* Create a new thread of execution. */
367d19d7d58SLionel Sambuc static inline objc_thread_t
__gthread_objc_thread_detach(void (* func)(void *),void * arg)368d19d7d58SLionel Sambuc __gthread_objc_thread_detach (void (*func)(void *), void *arg)
369d19d7d58SLionel Sambuc {
370d19d7d58SLionel Sambuc objc_thread_t thread_id;
371d19d7d58SLionel Sambuc pthread_t new_thread_handle;
372d19d7d58SLionel Sambuc
373d19d7d58SLionel Sambuc if (!__gthread_active_p ())
374d19d7d58SLionel Sambuc return NULL;
375d19d7d58SLionel Sambuc
376*0a6a1f1dSLionel Sambuc if (!(__gthrw_(pthread_create) (&new_thread_handle, &_objc_thread_attribs,
377*0a6a1f1dSLionel Sambuc (void *) func, arg)))
378d19d7d58SLionel Sambuc thread_id = (objc_thread_t) new_thread_handle;
379d19d7d58SLionel Sambuc else
380d19d7d58SLionel Sambuc thread_id = NULL;
381d19d7d58SLionel Sambuc
382d19d7d58SLionel Sambuc return thread_id;
383d19d7d58SLionel Sambuc }
384d19d7d58SLionel Sambuc
385d19d7d58SLionel Sambuc /* Set the current thread's priority. */
386d19d7d58SLionel Sambuc static inline int
__gthread_objc_thread_set_priority(int priority)387d19d7d58SLionel Sambuc __gthread_objc_thread_set_priority (int priority)
388d19d7d58SLionel Sambuc {
389d19d7d58SLionel Sambuc if (!__gthread_active_p ())
390d19d7d58SLionel Sambuc return -1;
391d19d7d58SLionel Sambuc else
392d19d7d58SLionel Sambuc {
393d19d7d58SLionel Sambuc #ifdef _POSIX_PRIORITY_SCHEDULING
394d19d7d58SLionel Sambuc #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
395d19d7d58SLionel Sambuc pthread_t thread_id = __gthrw_(pthread_self) ();
396d19d7d58SLionel Sambuc int policy;
397d19d7d58SLionel Sambuc struct sched_param params;
398d19d7d58SLionel Sambuc int priority_min, priority_max;
399d19d7d58SLionel Sambuc
400d19d7d58SLionel Sambuc if (__gthrw_(pthread_getschedparam) (thread_id, &policy, ¶ms) == 0)
401d19d7d58SLionel Sambuc {
402d19d7d58SLionel Sambuc if ((priority_max = __gthrw_(sched_get_priority_max) (policy)) == -1)
403d19d7d58SLionel Sambuc return -1;
404d19d7d58SLionel Sambuc
405d19d7d58SLionel Sambuc if ((priority_min = __gthrw_(sched_get_priority_min) (policy)) == -1)
406d19d7d58SLionel Sambuc return -1;
407d19d7d58SLionel Sambuc
408d19d7d58SLionel Sambuc if (priority > priority_max)
409d19d7d58SLionel Sambuc priority = priority_max;
410d19d7d58SLionel Sambuc else if (priority < priority_min)
411d19d7d58SLionel Sambuc priority = priority_min;
412d19d7d58SLionel Sambuc params.sched_priority = priority;
413d19d7d58SLionel Sambuc
414d19d7d58SLionel Sambuc /*
415d19d7d58SLionel Sambuc * The solaris 7 and several other man pages incorrectly state that
416d19d7d58SLionel Sambuc * this should be a pointer to policy but pthread.h is universally
417d19d7d58SLionel Sambuc * at odds with this.
418d19d7d58SLionel Sambuc */
419d19d7d58SLionel Sambuc if (__gthrw_(pthread_setschedparam) (thread_id, policy, ¶ms) == 0)
420d19d7d58SLionel Sambuc return 0;
421d19d7d58SLionel Sambuc }
422d19d7d58SLionel Sambuc #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
423d19d7d58SLionel Sambuc #endif /* _POSIX_PRIORITY_SCHEDULING */
424d19d7d58SLionel Sambuc return -1;
425d19d7d58SLionel Sambuc }
426d19d7d58SLionel Sambuc }
427d19d7d58SLionel Sambuc
428d19d7d58SLionel Sambuc /* Return the current thread's priority. */
429d19d7d58SLionel Sambuc static inline int
__gthread_objc_thread_get_priority(void)430d19d7d58SLionel Sambuc __gthread_objc_thread_get_priority (void)
431d19d7d58SLionel Sambuc {
432d19d7d58SLionel Sambuc #ifdef _POSIX_PRIORITY_SCHEDULING
433d19d7d58SLionel Sambuc #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
434d19d7d58SLionel Sambuc if (__gthread_active_p ())
435d19d7d58SLionel Sambuc {
436d19d7d58SLionel Sambuc int policy;
437d19d7d58SLionel Sambuc struct sched_param params;
438d19d7d58SLionel Sambuc
439d19d7d58SLionel Sambuc if (__gthrw_(pthread_getschedparam) (__gthrw_(pthread_self) (), &policy, ¶ms) == 0)
440d19d7d58SLionel Sambuc return params.sched_priority;
441d19d7d58SLionel Sambuc else
442d19d7d58SLionel Sambuc return -1;
443d19d7d58SLionel Sambuc }
444d19d7d58SLionel Sambuc else
445d19d7d58SLionel Sambuc #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
446d19d7d58SLionel Sambuc #endif /* _POSIX_PRIORITY_SCHEDULING */
447d19d7d58SLionel Sambuc return OBJC_THREAD_INTERACTIVE_PRIORITY;
448d19d7d58SLionel Sambuc }
449d19d7d58SLionel Sambuc
450d19d7d58SLionel Sambuc /* Yield our process time to another thread. */
451d19d7d58SLionel Sambuc static inline void
__gthread_objc_thread_yield(void)452d19d7d58SLionel Sambuc __gthread_objc_thread_yield (void)
453d19d7d58SLionel Sambuc {
454d19d7d58SLionel Sambuc if (__gthread_active_p ())
455d19d7d58SLionel Sambuc __gthrw_(sched_yield) ();
456d19d7d58SLionel Sambuc }
457d19d7d58SLionel Sambuc
458d19d7d58SLionel Sambuc /* Terminate the current thread. */
459d19d7d58SLionel Sambuc static inline int
__gthread_objc_thread_exit(void)460d19d7d58SLionel Sambuc __gthread_objc_thread_exit (void)
461d19d7d58SLionel Sambuc {
462d19d7d58SLionel Sambuc if (__gthread_active_p ())
463d19d7d58SLionel Sambuc /* exit the thread */
464d19d7d58SLionel Sambuc __gthrw_(pthread_exit) (&__objc_thread_exit_status);
465d19d7d58SLionel Sambuc
466d19d7d58SLionel Sambuc /* Failed if we reached here */
467d19d7d58SLionel Sambuc return -1;
468d19d7d58SLionel Sambuc }
469d19d7d58SLionel Sambuc
470d19d7d58SLionel Sambuc /* Returns an integer value which uniquely describes a thread. */
471d19d7d58SLionel Sambuc static inline objc_thread_t
__gthread_objc_thread_id(void)472d19d7d58SLionel Sambuc __gthread_objc_thread_id (void)
473d19d7d58SLionel Sambuc {
474d19d7d58SLionel Sambuc if (__gthread_active_p ())
475d19d7d58SLionel Sambuc return (objc_thread_t) __gthrw_(pthread_self) ();
476d19d7d58SLionel Sambuc else
477d19d7d58SLionel Sambuc return (objc_thread_t) 1;
478d19d7d58SLionel Sambuc }
479d19d7d58SLionel Sambuc
480d19d7d58SLionel Sambuc /* Sets the thread's local storage pointer. */
481d19d7d58SLionel Sambuc static inline int
__gthread_objc_thread_set_data(void * value)482d19d7d58SLionel Sambuc __gthread_objc_thread_set_data (void *value)
483d19d7d58SLionel Sambuc {
484d19d7d58SLionel Sambuc if (__gthread_active_p ())
485d19d7d58SLionel Sambuc return __gthrw_(pthread_setspecific) (_objc_thread_storage, value);
486d19d7d58SLionel Sambuc else
487d19d7d58SLionel Sambuc {
488d19d7d58SLionel Sambuc thread_local_storage = value;
489d19d7d58SLionel Sambuc return 0;
490d19d7d58SLionel Sambuc }
491d19d7d58SLionel Sambuc }
492d19d7d58SLionel Sambuc
493d19d7d58SLionel Sambuc /* Returns the thread's local storage pointer. */
494d19d7d58SLionel Sambuc static inline void *
__gthread_objc_thread_get_data(void)495d19d7d58SLionel Sambuc __gthread_objc_thread_get_data (void)
496d19d7d58SLionel Sambuc {
497d19d7d58SLionel Sambuc if (__gthread_active_p ())
498d19d7d58SLionel Sambuc return __gthrw_(pthread_getspecific) (_objc_thread_storage);
499d19d7d58SLionel Sambuc else
500d19d7d58SLionel Sambuc return thread_local_storage;
501d19d7d58SLionel Sambuc }
502d19d7d58SLionel Sambuc
503d19d7d58SLionel Sambuc /* Backend mutex functions */
504d19d7d58SLionel Sambuc
505d19d7d58SLionel Sambuc /* Allocate a mutex. */
506d19d7d58SLionel Sambuc static inline int
__gthread_objc_mutex_allocate(objc_mutex_t mutex)507d19d7d58SLionel Sambuc __gthread_objc_mutex_allocate (objc_mutex_t mutex)
508d19d7d58SLionel Sambuc {
509d19d7d58SLionel Sambuc if (__gthread_active_p ())
510d19d7d58SLionel Sambuc {
511d19d7d58SLionel Sambuc mutex->backend = objc_malloc (sizeof (pthread_mutex_t));
512d19d7d58SLionel Sambuc
513d19d7d58SLionel Sambuc if (__gthrw_(pthread_mutex_init) ((pthread_mutex_t *) mutex->backend, NULL))
514d19d7d58SLionel Sambuc {
515d19d7d58SLionel Sambuc objc_free (mutex->backend);
516d19d7d58SLionel Sambuc mutex->backend = NULL;
517d19d7d58SLionel Sambuc return -1;
518d19d7d58SLionel Sambuc }
519d19d7d58SLionel Sambuc }
520d19d7d58SLionel Sambuc
521d19d7d58SLionel Sambuc return 0;
522d19d7d58SLionel Sambuc }
523d19d7d58SLionel Sambuc
524d19d7d58SLionel Sambuc /* Deallocate a mutex. */
525d19d7d58SLionel Sambuc static inline int
__gthread_objc_mutex_deallocate(objc_mutex_t mutex)526d19d7d58SLionel Sambuc __gthread_objc_mutex_deallocate (objc_mutex_t mutex)
527d19d7d58SLionel Sambuc {
528d19d7d58SLionel Sambuc if (__gthread_active_p ())
529d19d7d58SLionel Sambuc {
530d19d7d58SLionel Sambuc int count;
531d19d7d58SLionel Sambuc
532d19d7d58SLionel Sambuc /*
533d19d7d58SLionel Sambuc * Posix Threads specifically require that the thread be unlocked
534d19d7d58SLionel Sambuc * for __gthrw_(pthread_mutex_destroy) to work.
535d19d7d58SLionel Sambuc */
536d19d7d58SLionel Sambuc
537d19d7d58SLionel Sambuc do
538d19d7d58SLionel Sambuc {
539d19d7d58SLionel Sambuc count = __gthrw_(pthread_mutex_unlock) ((pthread_mutex_t *) mutex->backend);
540d19d7d58SLionel Sambuc if (count < 0)
541d19d7d58SLionel Sambuc return -1;
542d19d7d58SLionel Sambuc }
543d19d7d58SLionel Sambuc while (count);
544d19d7d58SLionel Sambuc
545d19d7d58SLionel Sambuc if (__gthrw_(pthread_mutex_destroy) ((pthread_mutex_t *) mutex->backend))
546d19d7d58SLionel Sambuc return -1;
547d19d7d58SLionel Sambuc
548d19d7d58SLionel Sambuc objc_free (mutex->backend);
549d19d7d58SLionel Sambuc mutex->backend = NULL;
550d19d7d58SLionel Sambuc }
551d19d7d58SLionel Sambuc return 0;
552d19d7d58SLionel Sambuc }
553d19d7d58SLionel Sambuc
554d19d7d58SLionel Sambuc /* Grab a lock on a mutex. */
555d19d7d58SLionel Sambuc static inline int
__gthread_objc_mutex_lock(objc_mutex_t mutex)556d19d7d58SLionel Sambuc __gthread_objc_mutex_lock (objc_mutex_t mutex)
557d19d7d58SLionel Sambuc {
558d19d7d58SLionel Sambuc if (__gthread_active_p ()
559d19d7d58SLionel Sambuc && __gthrw_(pthread_mutex_lock) ((pthread_mutex_t *) mutex->backend) != 0)
560d19d7d58SLionel Sambuc {
561d19d7d58SLionel Sambuc return -1;
562d19d7d58SLionel Sambuc }
563d19d7d58SLionel Sambuc
564d19d7d58SLionel Sambuc return 0;
565d19d7d58SLionel Sambuc }
566d19d7d58SLionel Sambuc
567d19d7d58SLionel Sambuc /* Try to grab a lock on a mutex. */
568d19d7d58SLionel Sambuc static inline int
__gthread_objc_mutex_trylock(objc_mutex_t mutex)569d19d7d58SLionel Sambuc __gthread_objc_mutex_trylock (objc_mutex_t mutex)
570d19d7d58SLionel Sambuc {
571d19d7d58SLionel Sambuc if (__gthread_active_p ()
572d19d7d58SLionel Sambuc && __gthrw_(pthread_mutex_trylock) ((pthread_mutex_t *) mutex->backend) != 0)
573d19d7d58SLionel Sambuc {
574d19d7d58SLionel Sambuc return -1;
575d19d7d58SLionel Sambuc }
576d19d7d58SLionel Sambuc
577d19d7d58SLionel Sambuc return 0;
578d19d7d58SLionel Sambuc }
579d19d7d58SLionel Sambuc
580d19d7d58SLionel Sambuc /* Unlock the mutex */
581d19d7d58SLionel Sambuc static inline int
__gthread_objc_mutex_unlock(objc_mutex_t mutex)582d19d7d58SLionel Sambuc __gthread_objc_mutex_unlock (objc_mutex_t mutex)
583d19d7d58SLionel Sambuc {
584d19d7d58SLionel Sambuc if (__gthread_active_p ()
585d19d7d58SLionel Sambuc && __gthrw_(pthread_mutex_unlock) ((pthread_mutex_t *) mutex->backend) != 0)
586d19d7d58SLionel Sambuc {
587d19d7d58SLionel Sambuc return -1;
588d19d7d58SLionel Sambuc }
589d19d7d58SLionel Sambuc
590d19d7d58SLionel Sambuc return 0;
591d19d7d58SLionel Sambuc }
592d19d7d58SLionel Sambuc
593d19d7d58SLionel Sambuc /* Backend condition mutex functions */
594d19d7d58SLionel Sambuc
595d19d7d58SLionel Sambuc /* Allocate a condition. */
596d19d7d58SLionel Sambuc static inline int
__gthread_objc_condition_allocate(objc_condition_t condition)597d19d7d58SLionel Sambuc __gthread_objc_condition_allocate (objc_condition_t condition)
598d19d7d58SLionel Sambuc {
599d19d7d58SLionel Sambuc if (__gthread_active_p ())
600d19d7d58SLionel Sambuc {
601d19d7d58SLionel Sambuc condition->backend = objc_malloc (sizeof (pthread_cond_t));
602d19d7d58SLionel Sambuc
603d19d7d58SLionel Sambuc if (__gthrw_(pthread_cond_init) ((pthread_cond_t *) condition->backend, NULL))
604d19d7d58SLionel Sambuc {
605d19d7d58SLionel Sambuc objc_free (condition->backend);
606d19d7d58SLionel Sambuc condition->backend = NULL;
607d19d7d58SLionel Sambuc return -1;
608d19d7d58SLionel Sambuc }
609d19d7d58SLionel Sambuc }
610d19d7d58SLionel Sambuc
611d19d7d58SLionel Sambuc return 0;
612d19d7d58SLionel Sambuc }
613d19d7d58SLionel Sambuc
614d19d7d58SLionel Sambuc /* Deallocate a condition. */
615d19d7d58SLionel Sambuc static inline int
__gthread_objc_condition_deallocate(objc_condition_t condition)616d19d7d58SLionel Sambuc __gthread_objc_condition_deallocate (objc_condition_t condition)
617d19d7d58SLionel Sambuc {
618d19d7d58SLionel Sambuc if (__gthread_active_p ())
619d19d7d58SLionel Sambuc {
620d19d7d58SLionel Sambuc if (__gthrw_(pthread_cond_destroy) ((pthread_cond_t *) condition->backend))
621d19d7d58SLionel Sambuc return -1;
622d19d7d58SLionel Sambuc
623d19d7d58SLionel Sambuc objc_free (condition->backend);
624d19d7d58SLionel Sambuc condition->backend = NULL;
625d19d7d58SLionel Sambuc }
626d19d7d58SLionel Sambuc return 0;
627d19d7d58SLionel Sambuc }
628d19d7d58SLionel Sambuc
629d19d7d58SLionel Sambuc /* Wait on the condition */
630d19d7d58SLionel Sambuc static inline int
__gthread_objc_condition_wait(objc_condition_t condition,objc_mutex_t mutex)631d19d7d58SLionel Sambuc __gthread_objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex)
632d19d7d58SLionel Sambuc {
633d19d7d58SLionel Sambuc if (__gthread_active_p ())
634d19d7d58SLionel Sambuc return __gthrw_(pthread_cond_wait) ((pthread_cond_t *) condition->backend,
635d19d7d58SLionel Sambuc (pthread_mutex_t *) mutex->backend);
636d19d7d58SLionel Sambuc else
637d19d7d58SLionel Sambuc return 0;
638d19d7d58SLionel Sambuc }
639d19d7d58SLionel Sambuc
640d19d7d58SLionel Sambuc /* Wake up all threads waiting on this condition. */
641d19d7d58SLionel Sambuc static inline int
__gthread_objc_condition_broadcast(objc_condition_t condition)642d19d7d58SLionel Sambuc __gthread_objc_condition_broadcast (objc_condition_t condition)
643d19d7d58SLionel Sambuc {
644d19d7d58SLionel Sambuc if (__gthread_active_p ())
645d19d7d58SLionel Sambuc return __gthrw_(pthread_cond_broadcast) ((pthread_cond_t *) condition->backend);
646d19d7d58SLionel Sambuc else
647d19d7d58SLionel Sambuc return 0;
648d19d7d58SLionel Sambuc }
649d19d7d58SLionel Sambuc
650d19d7d58SLionel Sambuc /* Wake up one thread waiting on this condition. */
651d19d7d58SLionel Sambuc static inline int
__gthread_objc_condition_signal(objc_condition_t condition)652d19d7d58SLionel Sambuc __gthread_objc_condition_signal (objc_condition_t condition)
653d19d7d58SLionel Sambuc {
654d19d7d58SLionel Sambuc if (__gthread_active_p ())
655d19d7d58SLionel Sambuc return __gthrw_(pthread_cond_signal) ((pthread_cond_t *) condition->backend);
656d19d7d58SLionel Sambuc else
657d19d7d58SLionel Sambuc return 0;
658d19d7d58SLionel Sambuc }
659d19d7d58SLionel Sambuc
660d19d7d58SLionel Sambuc #else /* _LIBOBJC */
661d19d7d58SLionel Sambuc
662d19d7d58SLionel Sambuc static inline int
__gthread_create(__gthread_t * __threadid,void * (* __func)(void *),void * __args)663d19d7d58SLionel Sambuc __gthread_create (__gthread_t *__threadid, void *(*__func) (void*),
664d19d7d58SLionel Sambuc void *__args)
665d19d7d58SLionel Sambuc {
666d19d7d58SLionel Sambuc return __gthrw_(pthread_create) (__threadid, NULL, __func, __args);
667d19d7d58SLionel Sambuc }
668d19d7d58SLionel Sambuc
669d19d7d58SLionel Sambuc static inline int
__gthread_join(__gthread_t __threadid,void ** __value_ptr)670d19d7d58SLionel Sambuc __gthread_join (__gthread_t __threadid, void **__value_ptr)
671d19d7d58SLionel Sambuc {
672d19d7d58SLionel Sambuc return __gthrw_(pthread_join) (__threadid, __value_ptr);
673d19d7d58SLionel Sambuc }
674d19d7d58SLionel Sambuc
675d19d7d58SLionel Sambuc static inline int
__gthread_detach(__gthread_t __threadid)676d19d7d58SLionel Sambuc __gthread_detach (__gthread_t __threadid)
677d19d7d58SLionel Sambuc {
678d19d7d58SLionel Sambuc return __gthrw_(pthread_detach) (__threadid);
679d19d7d58SLionel Sambuc }
680d19d7d58SLionel Sambuc
681d19d7d58SLionel Sambuc static inline int
__gthread_equal(__gthread_t __t1,__gthread_t __t2)682d19d7d58SLionel Sambuc __gthread_equal (__gthread_t __t1, __gthread_t __t2)
683d19d7d58SLionel Sambuc {
684d19d7d58SLionel Sambuc return __gthrw_(pthread_equal) (__t1, __t2);
685d19d7d58SLionel Sambuc }
686d19d7d58SLionel Sambuc
687d19d7d58SLionel Sambuc static inline __gthread_t
__gthread_self(void)688d19d7d58SLionel Sambuc __gthread_self (void)
689d19d7d58SLionel Sambuc {
690d19d7d58SLionel Sambuc return __gthrw_(pthread_self) ();
691d19d7d58SLionel Sambuc }
692d19d7d58SLionel Sambuc
693d19d7d58SLionel Sambuc static inline int
__gthread_yield(void)694d19d7d58SLionel Sambuc __gthread_yield (void)
695d19d7d58SLionel Sambuc {
696d19d7d58SLionel Sambuc return __gthrw_(sched_yield) ();
697d19d7d58SLionel Sambuc }
698d19d7d58SLionel Sambuc
699d19d7d58SLionel Sambuc static inline int
__gthread_once(__gthread_once_t * __once,void (* __func)(void))700d19d7d58SLionel Sambuc __gthread_once (__gthread_once_t *__once, void (*__func) (void))
701d19d7d58SLionel Sambuc {
702d19d7d58SLionel Sambuc if (__gthread_active_p ())
703d19d7d58SLionel Sambuc return __gthrw_(pthread_once) (__once, __func);
704d19d7d58SLionel Sambuc else
705d19d7d58SLionel Sambuc return -1;
706d19d7d58SLionel Sambuc }
707d19d7d58SLionel Sambuc
708d19d7d58SLionel Sambuc static inline int
__gthread_key_create(__gthread_key_t * __key,void (* __dtor)(void *))709d19d7d58SLionel Sambuc __gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
710d19d7d58SLionel Sambuc {
711d19d7d58SLionel Sambuc return __gthrw_(pthread_key_create) (__key, __dtor);
712d19d7d58SLionel Sambuc }
713d19d7d58SLionel Sambuc
714d19d7d58SLionel Sambuc static inline int
__gthread_key_delete(__gthread_key_t __key)715d19d7d58SLionel Sambuc __gthread_key_delete (__gthread_key_t __key)
716d19d7d58SLionel Sambuc {
717d19d7d58SLionel Sambuc return __gthrw_(pthread_key_delete) (__key);
718d19d7d58SLionel Sambuc }
719d19d7d58SLionel Sambuc
720d19d7d58SLionel Sambuc static inline void *
__gthread_getspecific(__gthread_key_t __key)721d19d7d58SLionel Sambuc __gthread_getspecific (__gthread_key_t __key)
722d19d7d58SLionel Sambuc {
723d19d7d58SLionel Sambuc return __gthrw_(pthread_getspecific) (__key);
724d19d7d58SLionel Sambuc }
725d19d7d58SLionel Sambuc
726d19d7d58SLionel Sambuc static inline int
__gthread_setspecific(__gthread_key_t __key,const void * __ptr)727d19d7d58SLionel Sambuc __gthread_setspecific (__gthread_key_t __key, const void *__ptr)
728d19d7d58SLionel Sambuc {
729d19d7d58SLionel Sambuc return __gthrw_(pthread_setspecific) (__key, __ptr);
730d19d7d58SLionel Sambuc }
731d19d7d58SLionel Sambuc
732*0a6a1f1dSLionel Sambuc static inline void
__gthread_mutex_init_function(__gthread_mutex_t * __mutex)733*0a6a1f1dSLionel Sambuc __gthread_mutex_init_function (__gthread_mutex_t *__mutex)
734*0a6a1f1dSLionel Sambuc {
735*0a6a1f1dSLionel Sambuc if (__gthread_active_p ())
736*0a6a1f1dSLionel Sambuc __gthrw_(pthread_mutex_init) (__mutex, NULL);
737*0a6a1f1dSLionel Sambuc }
738*0a6a1f1dSLionel Sambuc
739d19d7d58SLionel Sambuc static inline int
__gthread_mutex_destroy(__gthread_mutex_t * __mutex)740d19d7d58SLionel Sambuc __gthread_mutex_destroy (__gthread_mutex_t *__mutex)
741d19d7d58SLionel Sambuc {
742d19d7d58SLionel Sambuc if (__gthread_active_p ())
743d19d7d58SLionel Sambuc return __gthrw_(pthread_mutex_destroy) (__mutex);
744d19d7d58SLionel Sambuc else
745d19d7d58SLionel Sambuc return 0;
746d19d7d58SLionel Sambuc }
747d19d7d58SLionel Sambuc
748d19d7d58SLionel Sambuc static inline int
__gthread_mutex_lock(__gthread_mutex_t * __mutex)749d19d7d58SLionel Sambuc __gthread_mutex_lock (__gthread_mutex_t *__mutex)
750d19d7d58SLionel Sambuc {
751d19d7d58SLionel Sambuc if (__gthread_active_p ())
752d19d7d58SLionel Sambuc return __gthrw_(pthread_mutex_lock) (__mutex);
753d19d7d58SLionel Sambuc else
754d19d7d58SLionel Sambuc return 0;
755d19d7d58SLionel Sambuc }
756d19d7d58SLionel Sambuc
757d19d7d58SLionel Sambuc static inline int
__gthread_mutex_trylock(__gthread_mutex_t * __mutex)758d19d7d58SLionel Sambuc __gthread_mutex_trylock (__gthread_mutex_t *__mutex)
759d19d7d58SLionel Sambuc {
760d19d7d58SLionel Sambuc if (__gthread_active_p ())
761d19d7d58SLionel Sambuc return __gthrw_(pthread_mutex_trylock) (__mutex);
762d19d7d58SLionel Sambuc else
763d19d7d58SLionel Sambuc return 0;
764d19d7d58SLionel Sambuc }
765d19d7d58SLionel Sambuc
766*0a6a1f1dSLionel Sambuc #if _GTHREAD_USE_MUTEX_TIMEDLOCK
767d19d7d58SLionel Sambuc static inline int
__gthread_mutex_timedlock(__gthread_mutex_t * __mutex,const __gthread_time_t * __abs_timeout)768d19d7d58SLionel Sambuc __gthread_mutex_timedlock (__gthread_mutex_t *__mutex,
769d19d7d58SLionel Sambuc const __gthread_time_t *__abs_timeout)
770d19d7d58SLionel Sambuc {
771d19d7d58SLionel Sambuc if (__gthread_active_p ())
772d19d7d58SLionel Sambuc return __gthrw_(pthread_mutex_timedlock) (__mutex, __abs_timeout);
773d19d7d58SLionel Sambuc else
774d19d7d58SLionel Sambuc return 0;
775d19d7d58SLionel Sambuc }
776d19d7d58SLionel Sambuc #endif
777d19d7d58SLionel Sambuc
778d19d7d58SLionel Sambuc static inline int
__gthread_mutex_unlock(__gthread_mutex_t * __mutex)779d19d7d58SLionel Sambuc __gthread_mutex_unlock (__gthread_mutex_t *__mutex)
780d19d7d58SLionel Sambuc {
781d19d7d58SLionel Sambuc if (__gthread_active_p ())
782d19d7d58SLionel Sambuc return __gthrw_(pthread_mutex_unlock) (__mutex);
783d19d7d58SLionel Sambuc else
784d19d7d58SLionel Sambuc return 0;
785d19d7d58SLionel Sambuc }
786d19d7d58SLionel Sambuc
787*0a6a1f1dSLionel Sambuc #if !defined( PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) \
788*0a6a1f1dSLionel Sambuc || defined(_GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC)
789d19d7d58SLionel Sambuc static inline int
__gthread_recursive_mutex_init_function(__gthread_recursive_mutex_t * __mutex)790d19d7d58SLionel Sambuc __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
791d19d7d58SLionel Sambuc {
792d19d7d58SLionel Sambuc if (__gthread_active_p ())
793d19d7d58SLionel Sambuc {
794d19d7d58SLionel Sambuc pthread_mutexattr_t __attr;
795d19d7d58SLionel Sambuc int __r;
796d19d7d58SLionel Sambuc
797d19d7d58SLionel Sambuc __r = __gthrw_(pthread_mutexattr_init) (&__attr);
798d19d7d58SLionel Sambuc if (!__r)
799d19d7d58SLionel Sambuc __r = __gthrw_(pthread_mutexattr_settype) (&__attr,
800d19d7d58SLionel Sambuc PTHREAD_MUTEX_RECURSIVE);
801d19d7d58SLionel Sambuc if (!__r)
802d19d7d58SLionel Sambuc __r = __gthrw_(pthread_mutex_init) (__mutex, &__attr);
803d19d7d58SLionel Sambuc if (!__r)
804d19d7d58SLionel Sambuc __r = __gthrw_(pthread_mutexattr_destroy) (&__attr);
805d19d7d58SLionel Sambuc return __r;
806d19d7d58SLionel Sambuc }
807d19d7d58SLionel Sambuc return 0;
808d19d7d58SLionel Sambuc }
809d19d7d58SLionel Sambuc #endif
810d19d7d58SLionel Sambuc
811d19d7d58SLionel Sambuc static inline int
__gthread_recursive_mutex_lock(__gthread_recursive_mutex_t * __mutex)812d19d7d58SLionel Sambuc __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
813d19d7d58SLionel Sambuc {
814d19d7d58SLionel Sambuc return __gthread_mutex_lock (__mutex);
815d19d7d58SLionel Sambuc }
816d19d7d58SLionel Sambuc
817d19d7d58SLionel Sambuc static inline int
__gthread_recursive_mutex_trylock(__gthread_recursive_mutex_t * __mutex)818d19d7d58SLionel Sambuc __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
819d19d7d58SLionel Sambuc {
820d19d7d58SLionel Sambuc return __gthread_mutex_trylock (__mutex);
821d19d7d58SLionel Sambuc }
822d19d7d58SLionel Sambuc
823*0a6a1f1dSLionel Sambuc #if _GTHREAD_USE_MUTEX_TIMEDLOCK
824d19d7d58SLionel Sambuc static inline int
__gthread_recursive_mutex_timedlock(__gthread_recursive_mutex_t * __mutex,const __gthread_time_t * __abs_timeout)825d19d7d58SLionel Sambuc __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *__mutex,
826d19d7d58SLionel Sambuc const __gthread_time_t *__abs_timeout)
827d19d7d58SLionel Sambuc {
828d19d7d58SLionel Sambuc return __gthread_mutex_timedlock (__mutex, __abs_timeout);
829d19d7d58SLionel Sambuc }
830d19d7d58SLionel Sambuc #endif
831d19d7d58SLionel Sambuc
832d19d7d58SLionel Sambuc static inline int
__gthread_recursive_mutex_unlock(__gthread_recursive_mutex_t * __mutex)833d19d7d58SLionel Sambuc __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
834d19d7d58SLionel Sambuc {
835d19d7d58SLionel Sambuc return __gthread_mutex_unlock (__mutex);
836d19d7d58SLionel Sambuc }
837d19d7d58SLionel Sambuc
838d19d7d58SLionel Sambuc static inline int
__gthread_recursive_mutex_destroy(__gthread_recursive_mutex_t * __mutex)839*0a6a1f1dSLionel Sambuc __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex)
840*0a6a1f1dSLionel Sambuc {
841*0a6a1f1dSLionel Sambuc return __gthread_mutex_destroy (__mutex);
842*0a6a1f1dSLionel Sambuc }
843*0a6a1f1dSLionel Sambuc
844*0a6a1f1dSLionel Sambuc #ifdef _GTHREAD_USE_COND_INIT_FUNC
845*0a6a1f1dSLionel Sambuc static inline void
__gthread_cond_init_function(__gthread_cond_t * __cond)846*0a6a1f1dSLionel Sambuc __gthread_cond_init_function (__gthread_cond_t *__cond)
847*0a6a1f1dSLionel Sambuc {
848*0a6a1f1dSLionel Sambuc if (__gthread_active_p ())
849*0a6a1f1dSLionel Sambuc __gthrw_(pthread_cond_init) (__cond, NULL);
850*0a6a1f1dSLionel Sambuc }
851*0a6a1f1dSLionel Sambuc #endif
852*0a6a1f1dSLionel Sambuc
853*0a6a1f1dSLionel Sambuc static inline int
__gthread_cond_broadcast(__gthread_cond_t * __cond)854d19d7d58SLionel Sambuc __gthread_cond_broadcast (__gthread_cond_t *__cond)
855d19d7d58SLionel Sambuc {
856d19d7d58SLionel Sambuc return __gthrw_(pthread_cond_broadcast) (__cond);
857d19d7d58SLionel Sambuc }
858d19d7d58SLionel Sambuc
859d19d7d58SLionel Sambuc static inline int
__gthread_cond_signal(__gthread_cond_t * __cond)860d19d7d58SLionel Sambuc __gthread_cond_signal (__gthread_cond_t *__cond)
861d19d7d58SLionel Sambuc {
862d19d7d58SLionel Sambuc return __gthrw_(pthread_cond_signal) (__cond);
863d19d7d58SLionel Sambuc }
864d19d7d58SLionel Sambuc
865d19d7d58SLionel Sambuc static inline int
__gthread_cond_wait(__gthread_cond_t * __cond,__gthread_mutex_t * __mutex)866d19d7d58SLionel Sambuc __gthread_cond_wait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex)
867d19d7d58SLionel Sambuc {
868d19d7d58SLionel Sambuc return __gthrw_(pthread_cond_wait) (__cond, __mutex);
869d19d7d58SLionel Sambuc }
870d19d7d58SLionel Sambuc
871d19d7d58SLionel Sambuc static inline int
__gthread_cond_timedwait(__gthread_cond_t * __cond,__gthread_mutex_t * __mutex,const __gthread_time_t * __abs_timeout)872d19d7d58SLionel Sambuc __gthread_cond_timedwait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex,
873d19d7d58SLionel Sambuc const __gthread_time_t *__abs_timeout)
874d19d7d58SLionel Sambuc {
875d19d7d58SLionel Sambuc return __gthrw_(pthread_cond_timedwait) (__cond, __mutex, __abs_timeout);
876d19d7d58SLionel Sambuc }
877d19d7d58SLionel Sambuc
878d19d7d58SLionel Sambuc static inline int
__gthread_cond_wait_recursive(__gthread_cond_t * __cond,__gthread_recursive_mutex_t * __mutex)879d19d7d58SLionel Sambuc __gthread_cond_wait_recursive (__gthread_cond_t *__cond,
880d19d7d58SLionel Sambuc __gthread_recursive_mutex_t *__mutex)
881d19d7d58SLionel Sambuc {
882d19d7d58SLionel Sambuc return __gthread_cond_wait (__cond, __mutex);
883d19d7d58SLionel Sambuc }
884d19d7d58SLionel Sambuc
885d19d7d58SLionel Sambuc static inline int
__gthread_cond_destroy(__gthread_cond_t * __cond)886d19d7d58SLionel Sambuc __gthread_cond_destroy (__gthread_cond_t* __cond)
887d19d7d58SLionel Sambuc {
888d19d7d58SLionel Sambuc return __gthrw_(pthread_cond_destroy) (__cond);
889d19d7d58SLionel Sambuc }
890d19d7d58SLionel Sambuc
891d19d7d58SLionel Sambuc #endif /* _LIBOBJC */
892d19d7d58SLionel Sambuc
893d19d7d58SLionel Sambuc #endif /* ! _GLIBCXX_GCC_GTHR_POSIX_H */
894