xref: /minix3/external/gpl3/gcc/lib/libstdc++-v3/arch/earmv4eb/gthr-posix.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
184d9c625SLionel 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  */
484d9c625SLionel Sambuc 
584d9c625SLionel Sambuc /* Threads compatibility routines for libgcc2 and libobjc.  */
684d9c625SLionel Sambuc /* Compile this one with gcc.  */
7*0a6a1f1dSLionel Sambuc /* Copyright (C) 1997-2013 Free Software Foundation, Inc.
884d9c625SLionel Sambuc 
984d9c625SLionel Sambuc This file is part of GCC.
1084d9c625SLionel Sambuc 
1184d9c625SLionel Sambuc GCC is free software; you can redistribute it and/or modify it under
1284d9c625SLionel Sambuc the terms of the GNU General Public License as published by the Free
1384d9c625SLionel Sambuc Software Foundation; either version 3, or (at your option) any later
1484d9c625SLionel Sambuc version.
1584d9c625SLionel Sambuc 
1684d9c625SLionel Sambuc GCC is distributed in the hope that it will be useful, but WITHOUT ANY
1784d9c625SLionel Sambuc WARRANTY; without even the implied warranty of MERCHANTABILITY or
1884d9c625SLionel Sambuc FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1984d9c625SLionel Sambuc for more details.
2084d9c625SLionel Sambuc 
2184d9c625SLionel Sambuc Under Section 7 of GPL version 3, you are granted additional
2284d9c625SLionel Sambuc permissions described in the GCC Runtime Library Exception, version
2384d9c625SLionel Sambuc 3.1, as published by the Free Software Foundation.
2484d9c625SLionel Sambuc 
2584d9c625SLionel Sambuc You should have received a copy of the GNU General Public License and
2684d9c625SLionel Sambuc a copy of the GCC Runtime Library Exception along with this program;
2784d9c625SLionel Sambuc see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
2884d9c625SLionel Sambuc <http://www.gnu.org/licenses/>.  */
2984d9c625SLionel Sambuc 
3084d9c625SLionel Sambuc #ifndef _GLIBCXX_GCC_GTHR_POSIX_H
3184d9c625SLionel Sambuc #define _GLIBCXX_GCC_GTHR_POSIX_H
3284d9c625SLionel Sambuc 
3384d9c625SLionel Sambuc /* POSIX threads specific definitions.
3484d9c625SLionel Sambuc    Easy, since the interface is just one-to-one mapping.  */
3584d9c625SLionel Sambuc 
3684d9c625SLionel Sambuc #define __GTHREADS 1
3784d9c625SLionel Sambuc #define __GTHREADS_CXX0X 1
3884d9c625SLionel Sambuc 
3984d9c625SLionel Sambuc #include <pthread.h>
40*0a6a1f1dSLionel Sambuc 
41*0a6a1f1dSLionel Sambuc #if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \
42*0a6a1f1dSLionel Sambuc      || !defined(_GTHREAD_USE_MUTEX_TIMEDLOCK))
4384d9c625SLionel 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
5084d9c625SLionel Sambuc 
5184d9c625SLionel Sambuc typedef pthread_t __gthread_t;
5284d9c625SLionel Sambuc typedef pthread_key_t __gthread_key_t;
5384d9c625SLionel Sambuc typedef pthread_once_t __gthread_once_t;
5484d9c625SLionel Sambuc typedef pthread_mutex_t __gthread_mutex_t;
5584d9c625SLionel Sambuc typedef pthread_mutex_t __gthread_recursive_mutex_t;
5684d9c625SLionel Sambuc typedef pthread_cond_t __gthread_cond_t;
5784d9c625SLionel Sambuc typedef struct timespec __gthread_time_t;
5884d9c625SLionel Sambuc 
5984d9c625SLionel Sambuc /* POSIX like conditional variables are supported.  Please look at comments
6084d9c625SLionel Sambuc    in gthr.h for details. */
6184d9c625SLionel Sambuc #define __GTHREAD_HAS_COND	1
6284d9c625SLionel Sambuc 
6384d9c625SLionel Sambuc #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
64*0a6a1f1dSLionel Sambuc #define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
6584d9c625SLionel Sambuc #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
6684d9c625SLionel Sambuc #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
6784d9c625SLionel Sambuc #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
6884d9c625SLionel Sambuc #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
6984d9c625SLionel Sambuc #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
7084d9c625SLionel Sambuc #else
7184d9c625SLionel Sambuc #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
7284d9c625SLionel Sambuc #endif
7384d9c625SLionel Sambuc #define __GTHREAD_COND_INIT PTHREAD_COND_INITIALIZER
7484d9c625SLionel Sambuc #define __GTHREAD_TIME_INIT {0,0}
7584d9c625SLionel 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 
8984d9c625SLionel Sambuc #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
9084d9c625SLionel Sambuc # ifndef __gthrw_pragma
9184d9c625SLionel Sambuc #  define __gthrw_pragma(pragma)
9284d9c625SLionel Sambuc # endif
9384d9c625SLionel Sambuc # define __gthrw2(name,name2,type) \
9484d9c625SLionel Sambuc   static __typeof(type) name __attribute__ ((__weakref__(#name2))); \
9584d9c625SLionel Sambuc   __gthrw_pragma(weak type)
9684d9c625SLionel Sambuc # define __gthrw_(name) __gthrw_ ## name
9784d9c625SLionel Sambuc #else
9884d9c625SLionel Sambuc # define __gthrw2(name,name2,type)
9984d9c625SLionel Sambuc # define __gthrw_(name) name
10084d9c625SLionel Sambuc #endif
10184d9c625SLionel Sambuc 
10284d9c625SLionel Sambuc /* Typically, __gthrw_foo is a weak reference to symbol foo.  */
10384d9c625SLionel Sambuc #define __gthrw(name) __gthrw2(__gthrw_ ## name,name,name)
10484d9c625SLionel Sambuc 
10584d9c625SLionel Sambuc __gthrw(pthread_once)
10684d9c625SLionel Sambuc __gthrw(pthread_getspecific)
10784d9c625SLionel Sambuc __gthrw(pthread_setspecific)
10884d9c625SLionel Sambuc 
10984d9c625SLionel Sambuc __gthrw(pthread_create)
11084d9c625SLionel Sambuc __gthrw(pthread_join)
11184d9c625SLionel Sambuc __gthrw(pthread_equal)
11284d9c625SLionel Sambuc __gthrw(pthread_self)
11384d9c625SLionel Sambuc __gthrw(pthread_detach)
114*0a6a1f1dSLionel Sambuc #ifndef __BIONIC__
11584d9c625SLionel Sambuc __gthrw(pthread_cancel)
116*0a6a1f1dSLionel Sambuc #endif
11784d9c625SLionel Sambuc __gthrw(sched_yield)
11884d9c625SLionel Sambuc 
11984d9c625SLionel Sambuc __gthrw(pthread_mutex_lock)
12084d9c625SLionel Sambuc __gthrw(pthread_mutex_trylock)
121*0a6a1f1dSLionel Sambuc #if _GTHREAD_USE_MUTEX_TIMEDLOCK
12284d9c625SLionel Sambuc __gthrw(pthread_mutex_timedlock)
12384d9c625SLionel Sambuc #endif
12484d9c625SLionel Sambuc __gthrw(pthread_mutex_unlock)
12584d9c625SLionel Sambuc __gthrw(pthread_mutex_init)
12684d9c625SLionel Sambuc __gthrw(pthread_mutex_destroy)
12784d9c625SLionel Sambuc 
128*0a6a1f1dSLionel Sambuc __gthrw(pthread_cond_init)
12984d9c625SLionel Sambuc __gthrw(pthread_cond_broadcast)
13084d9c625SLionel Sambuc __gthrw(pthread_cond_signal)
13184d9c625SLionel Sambuc __gthrw(pthread_cond_wait)
13284d9c625SLionel Sambuc __gthrw(pthread_cond_timedwait)
13384d9c625SLionel Sambuc __gthrw(pthread_cond_destroy)
13484d9c625SLionel Sambuc 
13584d9c625SLionel Sambuc __gthrw(pthread_key_create)
13684d9c625SLionel Sambuc __gthrw(pthread_key_delete)
13784d9c625SLionel Sambuc __gthrw(pthread_mutexattr_init)
13884d9c625SLionel Sambuc __gthrw(pthread_mutexattr_settype)
13984d9c625SLionel Sambuc __gthrw(pthread_mutexattr_destroy)
14084d9c625SLionel Sambuc 
14184d9c625SLionel Sambuc 
14284d9c625SLionel Sambuc #if defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)
14384d9c625SLionel Sambuc /* Objective-C.  */
14484d9c625SLionel Sambuc __gthrw(pthread_exit)
14584d9c625SLionel Sambuc #ifdef _POSIX_PRIORITY_SCHEDULING
14684d9c625SLionel Sambuc #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
14784d9c625SLionel Sambuc __gthrw(sched_get_priority_max)
14884d9c625SLionel Sambuc __gthrw(sched_get_priority_min)
14984d9c625SLionel Sambuc #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
15084d9c625SLionel Sambuc #endif /* _POSIX_PRIORITY_SCHEDULING */
15184d9c625SLionel Sambuc __gthrw(pthread_attr_destroy)
15284d9c625SLionel Sambuc __gthrw(pthread_attr_init)
15384d9c625SLionel Sambuc __gthrw(pthread_attr_setdetachstate)
15484d9c625SLionel Sambuc #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
15584d9c625SLionel Sambuc __gthrw(pthread_getschedparam)
15684d9c625SLionel Sambuc __gthrw(pthread_setschedparam)
15784d9c625SLionel Sambuc #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
15884d9c625SLionel Sambuc #endif /* _LIBOBJC || _LIBOBJC_WEAK */
15984d9c625SLionel Sambuc 
16084d9c625SLionel Sambuc #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
16184d9c625SLionel Sambuc 
16284d9c625SLionel Sambuc /* On Solaris 2.6 up to 9, the libc exposes a POSIX threads interface even if
16384d9c625SLionel Sambuc    -pthreads is not specified.  The functions are dummies and most return an
16484d9c625SLionel Sambuc    error value.  However pthread_once returns 0 without invoking the routine
16584d9c625SLionel Sambuc    it is passed so we cannot pretend that the interface is active if -pthreads
16684d9c625SLionel Sambuc    is not specified.  On Solaris 2.5.1, the interface is not exposed at all so
16784d9c625SLionel Sambuc    we need to play the usual game with weak symbols.  On Solaris 10 and up, a
16884d9c625SLionel Sambuc    working interface is always exposed.  On FreeBSD 6 and later, libc also
16984d9c625SLionel Sambuc    exposes a dummy POSIX threads interface, similar to what Solaris 2.6 up
17084d9c625SLionel Sambuc    to 9 does.  FreeBSD >= 700014 even provides a pthread_cancel stub in libc,
17184d9c625SLionel Sambuc    which means the alternate __gthread_active_p below cannot be used there.  */
17284d9c625SLionel Sambuc 
17384d9c625SLionel Sambuc #if defined(__FreeBSD__) || (defined(__sun) && defined(__svr4__))
17484d9c625SLionel Sambuc 
17584d9c625SLionel Sambuc static volatile int __gthread_active = -1;
17684d9c625SLionel Sambuc 
17784d9c625SLionel Sambuc static void
__gthread_trigger(void)17884d9c625SLionel Sambuc __gthread_trigger (void)
17984d9c625SLionel Sambuc {
18084d9c625SLionel Sambuc   __gthread_active = 1;
18184d9c625SLionel Sambuc }
18284d9c625SLionel Sambuc 
18384d9c625SLionel Sambuc static inline int
__gthread_active_p(void)18484d9c625SLionel Sambuc __gthread_active_p (void)
18584d9c625SLionel Sambuc {
18684d9c625SLionel Sambuc   static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
18784d9c625SLionel Sambuc   static pthread_once_t __gthread_active_once = PTHREAD_ONCE_INIT;
18884d9c625SLionel Sambuc 
18984d9c625SLionel Sambuc   /* Avoid reading __gthread_active twice on the main code path.  */
19084d9c625SLionel Sambuc   int __gthread_active_latest_value = __gthread_active;
19184d9c625SLionel Sambuc 
19284d9c625SLionel Sambuc   /* This test is not protected to avoid taking a lock on the main code
19384d9c625SLionel Sambuc      path so every update of __gthread_active in a threaded program must
19484d9c625SLionel Sambuc      be atomic with regard to the result of the test.  */
19584d9c625SLionel Sambuc   if (__builtin_expect (__gthread_active_latest_value < 0, 0))
19684d9c625SLionel Sambuc     {
19784d9c625SLionel Sambuc       if (__gthrw_(pthread_once))
19884d9c625SLionel Sambuc 	{
19984d9c625SLionel Sambuc 	  /* If this really is a threaded program, then we must ensure that
20084d9c625SLionel Sambuc 	     __gthread_active has been set to 1 before exiting this block.  */
20184d9c625SLionel Sambuc 	  __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex);
20284d9c625SLionel Sambuc 	  __gthrw_(pthread_once) (&__gthread_active_once, __gthread_trigger);
20384d9c625SLionel Sambuc 	  __gthrw_(pthread_mutex_unlock) (&__gthread_active_mutex);
20484d9c625SLionel Sambuc 	}
20584d9c625SLionel Sambuc 
20684d9c625SLionel Sambuc       /* Make sure we'll never enter this block again.  */
20784d9c625SLionel Sambuc       if (__gthread_active < 0)
20884d9c625SLionel Sambuc 	__gthread_active = 0;
20984d9c625SLionel Sambuc 
21084d9c625SLionel Sambuc       __gthread_active_latest_value = __gthread_active;
21184d9c625SLionel Sambuc     }
21284d9c625SLionel Sambuc 
21384d9c625SLionel Sambuc   return __gthread_active_latest_value != 0;
21484d9c625SLionel Sambuc }
21584d9c625SLionel Sambuc 
21684d9c625SLionel Sambuc #else /* neither FreeBSD nor Solaris */
21784d9c625SLionel 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 
25084d9c625SLionel Sambuc static inline int
25184d9c625SLionel Sambuc __gthread_active_p (void)
25284d9c625SLionel Sambuc {
25384d9c625SLionel Sambuc   static void *const __gthread_active_ptr
254*0a6a1f1dSLionel Sambuc     = __extension__ (void *) &GTHR_ACTIVE_PROXY;
25584d9c625SLionel Sambuc   return __gthread_active_ptr != 0;
25684d9c625SLionel Sambuc }
25784d9c625SLionel Sambuc 
25884d9c625SLionel Sambuc #endif /* FreeBSD or Solaris */
25984d9c625SLionel Sambuc 
26084d9c625SLionel Sambuc #else /* not __GXX_WEAK__ */
26184d9c625SLionel Sambuc 
26284d9c625SLionel Sambuc /* Similar to Solaris, HP-UX 11 for PA-RISC provides stubs for pthread
26384d9c625SLionel Sambuc    calls in shared flavors of the HP-UX C library.  Most of the stubs
26484d9c625SLionel Sambuc    have no functionality.  The details are described in the "libc cumulative
26584d9c625SLionel Sambuc    patch" for each subversion of HP-UX 11.  There are two special interfaces
26684d9c625SLionel Sambuc    provided for checking whether an application is linked to a shared pthread
26784d9c625SLionel Sambuc    library or not.  However, these interfaces aren't available in early
26884d9c625SLionel Sambuc    libpthread libraries.  We also need a test that works for archive
26984d9c625SLionel Sambuc    libraries.  We can't use pthread_once as some libc versions call the
27084d9c625SLionel Sambuc    init function.  We also can't use pthread_create or pthread_attr_init
27184d9c625SLionel Sambuc    as these create a thread and thereby prevent changing the default stack
27284d9c625SLionel Sambuc    size.  The function pthread_default_stacksize_np is available in both
27384d9c625SLionel Sambuc    the archive and shared versions of libpthread.   It can be used to
27484d9c625SLionel Sambuc    determine the default pthread stack size.  There is a stub in some
27584d9c625SLionel Sambuc    shared libc versions which returns a zero size if pthreads are not
27684d9c625SLionel Sambuc    active.  We provide an equivalent stub to handle cases where libc
27784d9c625SLionel Sambuc    doesn't provide one.  */
27884d9c625SLionel Sambuc 
27984d9c625SLionel Sambuc #if defined(__hppa__) && defined(__hpux__)
28084d9c625SLionel Sambuc 
28184d9c625SLionel Sambuc static volatile int __gthread_active = -1;
28284d9c625SLionel Sambuc 
28384d9c625SLionel Sambuc static inline int
28484d9c625SLionel Sambuc __gthread_active_p (void)
28584d9c625SLionel Sambuc {
28684d9c625SLionel Sambuc   /* Avoid reading __gthread_active twice on the main code path.  */
28784d9c625SLionel Sambuc   int __gthread_active_latest_value = __gthread_active;
28884d9c625SLionel Sambuc   size_t __s;
28984d9c625SLionel Sambuc 
29084d9c625SLionel Sambuc   if (__builtin_expect (__gthread_active_latest_value < 0, 0))
29184d9c625SLionel Sambuc     {
29284d9c625SLionel Sambuc       pthread_default_stacksize_np (0, &__s);
29384d9c625SLionel Sambuc       __gthread_active = __s ? 1 : 0;
29484d9c625SLionel Sambuc       __gthread_active_latest_value = __gthread_active;
29584d9c625SLionel Sambuc     }
29684d9c625SLionel Sambuc 
29784d9c625SLionel Sambuc   return __gthread_active_latest_value != 0;
29884d9c625SLionel Sambuc }
29984d9c625SLionel Sambuc 
30084d9c625SLionel Sambuc #else /* not hppa-hpux */
30184d9c625SLionel Sambuc 
30284d9c625SLionel Sambuc static inline int
30384d9c625SLionel Sambuc __gthread_active_p (void)
30484d9c625SLionel Sambuc {
30584d9c625SLionel Sambuc   return 1;
30684d9c625SLionel Sambuc }
30784d9c625SLionel Sambuc 
30884d9c625SLionel Sambuc #endif /* hppa-hpux */
30984d9c625SLionel Sambuc 
31084d9c625SLionel Sambuc #endif /* __GXX_WEAK__ */
31184d9c625SLionel Sambuc 
31284d9c625SLionel Sambuc #ifdef _LIBOBJC
31384d9c625SLionel Sambuc 
31484d9c625SLionel Sambuc /* This is the config.h file in libobjc/ */
31584d9c625SLionel Sambuc #include <config.h>
31684d9c625SLionel Sambuc 
31784d9c625SLionel Sambuc #ifdef HAVE_SCHED_H
31884d9c625SLionel Sambuc # include <sched.h>
31984d9c625SLionel Sambuc #endif
32084d9c625SLionel Sambuc 
32184d9c625SLionel Sambuc /* Key structure for maintaining thread specific storage */
32284d9c625SLionel Sambuc static pthread_key_t _objc_thread_storage;
32384d9c625SLionel Sambuc static pthread_attr_t _objc_thread_attribs;
32484d9c625SLionel Sambuc 
32584d9c625SLionel Sambuc /* Thread local storage for a single thread */
32684d9c625SLionel Sambuc static void *thread_local_storage = NULL;
32784d9c625SLionel Sambuc 
32884d9c625SLionel Sambuc /* Backend initialization functions */
32984d9c625SLionel Sambuc 
33084d9c625SLionel Sambuc /* Initialize the threads subsystem.  */
33184d9c625SLionel Sambuc static inline int
__gthread_objc_init_thread_system(void)33284d9c625SLionel Sambuc __gthread_objc_init_thread_system (void)
33384d9c625SLionel Sambuc {
33484d9c625SLionel Sambuc   if (__gthread_active_p ())
33584d9c625SLionel Sambuc     {
33684d9c625SLionel Sambuc       /* Initialize the thread storage key.  */
33784d9c625SLionel Sambuc       if (__gthrw_(pthread_key_create) (&_objc_thread_storage, NULL) == 0)
33884d9c625SLionel Sambuc 	{
33984d9c625SLionel Sambuc 	  /* The normal default detach state for threads is
34084d9c625SLionel Sambuc 	   * PTHREAD_CREATE_JOINABLE which causes threads to not die
34184d9c625SLionel Sambuc 	   * when you think they should.  */
34284d9c625SLionel Sambuc 	  if (__gthrw_(pthread_attr_init) (&_objc_thread_attribs) == 0
34384d9c625SLionel Sambuc 	      && __gthrw_(pthread_attr_setdetachstate) (&_objc_thread_attribs,
34484d9c625SLionel Sambuc 					      PTHREAD_CREATE_DETACHED) == 0)
34584d9c625SLionel Sambuc 	    return 0;
34684d9c625SLionel Sambuc 	}
34784d9c625SLionel Sambuc     }
34884d9c625SLionel Sambuc 
34984d9c625SLionel Sambuc   return -1;
35084d9c625SLionel Sambuc }
35184d9c625SLionel Sambuc 
35284d9c625SLionel Sambuc /* Close the threads subsystem.  */
35384d9c625SLionel Sambuc static inline int
__gthread_objc_close_thread_system(void)35484d9c625SLionel Sambuc __gthread_objc_close_thread_system (void)
35584d9c625SLionel Sambuc {
35684d9c625SLionel Sambuc   if (__gthread_active_p ()
35784d9c625SLionel Sambuc       && __gthrw_(pthread_key_delete) (_objc_thread_storage) == 0
35884d9c625SLionel Sambuc       && __gthrw_(pthread_attr_destroy) (&_objc_thread_attribs) == 0)
35984d9c625SLionel Sambuc     return 0;
36084d9c625SLionel Sambuc 
36184d9c625SLionel Sambuc   return -1;
36284d9c625SLionel Sambuc }
36384d9c625SLionel Sambuc 
36484d9c625SLionel Sambuc /* Backend thread functions */
36584d9c625SLionel Sambuc 
36684d9c625SLionel Sambuc /* Create a new thread of execution.  */
36784d9c625SLionel Sambuc static inline objc_thread_t
__gthread_objc_thread_detach(void (* func)(void *),void * arg)36884d9c625SLionel Sambuc __gthread_objc_thread_detach (void (*func)(void *), void *arg)
36984d9c625SLionel Sambuc {
37084d9c625SLionel Sambuc   objc_thread_t thread_id;
37184d9c625SLionel Sambuc   pthread_t new_thread_handle;
37284d9c625SLionel Sambuc 
37384d9c625SLionel Sambuc   if (!__gthread_active_p ())
37484d9c625SLionel Sambuc     return NULL;
37584d9c625SLionel Sambuc 
376*0a6a1f1dSLionel Sambuc   if (!(__gthrw_(pthread_create) (&new_thread_handle, &_objc_thread_attribs,
377*0a6a1f1dSLionel Sambuc 				  (void *) func, arg)))
37884d9c625SLionel Sambuc     thread_id = (objc_thread_t) new_thread_handle;
37984d9c625SLionel Sambuc   else
38084d9c625SLionel Sambuc     thread_id = NULL;
38184d9c625SLionel Sambuc 
38284d9c625SLionel Sambuc   return thread_id;
38384d9c625SLionel Sambuc }
38484d9c625SLionel Sambuc 
38584d9c625SLionel Sambuc /* Set the current thread's priority.  */
38684d9c625SLionel Sambuc static inline int
__gthread_objc_thread_set_priority(int priority)38784d9c625SLionel Sambuc __gthread_objc_thread_set_priority (int priority)
38884d9c625SLionel Sambuc {
38984d9c625SLionel Sambuc   if (!__gthread_active_p ())
39084d9c625SLionel Sambuc     return -1;
39184d9c625SLionel Sambuc   else
39284d9c625SLionel Sambuc     {
39384d9c625SLionel Sambuc #ifdef _POSIX_PRIORITY_SCHEDULING
39484d9c625SLionel Sambuc #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
39584d9c625SLionel Sambuc       pthread_t thread_id = __gthrw_(pthread_self) ();
39684d9c625SLionel Sambuc       int policy;
39784d9c625SLionel Sambuc       struct sched_param params;
39884d9c625SLionel Sambuc       int priority_min, priority_max;
39984d9c625SLionel Sambuc 
40084d9c625SLionel Sambuc       if (__gthrw_(pthread_getschedparam) (thread_id, &policy, &params) == 0)
40184d9c625SLionel Sambuc 	{
40284d9c625SLionel Sambuc 	  if ((priority_max = __gthrw_(sched_get_priority_max) (policy)) == -1)
40384d9c625SLionel Sambuc 	    return -1;
40484d9c625SLionel Sambuc 
40584d9c625SLionel Sambuc 	  if ((priority_min = __gthrw_(sched_get_priority_min) (policy)) == -1)
40684d9c625SLionel Sambuc 	    return -1;
40784d9c625SLionel Sambuc 
40884d9c625SLionel Sambuc 	  if (priority > priority_max)
40984d9c625SLionel Sambuc 	    priority = priority_max;
41084d9c625SLionel Sambuc 	  else if (priority < priority_min)
41184d9c625SLionel Sambuc 	    priority = priority_min;
41284d9c625SLionel Sambuc 	  params.sched_priority = priority;
41384d9c625SLionel Sambuc 
41484d9c625SLionel Sambuc 	  /*
41584d9c625SLionel Sambuc 	   * The solaris 7 and several other man pages incorrectly state that
41684d9c625SLionel Sambuc 	   * this should be a pointer to policy but pthread.h is universally
41784d9c625SLionel Sambuc 	   * at odds with this.
41884d9c625SLionel Sambuc 	   */
41984d9c625SLionel Sambuc 	  if (__gthrw_(pthread_setschedparam) (thread_id, policy, &params) == 0)
42084d9c625SLionel Sambuc 	    return 0;
42184d9c625SLionel Sambuc 	}
42284d9c625SLionel Sambuc #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
42384d9c625SLionel Sambuc #endif /* _POSIX_PRIORITY_SCHEDULING */
42484d9c625SLionel Sambuc       return -1;
42584d9c625SLionel Sambuc     }
42684d9c625SLionel Sambuc }
42784d9c625SLionel Sambuc 
42884d9c625SLionel Sambuc /* Return the current thread's priority.  */
42984d9c625SLionel Sambuc static inline int
__gthread_objc_thread_get_priority(void)43084d9c625SLionel Sambuc __gthread_objc_thread_get_priority (void)
43184d9c625SLionel Sambuc {
43284d9c625SLionel Sambuc #ifdef _POSIX_PRIORITY_SCHEDULING
43384d9c625SLionel Sambuc #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
43484d9c625SLionel Sambuc   if (__gthread_active_p ())
43584d9c625SLionel Sambuc     {
43684d9c625SLionel Sambuc       int policy;
43784d9c625SLionel Sambuc       struct sched_param params;
43884d9c625SLionel Sambuc 
43984d9c625SLionel Sambuc       if (__gthrw_(pthread_getschedparam) (__gthrw_(pthread_self) (), &policy, &params) == 0)
44084d9c625SLionel Sambuc 	return params.sched_priority;
44184d9c625SLionel Sambuc       else
44284d9c625SLionel Sambuc 	return -1;
44384d9c625SLionel Sambuc     }
44484d9c625SLionel Sambuc   else
44584d9c625SLionel Sambuc #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
44684d9c625SLionel Sambuc #endif /* _POSIX_PRIORITY_SCHEDULING */
44784d9c625SLionel Sambuc     return OBJC_THREAD_INTERACTIVE_PRIORITY;
44884d9c625SLionel Sambuc }
44984d9c625SLionel Sambuc 
45084d9c625SLionel Sambuc /* Yield our process time to another thread.  */
45184d9c625SLionel Sambuc static inline void
__gthread_objc_thread_yield(void)45284d9c625SLionel Sambuc __gthread_objc_thread_yield (void)
45384d9c625SLionel Sambuc {
45484d9c625SLionel Sambuc   if (__gthread_active_p ())
45584d9c625SLionel Sambuc     __gthrw_(sched_yield) ();
45684d9c625SLionel Sambuc }
45784d9c625SLionel Sambuc 
45884d9c625SLionel Sambuc /* Terminate the current thread.  */
45984d9c625SLionel Sambuc static inline int
__gthread_objc_thread_exit(void)46084d9c625SLionel Sambuc __gthread_objc_thread_exit (void)
46184d9c625SLionel Sambuc {
46284d9c625SLionel Sambuc   if (__gthread_active_p ())
46384d9c625SLionel Sambuc     /* exit the thread */
46484d9c625SLionel Sambuc     __gthrw_(pthread_exit) (&__objc_thread_exit_status);
46584d9c625SLionel Sambuc 
46684d9c625SLionel Sambuc   /* Failed if we reached here */
46784d9c625SLionel Sambuc   return -1;
46884d9c625SLionel Sambuc }
46984d9c625SLionel Sambuc 
47084d9c625SLionel Sambuc /* Returns an integer value which uniquely describes a thread.  */
47184d9c625SLionel Sambuc static inline objc_thread_t
__gthread_objc_thread_id(void)47284d9c625SLionel Sambuc __gthread_objc_thread_id (void)
47384d9c625SLionel Sambuc {
47484d9c625SLionel Sambuc   if (__gthread_active_p ())
47584d9c625SLionel Sambuc     return (objc_thread_t) __gthrw_(pthread_self) ();
47684d9c625SLionel Sambuc   else
47784d9c625SLionel Sambuc     return (objc_thread_t) 1;
47884d9c625SLionel Sambuc }
47984d9c625SLionel Sambuc 
48084d9c625SLionel Sambuc /* Sets the thread's local storage pointer.  */
48184d9c625SLionel Sambuc static inline int
__gthread_objc_thread_set_data(void * value)48284d9c625SLionel Sambuc __gthread_objc_thread_set_data (void *value)
48384d9c625SLionel Sambuc {
48484d9c625SLionel Sambuc   if (__gthread_active_p ())
48584d9c625SLionel Sambuc     return __gthrw_(pthread_setspecific) (_objc_thread_storage, value);
48684d9c625SLionel Sambuc   else
48784d9c625SLionel Sambuc     {
48884d9c625SLionel Sambuc       thread_local_storage = value;
48984d9c625SLionel Sambuc       return 0;
49084d9c625SLionel Sambuc     }
49184d9c625SLionel Sambuc }
49284d9c625SLionel Sambuc 
49384d9c625SLionel Sambuc /* Returns the thread's local storage pointer.  */
49484d9c625SLionel Sambuc static inline void *
__gthread_objc_thread_get_data(void)49584d9c625SLionel Sambuc __gthread_objc_thread_get_data (void)
49684d9c625SLionel Sambuc {
49784d9c625SLionel Sambuc   if (__gthread_active_p ())
49884d9c625SLionel Sambuc     return __gthrw_(pthread_getspecific) (_objc_thread_storage);
49984d9c625SLionel Sambuc   else
50084d9c625SLionel Sambuc     return thread_local_storage;
50184d9c625SLionel Sambuc }
50284d9c625SLionel Sambuc 
50384d9c625SLionel Sambuc /* Backend mutex functions */
50484d9c625SLionel Sambuc 
50584d9c625SLionel Sambuc /* Allocate a mutex.  */
50684d9c625SLionel Sambuc static inline int
__gthread_objc_mutex_allocate(objc_mutex_t mutex)50784d9c625SLionel Sambuc __gthread_objc_mutex_allocate (objc_mutex_t mutex)
50884d9c625SLionel Sambuc {
50984d9c625SLionel Sambuc   if (__gthread_active_p ())
51084d9c625SLionel Sambuc     {
51184d9c625SLionel Sambuc       mutex->backend = objc_malloc (sizeof (pthread_mutex_t));
51284d9c625SLionel Sambuc 
51384d9c625SLionel Sambuc       if (__gthrw_(pthread_mutex_init) ((pthread_mutex_t *) mutex->backend, NULL))
51484d9c625SLionel Sambuc 	{
51584d9c625SLionel Sambuc 	  objc_free (mutex->backend);
51684d9c625SLionel Sambuc 	  mutex->backend = NULL;
51784d9c625SLionel Sambuc 	  return -1;
51884d9c625SLionel Sambuc 	}
51984d9c625SLionel Sambuc     }
52084d9c625SLionel Sambuc 
52184d9c625SLionel Sambuc   return 0;
52284d9c625SLionel Sambuc }
52384d9c625SLionel Sambuc 
52484d9c625SLionel Sambuc /* Deallocate a mutex.  */
52584d9c625SLionel Sambuc static inline int
__gthread_objc_mutex_deallocate(objc_mutex_t mutex)52684d9c625SLionel Sambuc __gthread_objc_mutex_deallocate (objc_mutex_t mutex)
52784d9c625SLionel Sambuc {
52884d9c625SLionel Sambuc   if (__gthread_active_p ())
52984d9c625SLionel Sambuc     {
53084d9c625SLionel Sambuc       int count;
53184d9c625SLionel Sambuc 
53284d9c625SLionel Sambuc       /*
53384d9c625SLionel Sambuc        * Posix Threads specifically require that the thread be unlocked
53484d9c625SLionel Sambuc        * for __gthrw_(pthread_mutex_destroy) to work.
53584d9c625SLionel Sambuc        */
53684d9c625SLionel Sambuc 
53784d9c625SLionel Sambuc       do
53884d9c625SLionel Sambuc 	{
53984d9c625SLionel Sambuc 	  count = __gthrw_(pthread_mutex_unlock) ((pthread_mutex_t *) mutex->backend);
54084d9c625SLionel Sambuc 	  if (count < 0)
54184d9c625SLionel Sambuc 	    return -1;
54284d9c625SLionel Sambuc 	}
54384d9c625SLionel Sambuc       while (count);
54484d9c625SLionel Sambuc 
54584d9c625SLionel Sambuc       if (__gthrw_(pthread_mutex_destroy) ((pthread_mutex_t *) mutex->backend))
54684d9c625SLionel Sambuc 	return -1;
54784d9c625SLionel Sambuc 
54884d9c625SLionel Sambuc       objc_free (mutex->backend);
54984d9c625SLionel Sambuc       mutex->backend = NULL;
55084d9c625SLionel Sambuc     }
55184d9c625SLionel Sambuc   return 0;
55284d9c625SLionel Sambuc }
55384d9c625SLionel Sambuc 
55484d9c625SLionel Sambuc /* Grab a lock on a mutex.  */
55584d9c625SLionel Sambuc static inline int
__gthread_objc_mutex_lock(objc_mutex_t mutex)55684d9c625SLionel Sambuc __gthread_objc_mutex_lock (objc_mutex_t mutex)
55784d9c625SLionel Sambuc {
55884d9c625SLionel Sambuc   if (__gthread_active_p ()
55984d9c625SLionel Sambuc       && __gthrw_(pthread_mutex_lock) ((pthread_mutex_t *) mutex->backend) != 0)
56084d9c625SLionel Sambuc     {
56184d9c625SLionel Sambuc       return -1;
56284d9c625SLionel Sambuc     }
56384d9c625SLionel Sambuc 
56484d9c625SLionel Sambuc   return 0;
56584d9c625SLionel Sambuc }
56684d9c625SLionel Sambuc 
56784d9c625SLionel Sambuc /* Try to grab a lock on a mutex.  */
56884d9c625SLionel Sambuc static inline int
__gthread_objc_mutex_trylock(objc_mutex_t mutex)56984d9c625SLionel Sambuc __gthread_objc_mutex_trylock (objc_mutex_t mutex)
57084d9c625SLionel Sambuc {
57184d9c625SLionel Sambuc   if (__gthread_active_p ()
57284d9c625SLionel Sambuc       && __gthrw_(pthread_mutex_trylock) ((pthread_mutex_t *) mutex->backend) != 0)
57384d9c625SLionel Sambuc     {
57484d9c625SLionel Sambuc       return -1;
57584d9c625SLionel Sambuc     }
57684d9c625SLionel Sambuc 
57784d9c625SLionel Sambuc   return 0;
57884d9c625SLionel Sambuc }
57984d9c625SLionel Sambuc 
58084d9c625SLionel Sambuc /* Unlock the mutex */
58184d9c625SLionel Sambuc static inline int
__gthread_objc_mutex_unlock(objc_mutex_t mutex)58284d9c625SLionel Sambuc __gthread_objc_mutex_unlock (objc_mutex_t mutex)
58384d9c625SLionel Sambuc {
58484d9c625SLionel Sambuc   if (__gthread_active_p ()
58584d9c625SLionel Sambuc       && __gthrw_(pthread_mutex_unlock) ((pthread_mutex_t *) mutex->backend) != 0)
58684d9c625SLionel Sambuc     {
58784d9c625SLionel Sambuc       return -1;
58884d9c625SLionel Sambuc     }
58984d9c625SLionel Sambuc 
59084d9c625SLionel Sambuc   return 0;
59184d9c625SLionel Sambuc }
59284d9c625SLionel Sambuc 
59384d9c625SLionel Sambuc /* Backend condition mutex functions */
59484d9c625SLionel Sambuc 
59584d9c625SLionel Sambuc /* Allocate a condition.  */
59684d9c625SLionel Sambuc static inline int
__gthread_objc_condition_allocate(objc_condition_t condition)59784d9c625SLionel Sambuc __gthread_objc_condition_allocate (objc_condition_t condition)
59884d9c625SLionel Sambuc {
59984d9c625SLionel Sambuc   if (__gthread_active_p ())
60084d9c625SLionel Sambuc     {
60184d9c625SLionel Sambuc       condition->backend = objc_malloc (sizeof (pthread_cond_t));
60284d9c625SLionel Sambuc 
60384d9c625SLionel Sambuc       if (__gthrw_(pthread_cond_init) ((pthread_cond_t *) condition->backend, NULL))
60484d9c625SLionel Sambuc 	{
60584d9c625SLionel Sambuc 	  objc_free (condition->backend);
60684d9c625SLionel Sambuc 	  condition->backend = NULL;
60784d9c625SLionel Sambuc 	  return -1;
60884d9c625SLionel Sambuc 	}
60984d9c625SLionel Sambuc     }
61084d9c625SLionel Sambuc 
61184d9c625SLionel Sambuc   return 0;
61284d9c625SLionel Sambuc }
61384d9c625SLionel Sambuc 
61484d9c625SLionel Sambuc /* Deallocate a condition.  */
61584d9c625SLionel Sambuc static inline int
__gthread_objc_condition_deallocate(objc_condition_t condition)61684d9c625SLionel Sambuc __gthread_objc_condition_deallocate (objc_condition_t condition)
61784d9c625SLionel Sambuc {
61884d9c625SLionel Sambuc   if (__gthread_active_p ())
61984d9c625SLionel Sambuc     {
62084d9c625SLionel Sambuc       if (__gthrw_(pthread_cond_destroy) ((pthread_cond_t *) condition->backend))
62184d9c625SLionel Sambuc 	return -1;
62284d9c625SLionel Sambuc 
62384d9c625SLionel Sambuc       objc_free (condition->backend);
62484d9c625SLionel Sambuc       condition->backend = NULL;
62584d9c625SLionel Sambuc     }
62684d9c625SLionel Sambuc   return 0;
62784d9c625SLionel Sambuc }
62884d9c625SLionel Sambuc 
62984d9c625SLionel Sambuc /* Wait on the condition */
63084d9c625SLionel Sambuc static inline int
__gthread_objc_condition_wait(objc_condition_t condition,objc_mutex_t mutex)63184d9c625SLionel Sambuc __gthread_objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex)
63284d9c625SLionel Sambuc {
63384d9c625SLionel Sambuc   if (__gthread_active_p ())
63484d9c625SLionel Sambuc     return __gthrw_(pthread_cond_wait) ((pthread_cond_t *) condition->backend,
63584d9c625SLionel Sambuc 			      (pthread_mutex_t *) mutex->backend);
63684d9c625SLionel Sambuc   else
63784d9c625SLionel Sambuc     return 0;
63884d9c625SLionel Sambuc }
63984d9c625SLionel Sambuc 
64084d9c625SLionel Sambuc /* Wake up all threads waiting on this condition.  */
64184d9c625SLionel Sambuc static inline int
__gthread_objc_condition_broadcast(objc_condition_t condition)64284d9c625SLionel Sambuc __gthread_objc_condition_broadcast (objc_condition_t condition)
64384d9c625SLionel Sambuc {
64484d9c625SLionel Sambuc   if (__gthread_active_p ())
64584d9c625SLionel Sambuc     return __gthrw_(pthread_cond_broadcast) ((pthread_cond_t *) condition->backend);
64684d9c625SLionel Sambuc   else
64784d9c625SLionel Sambuc     return 0;
64884d9c625SLionel Sambuc }
64984d9c625SLionel Sambuc 
65084d9c625SLionel Sambuc /* Wake up one thread waiting on this condition.  */
65184d9c625SLionel Sambuc static inline int
__gthread_objc_condition_signal(objc_condition_t condition)65284d9c625SLionel Sambuc __gthread_objc_condition_signal (objc_condition_t condition)
65384d9c625SLionel Sambuc {
65484d9c625SLionel Sambuc   if (__gthread_active_p ())
65584d9c625SLionel Sambuc     return __gthrw_(pthread_cond_signal) ((pthread_cond_t *) condition->backend);
65684d9c625SLionel Sambuc   else
65784d9c625SLionel Sambuc     return 0;
65884d9c625SLionel Sambuc }
65984d9c625SLionel Sambuc 
66084d9c625SLionel Sambuc #else /* _LIBOBJC */
66184d9c625SLionel Sambuc 
66284d9c625SLionel Sambuc static inline int
__gthread_create(__gthread_t * __threadid,void * (* __func)(void *),void * __args)66384d9c625SLionel Sambuc __gthread_create (__gthread_t *__threadid, void *(*__func) (void*),
66484d9c625SLionel Sambuc 		  void *__args)
66584d9c625SLionel Sambuc {
66684d9c625SLionel Sambuc   return __gthrw_(pthread_create) (__threadid, NULL, __func, __args);
66784d9c625SLionel Sambuc }
66884d9c625SLionel Sambuc 
66984d9c625SLionel Sambuc static inline int
__gthread_join(__gthread_t __threadid,void ** __value_ptr)67084d9c625SLionel Sambuc __gthread_join (__gthread_t __threadid, void **__value_ptr)
67184d9c625SLionel Sambuc {
67284d9c625SLionel Sambuc   return __gthrw_(pthread_join) (__threadid, __value_ptr);
67384d9c625SLionel Sambuc }
67484d9c625SLionel Sambuc 
67584d9c625SLionel Sambuc static inline int
__gthread_detach(__gthread_t __threadid)67684d9c625SLionel Sambuc __gthread_detach (__gthread_t __threadid)
67784d9c625SLionel Sambuc {
67884d9c625SLionel Sambuc   return __gthrw_(pthread_detach) (__threadid);
67984d9c625SLionel Sambuc }
68084d9c625SLionel Sambuc 
68184d9c625SLionel Sambuc static inline int
__gthread_equal(__gthread_t __t1,__gthread_t __t2)68284d9c625SLionel Sambuc __gthread_equal (__gthread_t __t1, __gthread_t __t2)
68384d9c625SLionel Sambuc {
68484d9c625SLionel Sambuc   return __gthrw_(pthread_equal) (__t1, __t2);
68584d9c625SLionel Sambuc }
68684d9c625SLionel Sambuc 
68784d9c625SLionel Sambuc static inline __gthread_t
__gthread_self(void)68884d9c625SLionel Sambuc __gthread_self (void)
68984d9c625SLionel Sambuc {
69084d9c625SLionel Sambuc   return __gthrw_(pthread_self) ();
69184d9c625SLionel Sambuc }
69284d9c625SLionel Sambuc 
69384d9c625SLionel Sambuc static inline int
__gthread_yield(void)69484d9c625SLionel Sambuc __gthread_yield (void)
69584d9c625SLionel Sambuc {
69684d9c625SLionel Sambuc   return __gthrw_(sched_yield) ();
69784d9c625SLionel Sambuc }
69884d9c625SLionel Sambuc 
69984d9c625SLionel Sambuc static inline int
__gthread_once(__gthread_once_t * __once,void (* __func)(void))70084d9c625SLionel Sambuc __gthread_once (__gthread_once_t *__once, void (*__func) (void))
70184d9c625SLionel Sambuc {
70284d9c625SLionel Sambuc   if (__gthread_active_p ())
70384d9c625SLionel Sambuc     return __gthrw_(pthread_once) (__once, __func);
70484d9c625SLionel Sambuc   else
70584d9c625SLionel Sambuc     return -1;
70684d9c625SLionel Sambuc }
70784d9c625SLionel Sambuc 
70884d9c625SLionel Sambuc static inline int
__gthread_key_create(__gthread_key_t * __key,void (* __dtor)(void *))70984d9c625SLionel Sambuc __gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
71084d9c625SLionel Sambuc {
71184d9c625SLionel Sambuc   return __gthrw_(pthread_key_create) (__key, __dtor);
71284d9c625SLionel Sambuc }
71384d9c625SLionel Sambuc 
71484d9c625SLionel Sambuc static inline int
__gthread_key_delete(__gthread_key_t __key)71584d9c625SLionel Sambuc __gthread_key_delete (__gthread_key_t __key)
71684d9c625SLionel Sambuc {
71784d9c625SLionel Sambuc   return __gthrw_(pthread_key_delete) (__key);
71884d9c625SLionel Sambuc }
71984d9c625SLionel Sambuc 
72084d9c625SLionel Sambuc static inline void *
__gthread_getspecific(__gthread_key_t __key)72184d9c625SLionel Sambuc __gthread_getspecific (__gthread_key_t __key)
72284d9c625SLionel Sambuc {
72384d9c625SLionel Sambuc   return __gthrw_(pthread_getspecific) (__key);
72484d9c625SLionel Sambuc }
72584d9c625SLionel Sambuc 
72684d9c625SLionel Sambuc static inline int
__gthread_setspecific(__gthread_key_t __key,const void * __ptr)72784d9c625SLionel Sambuc __gthread_setspecific (__gthread_key_t __key, const void *__ptr)
72884d9c625SLionel Sambuc {
72984d9c625SLionel Sambuc   return __gthrw_(pthread_setspecific) (__key, __ptr);
73084d9c625SLionel Sambuc }
73184d9c625SLionel 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 
73984d9c625SLionel Sambuc static inline int
__gthread_mutex_destroy(__gthread_mutex_t * __mutex)74084d9c625SLionel Sambuc __gthread_mutex_destroy (__gthread_mutex_t *__mutex)
74184d9c625SLionel Sambuc {
74284d9c625SLionel Sambuc   if (__gthread_active_p ())
74384d9c625SLionel Sambuc     return __gthrw_(pthread_mutex_destroy) (__mutex);
74484d9c625SLionel Sambuc   else
74584d9c625SLionel Sambuc     return 0;
74684d9c625SLionel Sambuc }
74784d9c625SLionel Sambuc 
74884d9c625SLionel Sambuc static inline int
__gthread_mutex_lock(__gthread_mutex_t * __mutex)74984d9c625SLionel Sambuc __gthread_mutex_lock (__gthread_mutex_t *__mutex)
75084d9c625SLionel Sambuc {
75184d9c625SLionel Sambuc   if (__gthread_active_p ())
75284d9c625SLionel Sambuc     return __gthrw_(pthread_mutex_lock) (__mutex);
75384d9c625SLionel Sambuc   else
75484d9c625SLionel Sambuc     return 0;
75584d9c625SLionel Sambuc }
75684d9c625SLionel Sambuc 
75784d9c625SLionel Sambuc static inline int
__gthread_mutex_trylock(__gthread_mutex_t * __mutex)75884d9c625SLionel Sambuc __gthread_mutex_trylock (__gthread_mutex_t *__mutex)
75984d9c625SLionel Sambuc {
76084d9c625SLionel Sambuc   if (__gthread_active_p ())
76184d9c625SLionel Sambuc     return __gthrw_(pthread_mutex_trylock) (__mutex);
76284d9c625SLionel Sambuc   else
76384d9c625SLionel Sambuc     return 0;
76484d9c625SLionel Sambuc }
76584d9c625SLionel Sambuc 
766*0a6a1f1dSLionel Sambuc #if _GTHREAD_USE_MUTEX_TIMEDLOCK
76784d9c625SLionel Sambuc static inline int
__gthread_mutex_timedlock(__gthread_mutex_t * __mutex,const __gthread_time_t * __abs_timeout)76884d9c625SLionel Sambuc __gthread_mutex_timedlock (__gthread_mutex_t *__mutex,
76984d9c625SLionel Sambuc 			   const __gthread_time_t *__abs_timeout)
77084d9c625SLionel Sambuc {
77184d9c625SLionel Sambuc   if (__gthread_active_p ())
77284d9c625SLionel Sambuc     return __gthrw_(pthread_mutex_timedlock) (__mutex, __abs_timeout);
77384d9c625SLionel Sambuc   else
77484d9c625SLionel Sambuc     return 0;
77584d9c625SLionel Sambuc }
77684d9c625SLionel Sambuc #endif
77784d9c625SLionel Sambuc 
77884d9c625SLionel Sambuc static inline int
__gthread_mutex_unlock(__gthread_mutex_t * __mutex)77984d9c625SLionel Sambuc __gthread_mutex_unlock (__gthread_mutex_t *__mutex)
78084d9c625SLionel Sambuc {
78184d9c625SLionel Sambuc   if (__gthread_active_p ())
78284d9c625SLionel Sambuc     return __gthrw_(pthread_mutex_unlock) (__mutex);
78384d9c625SLionel Sambuc   else
78484d9c625SLionel Sambuc     return 0;
78584d9c625SLionel Sambuc }
78684d9c625SLionel Sambuc 
787*0a6a1f1dSLionel Sambuc #if !defined( PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) \
788*0a6a1f1dSLionel Sambuc   || defined(_GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC)
78984d9c625SLionel Sambuc static inline int
__gthread_recursive_mutex_init_function(__gthread_recursive_mutex_t * __mutex)79084d9c625SLionel Sambuc __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
79184d9c625SLionel Sambuc {
79284d9c625SLionel Sambuc   if (__gthread_active_p ())
79384d9c625SLionel Sambuc     {
79484d9c625SLionel Sambuc       pthread_mutexattr_t __attr;
79584d9c625SLionel Sambuc       int __r;
79684d9c625SLionel Sambuc 
79784d9c625SLionel Sambuc       __r = __gthrw_(pthread_mutexattr_init) (&__attr);
79884d9c625SLionel Sambuc       if (!__r)
79984d9c625SLionel Sambuc 	__r = __gthrw_(pthread_mutexattr_settype) (&__attr,
80084d9c625SLionel Sambuc 						   PTHREAD_MUTEX_RECURSIVE);
80184d9c625SLionel Sambuc       if (!__r)
80284d9c625SLionel Sambuc 	__r = __gthrw_(pthread_mutex_init) (__mutex, &__attr);
80384d9c625SLionel Sambuc       if (!__r)
80484d9c625SLionel Sambuc 	__r = __gthrw_(pthread_mutexattr_destroy) (&__attr);
80584d9c625SLionel Sambuc       return __r;
80684d9c625SLionel Sambuc     }
80784d9c625SLionel Sambuc   return 0;
80884d9c625SLionel Sambuc }
80984d9c625SLionel Sambuc #endif
81084d9c625SLionel Sambuc 
81184d9c625SLionel Sambuc static inline int
__gthread_recursive_mutex_lock(__gthread_recursive_mutex_t * __mutex)81284d9c625SLionel Sambuc __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
81384d9c625SLionel Sambuc {
81484d9c625SLionel Sambuc   return __gthread_mutex_lock (__mutex);
81584d9c625SLionel Sambuc }
81684d9c625SLionel Sambuc 
81784d9c625SLionel Sambuc static inline int
__gthread_recursive_mutex_trylock(__gthread_recursive_mutex_t * __mutex)81884d9c625SLionel Sambuc __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
81984d9c625SLionel Sambuc {
82084d9c625SLionel Sambuc   return __gthread_mutex_trylock (__mutex);
82184d9c625SLionel Sambuc }
82284d9c625SLionel Sambuc 
823*0a6a1f1dSLionel Sambuc #if _GTHREAD_USE_MUTEX_TIMEDLOCK
82484d9c625SLionel Sambuc static inline int
__gthread_recursive_mutex_timedlock(__gthread_recursive_mutex_t * __mutex,const __gthread_time_t * __abs_timeout)82584d9c625SLionel Sambuc __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *__mutex,
82684d9c625SLionel Sambuc 				     const __gthread_time_t *__abs_timeout)
82784d9c625SLionel Sambuc {
82884d9c625SLionel Sambuc   return __gthread_mutex_timedlock (__mutex, __abs_timeout);
82984d9c625SLionel Sambuc }
83084d9c625SLionel Sambuc #endif
83184d9c625SLionel Sambuc 
83284d9c625SLionel Sambuc static inline int
__gthread_recursive_mutex_unlock(__gthread_recursive_mutex_t * __mutex)83384d9c625SLionel Sambuc __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
83484d9c625SLionel Sambuc {
83584d9c625SLionel Sambuc   return __gthread_mutex_unlock (__mutex);
83684d9c625SLionel Sambuc }
83784d9c625SLionel Sambuc 
83884d9c625SLionel 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)85484d9c625SLionel Sambuc __gthread_cond_broadcast (__gthread_cond_t *__cond)
85584d9c625SLionel Sambuc {
85684d9c625SLionel Sambuc   return __gthrw_(pthread_cond_broadcast) (__cond);
85784d9c625SLionel Sambuc }
85884d9c625SLionel Sambuc 
85984d9c625SLionel Sambuc static inline int
__gthread_cond_signal(__gthread_cond_t * __cond)86084d9c625SLionel Sambuc __gthread_cond_signal (__gthread_cond_t *__cond)
86184d9c625SLionel Sambuc {
86284d9c625SLionel Sambuc   return __gthrw_(pthread_cond_signal) (__cond);
86384d9c625SLionel Sambuc }
86484d9c625SLionel Sambuc 
86584d9c625SLionel Sambuc static inline int
__gthread_cond_wait(__gthread_cond_t * __cond,__gthread_mutex_t * __mutex)86684d9c625SLionel Sambuc __gthread_cond_wait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex)
86784d9c625SLionel Sambuc {
86884d9c625SLionel Sambuc   return __gthrw_(pthread_cond_wait) (__cond, __mutex);
86984d9c625SLionel Sambuc }
87084d9c625SLionel Sambuc 
87184d9c625SLionel Sambuc static inline int
__gthread_cond_timedwait(__gthread_cond_t * __cond,__gthread_mutex_t * __mutex,const __gthread_time_t * __abs_timeout)87284d9c625SLionel Sambuc __gthread_cond_timedwait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex,
87384d9c625SLionel Sambuc 			  const __gthread_time_t *__abs_timeout)
87484d9c625SLionel Sambuc {
87584d9c625SLionel Sambuc   return __gthrw_(pthread_cond_timedwait) (__cond, __mutex, __abs_timeout);
87684d9c625SLionel Sambuc }
87784d9c625SLionel Sambuc 
87884d9c625SLionel Sambuc static inline int
__gthread_cond_wait_recursive(__gthread_cond_t * __cond,__gthread_recursive_mutex_t * __mutex)87984d9c625SLionel Sambuc __gthread_cond_wait_recursive (__gthread_cond_t *__cond,
88084d9c625SLionel Sambuc 			       __gthread_recursive_mutex_t *__mutex)
88184d9c625SLionel Sambuc {
88284d9c625SLionel Sambuc   return __gthread_cond_wait (__cond, __mutex);
88384d9c625SLionel Sambuc }
88484d9c625SLionel Sambuc 
88584d9c625SLionel Sambuc static inline int
__gthread_cond_destroy(__gthread_cond_t * __cond)88684d9c625SLionel Sambuc __gthread_cond_destroy (__gthread_cond_t* __cond)
88784d9c625SLionel Sambuc {
88884d9c625SLionel Sambuc   return __gthrw_(pthread_cond_destroy) (__cond);
88984d9c625SLionel Sambuc }
89084d9c625SLionel Sambuc 
89184d9c625SLionel Sambuc #endif /* _LIBOBJC */
89284d9c625SLionel Sambuc 
89384d9c625SLionel Sambuc #endif /* ! _GLIBCXX_GCC_GTHR_POSIX_H */
894