1 /* Threads compatibility routines for libgcc2 and libobjc. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. */
27 #ifndef GCC_GTHR_POSIX_H
28 #define GCC_GTHR_POSIX_H
30 /* POSIX threads specific definitions.
31 Easy, since the interface is just one-to-one mapping. */
34 #define __GTHREADS_CXX0X 1
36 /* Some implementations of <pthread.h> require this to be defined. */
37 #if !defined(_REENTRANT) && defined(__osf__)
43 #if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \
44 || !defined(_GTHREAD_USE_MUTEX_TIMEDLOCK))
46 # if defined(_POSIX_TIMEOUTS) && _POSIX_TIMEOUTS >= 0
47 # define _GTHREAD_USE_MUTEX_TIMEDLOCK 1
49 # define _GTHREAD_USE_MUTEX_TIMEDLOCK 0
53 typedef pthread_t __gthread_t
;
54 typedef pthread_key_t __gthread_key_t
;
55 typedef pthread_once_t __gthread_once_t
;
56 typedef pthread_mutex_t __gthread_mutex_t
;
57 typedef pthread_mutex_t __gthread_recursive_mutex_t
;
58 typedef pthread_cond_t __gthread_cond_t
;
59 typedef struct timespec __gthread_time_t
;
61 /* POSIX like conditional variables are supported. Please look at comments
62 in gthr.h for details. */
63 #define __GTHREAD_HAS_COND 1
65 #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
66 #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
67 #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
68 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
69 #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
70 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
72 #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
74 #define __GTHREAD_COND_INIT PTHREAD_COND_INITIALIZER
75 #define __GTHREAD_TIME_INIT {0,0}
77 #ifdef _GTHREAD_USE_MUTEX_INIT_FUNC
78 # undef __GTHREAD_MUTEX_INIT
79 # define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
81 #ifdef _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC
82 # undef __GTHREAD_RECURSIVE_MUTEX_INIT
83 # undef __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION
84 # define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
86 #ifdef _GTHREAD_USE_COND_INIT_FUNC
87 # undef __GTHREAD_COND_INIT
88 # define __GTHREAD_COND_INIT_FUNCTION __gthread_cond_init_function
91 #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
92 # ifndef __gthrw_pragma
93 # define __gthrw_pragma(pragma)
95 # define __gthrw2(name,name2,type) \
96 static __typeof(type) name __attribute__ ((__weakref__(#name2))); \
97 __gthrw_pragma(weak type)
98 # define __gthrw_(name) __gthrw_ ## name
100 # define __gthrw2(name,name2,type)
101 # define __gthrw_(name) name
104 /* Typically, __gthrw_foo is a weak reference to symbol foo. */
105 #define __gthrw(name) __gthrw2(__gthrw_ ## name,name,name)
107 /* On Tru64, /usr/include/pthread.h uses #pragma extern_prefix "__" to
108 map a subset of the POSIX pthread API to mangled versions of their
110 #if defined(__osf__) && defined(_PTHREAD_USE_MANGLED_NAMES_)
111 #define __gthrw3(name) __gthrw2(__gthrw_ ## name, __ ## name, name)
112 __gthrw3(pthread_once
)
113 __gthrw3(pthread_getspecific
)
114 __gthrw3(pthread_setspecific
)
116 __gthrw3(pthread_create
)
117 __gthrw3(pthread_join
)
118 __gthrw3(pthread_detach
)
119 __gthrw3(pthread_equal
)
120 __gthrw3(pthread_self
)
121 __gthrw3(pthread_cancel
)
122 __gthrw3(sched_yield
)
124 __gthrw3(pthread_mutex_lock
)
125 __gthrw3(pthread_mutex_trylock
)
126 #if _GTHREAD_USE_MUTEX_TIMEDLOCK
127 __gthrw3(pthread_mutex_timedlock
)
129 __gthrw3(pthread_mutex_unlock
)
130 __gthrw3(pthread_mutex_init
)
131 __gthrw3(pthread_mutex_destroy
)
133 __gthrw3(pthread_cond_init
)
134 __gthrw3(pthread_cond_broadcast
)
135 __gthrw3(pthread_cond_signal
)
136 __gthrw3(pthread_cond_wait
)
137 __gthrw3(pthread_cond_timedwait
)
138 __gthrw3(pthread_cond_destroy
)
140 __gthrw(pthread_once
)
141 __gthrw(pthread_getspecific
)
142 __gthrw(pthread_setspecific
)
144 __gthrw(pthread_create
)
145 __gthrw(pthread_join
)
146 __gthrw(pthread_equal
)
147 __gthrw(pthread_self
)
148 __gthrw(pthread_detach
)
150 __gthrw(pthread_cancel
)
154 __gthrw(pthread_mutex_lock
)
155 __gthrw(pthread_mutex_trylock
)
156 #if _GTHREAD_USE_MUTEX_TIMEDLOCK
157 __gthrw(pthread_mutex_timedlock
)
159 __gthrw(pthread_mutex_unlock
)
160 __gthrw(pthread_mutex_init
)
161 __gthrw(pthread_mutex_destroy
)
163 __gthrw(pthread_cond_init
)
164 __gthrw(pthread_cond_broadcast
)
165 __gthrw(pthread_cond_signal
)
166 __gthrw(pthread_cond_wait
)
167 __gthrw(pthread_cond_timedwait
)
168 __gthrw(pthread_cond_destroy
)
171 __gthrw(pthread_key_create
)
172 __gthrw(pthread_key_delete
)
173 __gthrw(pthread_mutexattr_init
)
174 __gthrw(pthread_mutexattr_settype
)
175 __gthrw(pthread_mutexattr_destroy
)
178 #if defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)
180 #if defined(__osf__) && defined(_PTHREAD_USE_MANGLED_NAMES_)
181 __gthrw3(pthread_exit
)
183 __gthrw(pthread_exit
)
184 #endif /* __osf__ && _PTHREAD_USE_MANGLED_NAMES_ */
185 #ifdef _POSIX_PRIORITY_SCHEDULING
186 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
187 __gthrw(sched_get_priority_max
)
188 __gthrw(sched_get_priority_min
)
189 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
190 #endif /* _POSIX_PRIORITY_SCHEDULING */
191 __gthrw(pthread_attr_destroy
)
192 __gthrw(pthread_attr_init
)
193 __gthrw(pthread_attr_setdetachstate
)
194 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
195 __gthrw(pthread_getschedparam
)
196 __gthrw(pthread_setschedparam
)
197 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
198 #endif /* _LIBOBJC || _LIBOBJC_WEAK */
200 #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
202 /* On Solaris 2.6 up to 9, the libc exposes a POSIX threads interface even if
203 -pthreads is not specified. The functions are dummies and most return an
204 error value. However pthread_once returns 0 without invoking the routine
205 it is passed so we cannot pretend that the interface is active if -pthreads
206 is not specified. On Solaris 2.5.1, the interface is not exposed at all so
207 we need to play the usual game with weak symbols. On Solaris 10 and up, a
208 working interface is always exposed. On FreeBSD 6 and later, libc also
209 exposes a dummy POSIX threads interface, similar to what Solaris 2.6 up
210 to 9 does. FreeBSD >= 700014 even provides a pthread_cancel stub in libc,
211 which means the alternate __gthread_active_p below cannot be used there. */
213 #if defined(__FreeBSD__) || (defined(__sun) && defined(__svr4__))
215 static volatile int __gthread_active
= -1;
218 __gthread_trigger (void)
220 __gthread_active
= 1;
224 __gthread_active_p (void)
226 static pthread_mutex_t __gthread_active_mutex
= PTHREAD_MUTEX_INITIALIZER
;
227 static pthread_once_t __gthread_active_once
= PTHREAD_ONCE_INIT
;
229 /* Avoid reading __gthread_active twice on the main code path. */
230 int __gthread_active_latest_value
= __gthread_active
;
232 /* This test is not protected to avoid taking a lock on the main code
233 path so every update of __gthread_active in a threaded program must
234 be atomic with regard to the result of the test. */
235 if (__builtin_expect (__gthread_active_latest_value
< 0, 0))
237 if (__gthrw_(pthread_once
))
239 /* If this really is a threaded program, then we must ensure that
240 __gthread_active has been set to 1 before exiting this block. */
241 __gthrw_(pthread_mutex_lock
) (&__gthread_active_mutex
);
242 __gthrw_(pthread_once
) (&__gthread_active_once
, __gthread_trigger
);
243 __gthrw_(pthread_mutex_unlock
) (&__gthread_active_mutex
);
246 /* Make sure we'll never enter this block again. */
247 if (__gthread_active
< 0)
248 __gthread_active
= 0;
250 __gthread_active_latest_value
= __gthread_active
;
253 return __gthread_active_latest_value
!= 0;
256 #else /* neither FreeBSD nor Solaris */
259 __gthread_active_p (void)
261 /* Android's C library does not provide pthread_cancel, check for
262 `pthread_create' instead. */
264 static void *const __gthread_active_ptr
265 = __extension__ (void *) &__gthrw_(pthread_cancel
);
267 static void *const __gthread_active_ptr
268 = __extension__ (void *) &__gthrw_(pthread_create
);
270 return __gthread_active_ptr
!= 0;
273 #endif /* FreeBSD or Solaris */
275 #else /* not SUPPORTS_WEAK */
277 /* Similar to Solaris, HP-UX 11 for PA-RISC provides stubs for pthread
278 calls in shared flavors of the HP-UX C library. Most of the stubs
279 have no functionality. The details are described in the "libc cumulative
280 patch" for each subversion of HP-UX 11. There are two special interfaces
281 provided for checking whether an application is linked to a shared pthread
282 library or not. However, these interfaces aren't available in early
283 libpthread libraries. We also need a test that works for archive
284 libraries. We can't use pthread_once as some libc versions call the
285 init function. We also can't use pthread_create or pthread_attr_init
286 as these create a thread and thereby prevent changing the default stack
287 size. The function pthread_default_stacksize_np is available in both
288 the archive and shared versions of libpthread. It can be used to
289 determine the default pthread stack size. There is a stub in some
290 shared libc versions which returns a zero size if pthreads are not
291 active. We provide an equivalent stub to handle cases where libc
292 doesn't provide one. */
294 #if defined(__hppa__) && defined(__hpux__)
296 static volatile int __gthread_active
= -1;
299 __gthread_active_p (void)
301 /* Avoid reading __gthread_active twice on the main code path. */
302 int __gthread_active_latest_value
= __gthread_active
;
305 if (__builtin_expect (__gthread_active_latest_value
< 0, 0))
307 pthread_default_stacksize_np (0, &__s
);
308 __gthread_active
= __s
? 1 : 0;
309 __gthread_active_latest_value
= __gthread_active
;
312 return __gthread_active_latest_value
!= 0;
315 #else /* not hppa-hpux */
318 __gthread_active_p (void)
323 #endif /* hppa-hpux */
325 #endif /* SUPPORTS_WEAK */
329 /* This is the config.h file in libobjc/ */
336 /* Key structure for maintaining thread specific storage */
337 static pthread_key_t _objc_thread_storage
;
338 static pthread_attr_t _objc_thread_attribs
;
340 /* Thread local storage for a single thread */
341 static void *thread_local_storage
= NULL
;
343 /* Backend initialization functions */
345 /* Initialize the threads subsystem. */
347 __gthread_objc_init_thread_system (void)
349 if (__gthread_active_p ())
351 /* Initialize the thread storage key. */
352 if (__gthrw_(pthread_key_create
) (&_objc_thread_storage
, NULL
) == 0)
354 /* The normal default detach state for threads is
355 * PTHREAD_CREATE_JOINABLE which causes threads to not die
356 * when you think they should. */
357 if (__gthrw_(pthread_attr_init
) (&_objc_thread_attribs
) == 0
358 && __gthrw_(pthread_attr_setdetachstate
) (&_objc_thread_attribs
,
359 PTHREAD_CREATE_DETACHED
) == 0)
367 /* Close the threads subsystem. */
369 __gthread_objc_close_thread_system (void)
371 if (__gthread_active_p ()
372 && __gthrw_(pthread_key_delete
) (_objc_thread_storage
) == 0
373 && __gthrw_(pthread_attr_destroy
) (&_objc_thread_attribs
) == 0)
379 /* Backend thread functions */
381 /* Create a new thread of execution. */
382 static inline objc_thread_t
383 __gthread_objc_thread_detach (void (*func
)(void *), void *arg
)
385 objc_thread_t thread_id
;
386 pthread_t new_thread_handle
;
388 if (!__gthread_active_p ())
391 if (!(__gthrw_(pthread_create
) (&new_thread_handle
, &_objc_thread_attribs
,
392 (void *) func
, arg
)))
393 thread_id
= (objc_thread_t
) new_thread_handle
;
400 /* Set the current thread's priority. */
402 __gthread_objc_thread_set_priority (int priority
)
404 if (!__gthread_active_p ())
408 #ifdef _POSIX_PRIORITY_SCHEDULING
409 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
410 pthread_t thread_id
= __gthrw_(pthread_self
) ();
412 struct sched_param params
;
413 int priority_min
, priority_max
;
415 if (__gthrw_(pthread_getschedparam
) (thread_id
, &policy
, ¶ms
) == 0)
417 if ((priority_max
= __gthrw_(sched_get_priority_max
) (policy
)) == -1)
420 if ((priority_min
= __gthrw_(sched_get_priority_min
) (policy
)) == -1)
423 if (priority
> priority_max
)
424 priority
= priority_max
;
425 else if (priority
< priority_min
)
426 priority
= priority_min
;
427 params
.sched_priority
= priority
;
430 * The solaris 7 and several other man pages incorrectly state that
431 * this should be a pointer to policy but pthread.h is universally
434 if (__gthrw_(pthread_setschedparam
) (thread_id
, policy
, ¶ms
) == 0)
437 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
438 #endif /* _POSIX_PRIORITY_SCHEDULING */
443 /* Return the current thread's priority. */
445 __gthread_objc_thread_get_priority (void)
447 #ifdef _POSIX_PRIORITY_SCHEDULING
448 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
449 if (__gthread_active_p ())
452 struct sched_param params
;
454 if (__gthrw_(pthread_getschedparam
) (__gthrw_(pthread_self
) (), &policy
, ¶ms
) == 0)
455 return params
.sched_priority
;
460 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
461 #endif /* _POSIX_PRIORITY_SCHEDULING */
462 return OBJC_THREAD_INTERACTIVE_PRIORITY
;
465 /* Yield our process time to another thread. */
467 __gthread_objc_thread_yield (void)
469 if (__gthread_active_p ())
470 __gthrw_(sched_yield
) ();
473 /* Terminate the current thread. */
475 __gthread_objc_thread_exit (void)
477 if (__gthread_active_p ())
478 /* exit the thread */
479 __gthrw_(pthread_exit
) (&__objc_thread_exit_status
);
481 /* Failed if we reached here */
485 /* Returns an integer value which uniquely describes a thread. */
486 static inline objc_thread_t
487 __gthread_objc_thread_id (void)
489 if (__gthread_active_p ())
490 return (objc_thread_t
) __gthrw_(pthread_self
) ();
492 return (objc_thread_t
) 1;
495 /* Sets the thread's local storage pointer. */
497 __gthread_objc_thread_set_data (void *value
)
499 if (__gthread_active_p ())
500 return __gthrw_(pthread_setspecific
) (_objc_thread_storage
, value
);
503 thread_local_storage
= value
;
508 /* Returns the thread's local storage pointer. */
510 __gthread_objc_thread_get_data (void)
512 if (__gthread_active_p ())
513 return __gthrw_(pthread_getspecific
) (_objc_thread_storage
);
515 return thread_local_storage
;
518 /* Backend mutex functions */
520 /* Allocate a mutex. */
522 __gthread_objc_mutex_allocate (objc_mutex_t mutex
)
524 if (__gthread_active_p ())
526 mutex
->backend
= objc_malloc (sizeof (pthread_mutex_t
));
528 if (__gthrw_(pthread_mutex_init
) ((pthread_mutex_t
*) mutex
->backend
, NULL
))
530 objc_free (mutex
->backend
);
531 mutex
->backend
= NULL
;
539 /* Deallocate a mutex. */
541 __gthread_objc_mutex_deallocate (objc_mutex_t mutex
)
543 if (__gthread_active_p ())
548 * Posix Threads specifically require that the thread be unlocked
549 * for __gthrw_(pthread_mutex_destroy) to work.
554 count
= __gthrw_(pthread_mutex_unlock
) ((pthread_mutex_t
*) mutex
->backend
);
560 if (__gthrw_(pthread_mutex_destroy
) ((pthread_mutex_t
*) mutex
->backend
))
563 objc_free (mutex
->backend
);
564 mutex
->backend
= NULL
;
569 /* Grab a lock on a mutex. */
571 __gthread_objc_mutex_lock (objc_mutex_t mutex
)
573 if (__gthread_active_p ()
574 && __gthrw_(pthread_mutex_lock
) ((pthread_mutex_t
*) mutex
->backend
) != 0)
582 /* Try to grab a lock on a mutex. */
584 __gthread_objc_mutex_trylock (objc_mutex_t mutex
)
586 if (__gthread_active_p ()
587 && __gthrw_(pthread_mutex_trylock
) ((pthread_mutex_t
*) mutex
->backend
) != 0)
595 /* Unlock the mutex */
597 __gthread_objc_mutex_unlock (objc_mutex_t mutex
)
599 if (__gthread_active_p ()
600 && __gthrw_(pthread_mutex_unlock
) ((pthread_mutex_t
*) mutex
->backend
) != 0)
608 /* Backend condition mutex functions */
610 /* Allocate a condition. */
612 __gthread_objc_condition_allocate (objc_condition_t condition
)
614 if (__gthread_active_p ())
616 condition
->backend
= objc_malloc (sizeof (pthread_cond_t
));
618 if (__gthrw_(pthread_cond_init
) ((pthread_cond_t
*) condition
->backend
, NULL
))
620 objc_free (condition
->backend
);
621 condition
->backend
= NULL
;
629 /* Deallocate a condition. */
631 __gthread_objc_condition_deallocate (objc_condition_t condition
)
633 if (__gthread_active_p ())
635 if (__gthrw_(pthread_cond_destroy
) ((pthread_cond_t
*) condition
->backend
))
638 objc_free (condition
->backend
);
639 condition
->backend
= NULL
;
644 /* Wait on the condition */
646 __gthread_objc_condition_wait (objc_condition_t condition
, objc_mutex_t mutex
)
648 if (__gthread_active_p ())
649 return __gthrw_(pthread_cond_wait
) ((pthread_cond_t
*) condition
->backend
,
650 (pthread_mutex_t
*) mutex
->backend
);
655 /* Wake up all threads waiting on this condition. */
657 __gthread_objc_condition_broadcast (objc_condition_t condition
)
659 if (__gthread_active_p ())
660 return __gthrw_(pthread_cond_broadcast
) ((pthread_cond_t
*) condition
->backend
);
665 /* Wake up one thread waiting on this condition. */
667 __gthread_objc_condition_signal (objc_condition_t condition
)
669 if (__gthread_active_p ())
670 return __gthrw_(pthread_cond_signal
) ((pthread_cond_t
*) condition
->backend
);
678 __gthread_create (__gthread_t
*__threadid
, void *(*__func
) (void*),
681 return __gthrw_(pthread_create
) (__threadid
, NULL
, __func
, __args
);
685 __gthread_join (__gthread_t __threadid
, void **__value_ptr
)
687 return __gthrw_(pthread_join
) (__threadid
, __value_ptr
);
691 __gthread_detach (__gthread_t __threadid
)
693 return __gthrw_(pthread_detach
) (__threadid
);
697 __gthread_equal (__gthread_t __t1
, __gthread_t __t2
)
699 return __gthrw_(pthread_equal
) (__t1
, __t2
);
702 static inline __gthread_t
703 __gthread_self (void)
705 return __gthrw_(pthread_self
) ();
709 __gthread_yield (void)
711 return __gthrw_(sched_yield
) ();
715 __gthread_once (__gthread_once_t
*__once
, void (*__func
) (void))
717 if (__gthread_active_p ())
718 return __gthrw_(pthread_once
) (__once
, __func
);
724 __gthread_key_create (__gthread_key_t
*__key
, void (*__dtor
) (void *))
726 return __gthrw_(pthread_key_create
) (__key
, __dtor
);
730 __gthread_key_delete (__gthread_key_t __key
)
732 return __gthrw_(pthread_key_delete
) (__key
);
736 __gthread_getspecific (__gthread_key_t __key
)
738 return __gthrw_(pthread_getspecific
) (__key
);
742 __gthread_setspecific (__gthread_key_t __key
, const void *__ptr
)
744 return __gthrw_(pthread_setspecific
) (__key
, __ptr
);
747 #ifdef _GTHREAD_USE_MUTEX_INIT_FUNC
749 __gthread_mutex_init_function (__gthread_mutex_t
*__mutex
)
751 if (__gthread_active_p ())
752 __gthrw_(pthread_mutex_init
) (__mutex
, NULL
);
757 __gthread_mutex_destroy (__gthread_mutex_t
*__mutex
)
759 if (__gthread_active_p ())
760 return __gthrw_(pthread_mutex_destroy
) (__mutex
);
766 __gthread_mutex_lock (__gthread_mutex_t
*__mutex
)
768 if (__gthread_active_p ())
769 return __gthrw_(pthread_mutex_lock
) (__mutex
);
775 __gthread_mutex_trylock (__gthread_mutex_t
*__mutex
)
777 if (__gthread_active_p ())
778 return __gthrw_(pthread_mutex_trylock
) (__mutex
);
783 #if _GTHREAD_USE_MUTEX_TIMEDLOCK
785 __gthread_mutex_timedlock (__gthread_mutex_t
*__mutex
,
786 const __gthread_time_t
*__abs_timeout
)
788 if (__gthread_active_p ())
789 return __gthrw_(pthread_mutex_timedlock
) (__mutex
, __abs_timeout
);
796 __gthread_mutex_unlock (__gthread_mutex_t
*__mutex
)
798 if (__gthread_active_p ())
799 return __gthrw_(pthread_mutex_unlock
) (__mutex
);
804 #if !defined( PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) \
805 || defined(_GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC)
807 __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t
*__mutex
)
809 if (__gthread_active_p ())
811 pthread_mutexattr_t __attr
;
814 __r
= __gthrw_(pthread_mutexattr_init
) (&__attr
);
816 __r
= __gthrw_(pthread_mutexattr_settype
) (&__attr
,
817 PTHREAD_MUTEX_RECURSIVE
);
819 __r
= __gthrw_(pthread_mutex_init
) (__mutex
, &__attr
);
821 __r
= __gthrw_(pthread_mutexattr_destroy
) (&__attr
);
829 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t
*__mutex
)
831 return __gthread_mutex_lock (__mutex
);
835 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t
*__mutex
)
837 return __gthread_mutex_trylock (__mutex
);
840 #if _GTHREAD_USE_MUTEX_TIMEDLOCK
842 __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t
*__mutex
,
843 const __gthread_time_t
*__abs_timeout
)
845 return __gthread_mutex_timedlock (__mutex
, __abs_timeout
);
850 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t
*__mutex
)
852 return __gthread_mutex_unlock (__mutex
);
855 #ifdef _GTHREAD_USE_COND_INIT_FUNC
857 __gthread_cond_init_function (__gthread_cond_t
*__cond
)
859 if (__gthread_active_p ())
860 __gthrw_(pthread_cond_init
) (__cond
, NULL
);
865 __gthread_cond_broadcast (__gthread_cond_t
*__cond
)
867 return __gthrw_(pthread_cond_broadcast
) (__cond
);
871 __gthread_cond_signal (__gthread_cond_t
*__cond
)
873 return __gthrw_(pthread_cond_signal
) (__cond
);
877 __gthread_cond_wait (__gthread_cond_t
*__cond
, __gthread_mutex_t
*__mutex
)
879 return __gthrw_(pthread_cond_wait
) (__cond
, __mutex
);
883 __gthread_cond_timedwait (__gthread_cond_t
*__cond
, __gthread_mutex_t
*__mutex
,
884 const __gthread_time_t
*__abs_timeout
)
886 return __gthrw_(pthread_cond_timedwait
) (__cond
, __mutex
, __abs_timeout
);
890 __gthread_cond_wait_recursive (__gthread_cond_t
*__cond
,
891 __gthread_recursive_mutex_t
*__mutex
)
893 return __gthread_cond_wait (__cond
, __mutex
);
897 __gthread_cond_timedwait_recursive (__gthread_cond_t
*__cond
,
898 __gthread_recursive_mutex_t
*__mutex
,
899 const __gthread_time_t
*__abs_timeout
)
901 return __gthread_cond_timedwait (__cond
, __mutex
, __abs_timeout
);
905 __gthread_cond_destroy (__gthread_cond_t
* __cond
)
907 return __gthrw_(pthread_cond_destroy
) (__cond
);
910 #endif /* _LIBOBJC */
912 #endif /* ! GCC_GTHR_POSIX_H */