Remove dead reference in checking code
[official-gcc.git] / gcc-4_7-mobile / libgcc / gthr-posix.h
blob6c9af1a476582898b614c16a9bff1a402cc120b5
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
11 version.
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
16 for more details.
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. */
33 #define __GTHREADS 1
34 #define __GTHREADS_CXX0X 1
36 /* Some implementations of <pthread.h> require this to be defined. */
37 #if !defined(_REENTRANT) && defined(__osf__)
38 #define _REENTRANT 1
39 #endif
41 #include <pthread.h>
43 #if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \
44 || !defined(_GTHREAD_USE_MUTEX_TIMEDLOCK))
45 # include <unistd.h>
46 # if defined(_POSIX_TIMEOUTS) && _POSIX_TIMEOUTS >= 0
47 # define _GTHREAD_USE_MUTEX_TIMEDLOCK 1
48 # else
49 # define _GTHREAD_USE_MUTEX_TIMEDLOCK 0
50 # endif
51 #endif
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_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
67 #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
68 #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
69 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
70 #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
71 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
72 #else
73 #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
74 #endif
75 #define __GTHREAD_COND_INIT PTHREAD_COND_INITIALIZER
76 #define __GTHREAD_TIME_INIT {0,0}
78 #ifdef _GTHREAD_USE_MUTEX_INIT_FUNC
79 # undef __GTHREAD_MUTEX_INIT
80 # define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
81 #endif
82 #ifdef _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC
83 # undef __GTHREAD_RECURSIVE_MUTEX_INIT
84 # undef __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION
85 # define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
86 #endif
87 #ifdef _GTHREAD_USE_COND_INIT_FUNC
88 # undef __GTHREAD_COND_INIT
89 # define __GTHREAD_COND_INIT_FUNCTION __gthread_cond_init_function
90 #endif
92 #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
93 # ifndef __gthrw_pragma
94 # define __gthrw_pragma(pragma)
95 # endif
96 # define __gthrw2(name,name2,type) \
97 static __typeof(type) name __attribute__ ((__weakref__(#name2))); \
98 __gthrw_pragma(weak type)
99 # define __gthrw_(name) __gthrw_ ## name
100 #else
101 # define __gthrw2(name,name2,type)
102 # define __gthrw_(name) name
103 #endif
105 /* Typically, __gthrw_foo is a weak reference to symbol foo. */
106 #define __gthrw(name) __gthrw2(__gthrw_ ## name,name,name)
108 /* On Tru64, /usr/include/pthread.h uses #pragma extern_prefix "__" to
109 map a subset of the POSIX pthread API to mangled versions of their
110 names. */
111 #if defined(__osf__) && defined(_PTHREAD_USE_MANGLED_NAMES_)
112 #define __gthrw3(name) __gthrw2(__gthrw_ ## name, __ ## name, name)
113 __gthrw3(pthread_once)
114 __gthrw3(pthread_getspecific)
115 __gthrw3(pthread_setspecific)
117 __gthrw3(pthread_create)
118 __gthrw3(pthread_join)
119 __gthrw3(pthread_detach)
120 __gthrw3(pthread_equal)
121 __gthrw3(pthread_self)
122 __gthrw3(pthread_cancel)
123 __gthrw3(sched_yield)
125 __gthrw3(pthread_mutex_lock)
126 __gthrw3(pthread_mutex_trylock)
127 #if _GTHREAD_USE_MUTEX_TIMEDLOCK
128 __gthrw3(pthread_mutex_timedlock)
129 #endif
130 __gthrw3(pthread_mutex_unlock)
131 __gthrw3(pthread_mutex_init)
132 __gthrw3(pthread_mutex_destroy)
134 __gthrw3(pthread_cond_init)
135 __gthrw3(pthread_cond_broadcast)
136 __gthrw3(pthread_cond_signal)
137 __gthrw3(pthread_cond_wait)
138 __gthrw3(pthread_cond_timedwait)
139 __gthrw3(pthread_cond_destroy)
140 #else
141 __gthrw(pthread_once)
142 __gthrw(pthread_getspecific)
143 __gthrw(pthread_setspecific)
145 __gthrw(pthread_create)
146 __gthrw(pthread_join)
147 __gthrw(pthread_equal)
148 __gthrw(pthread_self)
149 __gthrw(pthread_detach)
150 #ifndef __BIONIC__
151 __gthrw(pthread_cancel)
152 #endif
153 __gthrw(sched_yield)
155 __gthrw(pthread_mutex_lock)
156 __gthrw(pthread_mutex_trylock)
157 #if _GTHREAD_USE_MUTEX_TIMEDLOCK
158 __gthrw(pthread_mutex_timedlock)
159 #endif
160 __gthrw(pthread_mutex_unlock)
161 __gthrw(pthread_mutex_init)
162 __gthrw(pthread_mutex_destroy)
164 __gthrw(pthread_cond_init)
165 __gthrw(pthread_cond_broadcast)
166 __gthrw(pthread_cond_signal)
167 __gthrw(pthread_cond_wait)
168 __gthrw(pthread_cond_timedwait)
169 __gthrw(pthread_cond_destroy)
170 #endif
172 __gthrw(pthread_key_create)
173 __gthrw(pthread_key_delete)
174 __gthrw(pthread_mutexattr_init)
175 __gthrw(pthread_mutexattr_settype)
176 __gthrw(pthread_mutexattr_destroy)
179 #if defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)
180 /* Objective-C. */
181 #if defined(__osf__) && defined(_PTHREAD_USE_MANGLED_NAMES_)
182 __gthrw3(pthread_exit)
183 #else
184 __gthrw(pthread_exit)
185 #endif /* __osf__ && _PTHREAD_USE_MANGLED_NAMES_ */
186 #ifdef _POSIX_PRIORITY_SCHEDULING
187 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
188 __gthrw(sched_get_priority_max)
189 __gthrw(sched_get_priority_min)
190 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
191 #endif /* _POSIX_PRIORITY_SCHEDULING */
192 __gthrw(pthread_attr_destroy)
193 __gthrw(pthread_attr_init)
194 __gthrw(pthread_attr_setdetachstate)
195 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
196 __gthrw(pthread_getschedparam)
197 __gthrw(pthread_setschedparam)
198 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
199 #endif /* _LIBOBJC || _LIBOBJC_WEAK */
201 #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
203 /* On Solaris 2.6 up to 9, the libc exposes a POSIX threads interface even if
204 -pthreads is not specified. The functions are dummies and most return an
205 error value. However pthread_once returns 0 without invoking the routine
206 it is passed so we cannot pretend that the interface is active if -pthreads
207 is not specified. On Solaris 2.5.1, the interface is not exposed at all so
208 we need to play the usual game with weak symbols. On Solaris 10 and up, a
209 working interface is always exposed. On FreeBSD 6 and later, libc also
210 exposes a dummy POSIX threads interface, similar to what Solaris 2.6 up
211 to 9 does. FreeBSD >= 700014 even provides a pthread_cancel stub in libc,
212 which means the alternate __gthread_active_p below cannot be used there. */
214 #if defined(__FreeBSD__) || (defined(__sun) && defined(__svr4__))
216 static volatile int __gthread_active = -1;
218 static void
219 __gthread_trigger (void)
221 __gthread_active = 1;
224 static inline int
225 __gthread_active_p (void)
227 static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
228 static pthread_once_t __gthread_active_once = PTHREAD_ONCE_INIT;
230 /* Avoid reading __gthread_active twice on the main code path. */
231 int __gthread_active_latest_value = __gthread_active;
233 /* This test is not protected to avoid taking a lock on the main code
234 path so every update of __gthread_active in a threaded program must
235 be atomic with regard to the result of the test. */
236 if (__builtin_expect (__gthread_active_latest_value < 0, 0))
238 if (__gthrw_(pthread_once))
240 /* If this really is a threaded program, then we must ensure that
241 __gthread_active has been set to 1 before exiting this block. */
242 __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex);
243 __gthrw_(pthread_once) (&__gthread_active_once, __gthread_trigger);
244 __gthrw_(pthread_mutex_unlock) (&__gthread_active_mutex);
247 /* Make sure we'll never enter this block again. */
248 if (__gthread_active < 0)
249 __gthread_active = 0;
251 __gthread_active_latest_value = __gthread_active;
254 return __gthread_active_latest_value != 0;
257 #else /* neither FreeBSD nor Solaris */
259 static inline int
260 __gthread_active_p (void)
262 /* Android's C library does not provide pthread_cancel, check for
263 `pthread_create' instead. */
264 #ifndef __BIONIC__
265 static void *const __gthread_active_ptr
266 = __extension__ (void *) &__gthrw_(pthread_cancel);
267 #else
268 static void *const __gthread_active_ptr
269 = __extension__ (void *) &__gthrw_(pthread_create);
270 #endif
271 return __gthread_active_ptr != 0;
274 #endif /* FreeBSD or Solaris */
276 #else /* not SUPPORTS_WEAK */
278 /* Similar to Solaris, HP-UX 11 for PA-RISC provides stubs for pthread
279 calls in shared flavors of the HP-UX C library. Most of the stubs
280 have no functionality. The details are described in the "libc cumulative
281 patch" for each subversion of HP-UX 11. There are two special interfaces
282 provided for checking whether an application is linked to a shared pthread
283 library or not. However, these interfaces aren't available in early
284 libpthread libraries. We also need a test that works for archive
285 libraries. We can't use pthread_once as some libc versions call the
286 init function. We also can't use pthread_create or pthread_attr_init
287 as these create a thread and thereby prevent changing the default stack
288 size. The function pthread_default_stacksize_np is available in both
289 the archive and shared versions of libpthread. It can be used to
290 determine the default pthread stack size. There is a stub in some
291 shared libc versions which returns a zero size if pthreads are not
292 active. We provide an equivalent stub to handle cases where libc
293 doesn't provide one. */
295 #if defined(__hppa__) && defined(__hpux__)
297 static volatile int __gthread_active = -1;
299 static inline int
300 __gthread_active_p (void)
302 /* Avoid reading __gthread_active twice on the main code path. */
303 int __gthread_active_latest_value = __gthread_active;
304 size_t __s;
306 if (__builtin_expect (__gthread_active_latest_value < 0, 0))
308 pthread_default_stacksize_np (0, &__s);
309 __gthread_active = __s ? 1 : 0;
310 __gthread_active_latest_value = __gthread_active;
313 return __gthread_active_latest_value != 0;
316 #else /* not hppa-hpux */
318 static inline int
319 __gthread_active_p (void)
321 return 1;
324 #endif /* hppa-hpux */
326 #endif /* SUPPORTS_WEAK */
328 #ifdef _LIBOBJC
330 /* This is the config.h file in libobjc/ */
331 #include <config.h>
333 #ifdef HAVE_SCHED_H
334 # include <sched.h>
335 #endif
337 /* Key structure for maintaining thread specific storage */
338 static pthread_key_t _objc_thread_storage;
339 static pthread_attr_t _objc_thread_attribs;
341 /* Thread local storage for a single thread */
342 static void *thread_local_storage = NULL;
344 /* Backend initialization functions */
346 /* Initialize the threads subsystem. */
347 static inline int
348 __gthread_objc_init_thread_system (void)
350 if (__gthread_active_p ())
352 /* Initialize the thread storage key. */
353 if (__gthrw_(pthread_key_create) (&_objc_thread_storage, NULL) == 0)
355 /* The normal default detach state for threads is
356 * PTHREAD_CREATE_JOINABLE which causes threads to not die
357 * when you think they should. */
358 if (__gthrw_(pthread_attr_init) (&_objc_thread_attribs) == 0
359 && __gthrw_(pthread_attr_setdetachstate) (&_objc_thread_attribs,
360 PTHREAD_CREATE_DETACHED) == 0)
361 return 0;
365 return -1;
368 /* Close the threads subsystem. */
369 static inline int
370 __gthread_objc_close_thread_system (void)
372 if (__gthread_active_p ()
373 && __gthrw_(pthread_key_delete) (_objc_thread_storage) == 0
374 && __gthrw_(pthread_attr_destroy) (&_objc_thread_attribs) == 0)
375 return 0;
377 return -1;
380 /* Backend thread functions */
382 /* Create a new thread of execution. */
383 static inline objc_thread_t
384 __gthread_objc_thread_detach (void (*func)(void *), void *arg)
386 objc_thread_t thread_id;
387 pthread_t new_thread_handle;
389 if (!__gthread_active_p ())
390 return NULL;
392 if (!(__gthrw_(pthread_create) (&new_thread_handle, &_objc_thread_attribs,
393 (void *) func, arg)))
394 thread_id = (objc_thread_t) new_thread_handle;
395 else
396 thread_id = NULL;
398 return thread_id;
401 /* Set the current thread's priority. */
402 static inline int
403 __gthread_objc_thread_set_priority (int priority)
405 if (!__gthread_active_p ())
406 return -1;
407 else
409 #ifdef _POSIX_PRIORITY_SCHEDULING
410 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
411 pthread_t thread_id = __gthrw_(pthread_self) ();
412 int policy;
413 struct sched_param params;
414 int priority_min, priority_max;
416 if (__gthrw_(pthread_getschedparam) (thread_id, &policy, &params) == 0)
418 if ((priority_max = __gthrw_(sched_get_priority_max) (policy)) == -1)
419 return -1;
421 if ((priority_min = __gthrw_(sched_get_priority_min) (policy)) == -1)
422 return -1;
424 if (priority > priority_max)
425 priority = priority_max;
426 else if (priority < priority_min)
427 priority = priority_min;
428 params.sched_priority = priority;
431 * The solaris 7 and several other man pages incorrectly state that
432 * this should be a pointer to policy but pthread.h is universally
433 * at odds with this.
435 if (__gthrw_(pthread_setschedparam) (thread_id, policy, &params) == 0)
436 return 0;
438 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
439 #endif /* _POSIX_PRIORITY_SCHEDULING */
440 return -1;
444 /* Return the current thread's priority. */
445 static inline int
446 __gthread_objc_thread_get_priority (void)
448 #ifdef _POSIX_PRIORITY_SCHEDULING
449 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
450 if (__gthread_active_p ())
452 int policy;
453 struct sched_param params;
455 if (__gthrw_(pthread_getschedparam) (__gthrw_(pthread_self) (), &policy, &params) == 0)
456 return params.sched_priority;
457 else
458 return -1;
460 else
461 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
462 #endif /* _POSIX_PRIORITY_SCHEDULING */
463 return OBJC_THREAD_INTERACTIVE_PRIORITY;
466 /* Yield our process time to another thread. */
467 static inline void
468 __gthread_objc_thread_yield (void)
470 if (__gthread_active_p ())
471 __gthrw_(sched_yield) ();
474 /* Terminate the current thread. */
475 static inline int
476 __gthread_objc_thread_exit (void)
478 if (__gthread_active_p ())
479 /* exit the thread */
480 __gthrw_(pthread_exit) (&__objc_thread_exit_status);
482 /* Failed if we reached here */
483 return -1;
486 /* Returns an integer value which uniquely describes a thread. */
487 static inline objc_thread_t
488 __gthread_objc_thread_id (void)
490 if (__gthread_active_p ())
491 return (objc_thread_t) __gthrw_(pthread_self) ();
492 else
493 return (objc_thread_t) 1;
496 /* Sets the thread's local storage pointer. */
497 static inline int
498 __gthread_objc_thread_set_data (void *value)
500 if (__gthread_active_p ())
501 return __gthrw_(pthread_setspecific) (_objc_thread_storage, value);
502 else
504 thread_local_storage = value;
505 return 0;
509 /* Returns the thread's local storage pointer. */
510 static inline void *
511 __gthread_objc_thread_get_data (void)
513 if (__gthread_active_p ())
514 return __gthrw_(pthread_getspecific) (_objc_thread_storage);
515 else
516 return thread_local_storage;
519 /* Backend mutex functions */
521 /* Allocate a mutex. */
522 static inline int
523 __gthread_objc_mutex_allocate (objc_mutex_t mutex)
525 if (__gthread_active_p ())
527 mutex->backend = objc_malloc (sizeof (pthread_mutex_t));
529 if (__gthrw_(pthread_mutex_init) ((pthread_mutex_t *) mutex->backend, NULL))
531 objc_free (mutex->backend);
532 mutex->backend = NULL;
533 return -1;
537 return 0;
540 /* Deallocate a mutex. */
541 static inline int
542 __gthread_objc_mutex_deallocate (objc_mutex_t mutex)
544 if (__gthread_active_p ())
546 int count;
549 * Posix Threads specifically require that the thread be unlocked
550 * for __gthrw_(pthread_mutex_destroy) to work.
555 count = __gthrw_(pthread_mutex_unlock) ((pthread_mutex_t *) mutex->backend);
556 if (count < 0)
557 return -1;
559 while (count);
561 if (__gthrw_(pthread_mutex_destroy) ((pthread_mutex_t *) mutex->backend))
562 return -1;
564 objc_free (mutex->backend);
565 mutex->backend = NULL;
567 return 0;
570 /* Grab a lock on a mutex. */
571 static inline int
572 __gthread_objc_mutex_lock (objc_mutex_t mutex)
574 if (__gthread_active_p ()
575 && __gthrw_(pthread_mutex_lock) ((pthread_mutex_t *) mutex->backend) != 0)
577 return -1;
580 return 0;
583 /* Try to grab a lock on a mutex. */
584 static inline int
585 __gthread_objc_mutex_trylock (objc_mutex_t mutex)
587 if (__gthread_active_p ()
588 && __gthrw_(pthread_mutex_trylock) ((pthread_mutex_t *) mutex->backend) != 0)
590 return -1;
593 return 0;
596 /* Unlock the mutex */
597 static inline int
598 __gthread_objc_mutex_unlock (objc_mutex_t mutex)
600 if (__gthread_active_p ()
601 && __gthrw_(pthread_mutex_unlock) ((pthread_mutex_t *) mutex->backend) != 0)
603 return -1;
606 return 0;
609 /* Backend condition mutex functions */
611 /* Allocate a condition. */
612 static inline int
613 __gthread_objc_condition_allocate (objc_condition_t condition)
615 if (__gthread_active_p ())
617 condition->backend = objc_malloc (sizeof (pthread_cond_t));
619 if (__gthrw_(pthread_cond_init) ((pthread_cond_t *) condition->backend, NULL))
621 objc_free (condition->backend);
622 condition->backend = NULL;
623 return -1;
627 return 0;
630 /* Deallocate a condition. */
631 static inline int
632 __gthread_objc_condition_deallocate (objc_condition_t condition)
634 if (__gthread_active_p ())
636 if (__gthrw_(pthread_cond_destroy) ((pthread_cond_t *) condition->backend))
637 return -1;
639 objc_free (condition->backend);
640 condition->backend = NULL;
642 return 0;
645 /* Wait on the condition */
646 static inline int
647 __gthread_objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex)
649 if (__gthread_active_p ())
650 return __gthrw_(pthread_cond_wait) ((pthread_cond_t *) condition->backend,
651 (pthread_mutex_t *) mutex->backend);
652 else
653 return 0;
656 /* Wake up all threads waiting on this condition. */
657 static inline int
658 __gthread_objc_condition_broadcast (objc_condition_t condition)
660 if (__gthread_active_p ())
661 return __gthrw_(pthread_cond_broadcast) ((pthread_cond_t *) condition->backend);
662 else
663 return 0;
666 /* Wake up one thread waiting on this condition. */
667 static inline int
668 __gthread_objc_condition_signal (objc_condition_t condition)
670 if (__gthread_active_p ())
671 return __gthrw_(pthread_cond_signal) ((pthread_cond_t *) condition->backend);
672 else
673 return 0;
676 #else /* _LIBOBJC */
678 static inline int
679 __gthread_create (__gthread_t *__threadid, void *(*__func) (void*),
680 void *__args)
682 return __gthrw_(pthread_create) (__threadid, NULL, __func, __args);
685 static inline int
686 __gthread_join (__gthread_t __threadid, void **__value_ptr)
688 return __gthrw_(pthread_join) (__threadid, __value_ptr);
691 static inline int
692 __gthread_detach (__gthread_t __threadid)
694 return __gthrw_(pthread_detach) (__threadid);
697 static inline int
698 __gthread_equal (__gthread_t __t1, __gthread_t __t2)
700 return __gthrw_(pthread_equal) (__t1, __t2);
703 static inline __gthread_t
704 __gthread_self (void)
706 return __gthrw_(pthread_self) ();
709 static inline int
710 __gthread_yield (void)
712 return __gthrw_(sched_yield) ();
715 static inline int
716 __gthread_once (__gthread_once_t *__once, void (*__func) (void))
718 if (__gthread_active_p ())
719 return __gthrw_(pthread_once) (__once, __func);
720 else
721 return -1;
724 static inline int
725 __gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
727 return __gthrw_(pthread_key_create) (__key, __dtor);
730 static inline int
731 __gthread_key_delete (__gthread_key_t __key)
733 return __gthrw_(pthread_key_delete) (__key);
736 static inline void *
737 __gthread_getspecific (__gthread_key_t __key)
739 return __gthrw_(pthread_getspecific) (__key);
742 static inline int
743 __gthread_setspecific (__gthread_key_t __key, const void *__ptr)
745 return __gthrw_(pthread_setspecific) (__key, __ptr);
748 #ifdef _GTHREAD_USE_MUTEX_INIT_FUNC
749 static inline void
750 __gthread_mutex_init_function (__gthread_mutex_t *__mutex)
752 if (__gthread_active_p ())
753 __gthrw_(pthread_mutex_init) (__mutex, NULL);
755 #endif
757 static inline int
758 __gthread_mutex_init_function (__gthread_mutex_t *__mutex)
760 if (__gthread_active_p ())
761 return __gthrw_(pthread_mutex_init) (__mutex, NULL);
762 return 0;
765 static inline int
766 __gthread_mutex_destroy (__gthread_mutex_t *__mutex)
768 if (__gthread_active_p ())
769 return __gthrw_(pthread_mutex_destroy) (__mutex);
770 else
771 return 0;
774 static inline int
775 __gthread_mutex_lock (__gthread_mutex_t *__mutex)
777 if (__gthread_active_p ())
778 return __gthrw_(pthread_mutex_lock) (__mutex);
779 else
780 return 0;
783 static inline int
784 __gthread_mutex_trylock (__gthread_mutex_t *__mutex)
786 if (__gthread_active_p ())
787 return __gthrw_(pthread_mutex_trylock) (__mutex);
788 else
789 return 0;
792 #if _GTHREAD_USE_MUTEX_TIMEDLOCK
793 static inline int
794 __gthread_mutex_timedlock (__gthread_mutex_t *__mutex,
795 const __gthread_time_t *__abs_timeout)
797 if (__gthread_active_p ())
798 return __gthrw_(pthread_mutex_timedlock) (__mutex, __abs_timeout);
799 else
800 return 0;
802 #endif
804 static inline int
805 __gthread_mutex_unlock (__gthread_mutex_t *__mutex)
807 if (__gthread_active_p ())
808 return __gthrw_(pthread_mutex_unlock) (__mutex);
809 else
810 return 0;
813 #if !defined( PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) \
814 || defined(_GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC)
815 static inline int
816 __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
818 if (__gthread_active_p ())
820 pthread_mutexattr_t __attr;
821 int __r;
823 __r = __gthrw_(pthread_mutexattr_init) (&__attr);
824 if (!__r)
825 __r = __gthrw_(pthread_mutexattr_settype) (&__attr,
826 PTHREAD_MUTEX_RECURSIVE);
827 if (!__r)
828 __r = __gthrw_(pthread_mutex_init) (__mutex, &__attr);
829 if (!__r)
830 __r = __gthrw_(pthread_mutexattr_destroy) (&__attr);
831 return __r;
833 return 0;
835 #endif
837 static inline int
838 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
840 return __gthread_mutex_lock (__mutex);
843 static inline int
844 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
846 return __gthread_mutex_trylock (__mutex);
849 #if _GTHREAD_USE_MUTEX_TIMEDLOCK
850 static inline int
851 __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *__mutex,
852 const __gthread_time_t *__abs_timeout)
854 return __gthread_mutex_timedlock (__mutex, __abs_timeout);
856 #endif
858 static inline int
859 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
861 return __gthread_mutex_unlock (__mutex);
864 #ifdef _GTHREAD_USE_COND_INIT_FUNC
865 static inline void
866 __gthread_cond_init_function (__gthread_cond_t *__cond)
868 if (__gthread_active_p ())
869 __gthrw_(pthread_cond_init) (__cond, NULL);
871 #endif
873 static inline int
874 __gthread_cond_broadcast (__gthread_cond_t *__cond)
876 return __gthrw_(pthread_cond_broadcast) (__cond);
879 static inline int
880 __gthread_cond_signal (__gthread_cond_t *__cond)
882 return __gthrw_(pthread_cond_signal) (__cond);
885 static inline int
886 __gthread_cond_wait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex)
888 return __gthrw_(pthread_cond_wait) (__cond, __mutex);
891 static inline int
892 __gthread_cond_timedwait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex,
893 const __gthread_time_t *__abs_timeout)
895 return __gthrw_(pthread_cond_timedwait) (__cond, __mutex, __abs_timeout);
898 static inline int
899 __gthread_cond_wait_recursive (__gthread_cond_t *__cond,
900 __gthread_recursive_mutex_t *__mutex)
902 return __gthread_cond_wait (__cond, __mutex);
905 static inline int
906 __gthread_cond_timedwait_recursive (__gthread_cond_t *__cond,
907 __gthread_recursive_mutex_t *__mutex,
908 const __gthread_time_t *__abs_timeout)
910 return __gthread_cond_timedwait (__cond, __mutex, __abs_timeout);
913 static inline int
914 __gthread_cond_destroy (__gthread_cond_t* __cond)
916 return __gthrw_(pthread_cond_destroy) (__cond);
919 #endif /* _LIBOBJC */
921 #endif /* ! GCC_GTHR_POSIX_H */