release.sh changes & fixes
[minix3.git] / external / gpl3 / gcc / lib / libstdc++-v3 / arch / vax / gthr-default.h
blobf03ee79a3de63d8dd79631d7b257dd69002003a7
1 /* This file is automatically generated. DO NOT EDIT! */
2 /* Generated from: NetBSD: mknative-gcc,v 1.58 2011/07/02 13:25:05 mrg Exp */
3 /* Generated from: NetBSD: mknative.common,v 1.9 2007/02/05 18:26:01 apb Exp */
5 /* Threads compatibility routines for libgcc2 and libobjc. */
6 /* Compile this one with gcc. */
7 /* Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
8 2008, 2009, 2011 Free Software Foundation, Inc.
10 This file is part of GCC.
12 GCC is free software; you can redistribute it and/or modify it under
13 the terms of the GNU General Public License as published by the Free
14 Software Foundation; either version 3, or (at your option) any later
15 version.
17 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
18 WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 for more details.
22 Under Section 7 of GPL version 3, you are granted additional
23 permissions described in the GCC Runtime Library Exception, version
24 3.1, as published by the Free Software Foundation.
26 You should have received a copy of the GNU General Public License and
27 a copy of the GCC Runtime Library Exception along with this program;
28 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
29 <http://www.gnu.org/licenses/>. */
31 #ifndef _GLIBCXX_GCC_GTHR_POSIX_H
32 #define _GLIBCXX_GCC_GTHR_POSIX_H
34 /* POSIX threads specific definitions.
35 Easy, since the interface is just one-to-one mapping. */
37 #define __GTHREADS 1
38 #define __GTHREADS_CXX0X 1
40 /* Some implementations of <pthread.h> require this to be defined. */
41 #if !defined(_REENTRANT) && defined(__osf__)
42 #define _REENTRANT 1
43 #endif
45 #include <pthread.h>
46 #include <unistd.h>
48 typedef pthread_t __gthread_t;
49 typedef pthread_key_t __gthread_key_t;
50 typedef pthread_once_t __gthread_once_t;
51 typedef pthread_mutex_t __gthread_mutex_t;
52 typedef pthread_mutex_t __gthread_recursive_mutex_t;
53 typedef pthread_cond_t __gthread_cond_t;
54 typedef struct timespec __gthread_time_t;
56 /* POSIX like conditional variables are supported. Please look at comments
57 in gthr.h for details. */
58 #define __GTHREAD_HAS_COND 1
60 #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
61 #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
62 #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
63 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
64 #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
65 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
66 #else
67 #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
68 #endif
69 #define __GTHREAD_COND_INIT PTHREAD_COND_INITIALIZER
70 #define __GTHREAD_TIME_INIT {0,0}
72 #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
73 # ifndef __gthrw_pragma
74 # define __gthrw_pragma(pragma)
75 # endif
76 # define __gthrw2(name,name2,type) \
77 static __typeof(type) name __attribute__ ((__weakref__(#name2))); \
78 __gthrw_pragma(weak type)
79 # define __gthrw_(name) __gthrw_ ## name
80 #else
81 # define __gthrw2(name,name2,type)
82 # define __gthrw_(name) name
83 #endif
85 /* Typically, __gthrw_foo is a weak reference to symbol foo. */
86 #define __gthrw(name) __gthrw2(__gthrw_ ## name,name,name)
88 /* On Tru64, /usr/include/pthread.h uses #pragma extern_prefix "__" to
89 map a subset of the POSIX pthread API to mangled versions of their
90 names. */
91 #if defined(__osf__) && defined(_PTHREAD_USE_MANGLED_NAMES_)
92 #define __gthrw3(name) __gthrw2(__gthrw_ ## name, __ ## name, name)
93 __gthrw3(pthread_once)
94 __gthrw3(pthread_getspecific)
95 __gthrw3(pthread_setspecific)
97 __gthrw3(pthread_create)
98 __gthrw3(pthread_join)
99 __gthrw3(pthread_detach)
100 __gthrw3(pthread_equal)
101 __gthrw3(pthread_self)
102 __gthrw3(pthread_cancel)
103 __gthrw3(sched_yield)
105 __gthrw3(pthread_mutex_lock)
106 __gthrw3(pthread_mutex_trylock)
107 #ifdef _POSIX_TIMEOUTS
108 #if _POSIX_TIMEOUTS >= 0
109 __gthrw3(pthread_mutex_timedlock)
110 #endif
111 #endif /* _POSIX_TIMEOUTS */
112 __gthrw3(pthread_mutex_unlock)
113 __gthrw3(pthread_mutex_init)
114 __gthrw3(pthread_mutex_destroy)
116 __gthrw3(pthread_cond_broadcast)
117 __gthrw3(pthread_cond_signal)
118 __gthrw3(pthread_cond_wait)
119 __gthrw3(pthread_cond_timedwait)
120 __gthrw3(pthread_cond_destroy)
121 #else
122 __gthrw(pthread_once)
123 __gthrw(pthread_getspecific)
124 __gthrw(pthread_setspecific)
126 __gthrw(pthread_create)
127 __gthrw(pthread_join)
128 __gthrw(pthread_equal)
129 __gthrw(pthread_self)
130 __gthrw(pthread_detach)
131 __gthrw(pthread_cancel)
132 __gthrw(sched_yield)
134 __gthrw(pthread_mutex_lock)
135 __gthrw(pthread_mutex_trylock)
136 #ifdef _POSIX_TIMEOUTS
137 #if _POSIX_TIMEOUTS >= 0
138 __gthrw(pthread_mutex_timedlock)
139 #endif
140 #endif /* _POSIX_TIMEOUTS */
141 __gthrw(pthread_mutex_unlock)
142 __gthrw(pthread_mutex_init)
143 __gthrw(pthread_mutex_destroy)
145 __gthrw(pthread_cond_broadcast)
146 __gthrw(pthread_cond_signal)
147 __gthrw(pthread_cond_wait)
148 __gthrw(pthread_cond_timedwait)
149 __gthrw(pthread_cond_destroy)
150 #endif
152 __gthrw(pthread_key_create)
153 __gthrw(pthread_key_delete)
154 __gthrw(pthread_mutexattr_init)
155 __gthrw(pthread_mutexattr_settype)
156 __gthrw(pthread_mutexattr_destroy)
159 #if defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)
160 /* Objective-C. */
161 #if defined(__osf__) && defined(_PTHREAD_USE_MANGLED_NAMES_)
162 __gthrw3(pthread_cond_init)
163 __gthrw3(pthread_exit)
164 #else
165 __gthrw(pthread_cond_init)
166 __gthrw(pthread_exit)
167 #endif /* __osf__ && _PTHREAD_USE_MANGLED_NAMES_ */
168 #ifdef _POSIX_PRIORITY_SCHEDULING
169 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
170 __gthrw(sched_get_priority_max)
171 __gthrw(sched_get_priority_min)
172 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
173 #endif /* _POSIX_PRIORITY_SCHEDULING */
174 __gthrw(pthread_attr_destroy)
175 __gthrw(pthread_attr_init)
176 __gthrw(pthread_attr_setdetachstate)
177 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
178 __gthrw(pthread_getschedparam)
179 __gthrw(pthread_setschedparam)
180 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
181 #endif /* _LIBOBJC || _LIBOBJC_WEAK */
183 #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
185 /* On Solaris 2.6 up to 9, the libc exposes a POSIX threads interface even if
186 -pthreads is not specified. The functions are dummies and most return an
187 error value. However pthread_once returns 0 without invoking the routine
188 it is passed so we cannot pretend that the interface is active if -pthreads
189 is not specified. On Solaris 2.5.1, the interface is not exposed at all so
190 we need to play the usual game with weak symbols. On Solaris 10 and up, a
191 working interface is always exposed. On FreeBSD 6 and later, libc also
192 exposes a dummy POSIX threads interface, similar to what Solaris 2.6 up
193 to 9 does. FreeBSD >= 700014 even provides a pthread_cancel stub in libc,
194 which means the alternate __gthread_active_p below cannot be used there. */
196 #if defined(__FreeBSD__) || (defined(__sun) && defined(__svr4__))
198 static volatile int __gthread_active = -1;
200 static void
201 __gthread_trigger (void)
203 __gthread_active = 1;
206 static inline int
207 __gthread_active_p (void)
209 static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
210 static pthread_once_t __gthread_active_once = PTHREAD_ONCE_INIT;
212 /* Avoid reading __gthread_active twice on the main code path. */
213 int __gthread_active_latest_value = __gthread_active;
215 /* This test is not protected to avoid taking a lock on the main code
216 path so every update of __gthread_active in a threaded program must
217 be atomic with regard to the result of the test. */
218 if (__builtin_expect (__gthread_active_latest_value < 0, 0))
220 if (__gthrw_(pthread_once))
222 /* If this really is a threaded program, then we must ensure that
223 __gthread_active has been set to 1 before exiting this block. */
224 __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex);
225 __gthrw_(pthread_once) (&__gthread_active_once, __gthread_trigger);
226 __gthrw_(pthread_mutex_unlock) (&__gthread_active_mutex);
229 /* Make sure we'll never enter this block again. */
230 if (__gthread_active < 0)
231 __gthread_active = 0;
233 __gthread_active_latest_value = __gthread_active;
236 return __gthread_active_latest_value != 0;
239 #else /* neither FreeBSD nor Solaris */
241 static inline int
242 __gthread_active_p (void)
244 static void *const __gthread_active_ptr
245 = __extension__ (void *) &__gthrw_(pthread_cancel);
246 return __gthread_active_ptr != 0;
249 #endif /* FreeBSD or Solaris */
251 #else /* not __GXX_WEAK__ */
253 /* Similar to Solaris, HP-UX 11 for PA-RISC provides stubs for pthread
254 calls in shared flavors of the HP-UX C library. Most of the stubs
255 have no functionality. The details are described in the "libc cumulative
256 patch" for each subversion of HP-UX 11. There are two special interfaces
257 provided for checking whether an application is linked to a shared pthread
258 library or not. However, these interfaces aren't available in early
259 libpthread libraries. We also need a test that works for archive
260 libraries. We can't use pthread_once as some libc versions call the
261 init function. We also can't use pthread_create or pthread_attr_init
262 as these create a thread and thereby prevent changing the default stack
263 size. The function pthread_default_stacksize_np is available in both
264 the archive and shared versions of libpthread. It can be used to
265 determine the default pthread stack size. There is a stub in some
266 shared libc versions which returns a zero size if pthreads are not
267 active. We provide an equivalent stub to handle cases where libc
268 doesn't provide one. */
270 #if defined(__hppa__) && defined(__hpux__)
272 static volatile int __gthread_active = -1;
274 static inline int
275 __gthread_active_p (void)
277 /* Avoid reading __gthread_active twice on the main code path. */
278 int __gthread_active_latest_value = __gthread_active;
279 size_t __s;
281 if (__builtin_expect (__gthread_active_latest_value < 0, 0))
283 pthread_default_stacksize_np (0, &__s);
284 __gthread_active = __s ? 1 : 0;
285 __gthread_active_latest_value = __gthread_active;
288 return __gthread_active_latest_value != 0;
291 #else /* not hppa-hpux */
293 static inline int
294 __gthread_active_p (void)
296 return 1;
299 #endif /* hppa-hpux */
301 #endif /* __GXX_WEAK__ */
303 #ifdef _LIBOBJC
305 /* This is the config.h file in libobjc/ */
306 #include <config.h>
308 #ifdef HAVE_SCHED_H
309 # include <sched.h>
310 #endif
312 /* Key structure for maintaining thread specific storage */
313 static pthread_key_t _objc_thread_storage;
314 static pthread_attr_t _objc_thread_attribs;
316 /* Thread local storage for a single thread */
317 static void *thread_local_storage = NULL;
319 /* Backend initialization functions */
321 /* Initialize the threads subsystem. */
322 static inline int
323 __gthread_objc_init_thread_system (void)
325 if (__gthread_active_p ())
327 /* Initialize the thread storage key. */
328 if (__gthrw_(pthread_key_create) (&_objc_thread_storage, NULL) == 0)
330 /* The normal default detach state for threads is
331 * PTHREAD_CREATE_JOINABLE which causes threads to not die
332 * when you think they should. */
333 if (__gthrw_(pthread_attr_init) (&_objc_thread_attribs) == 0
334 && __gthrw_(pthread_attr_setdetachstate) (&_objc_thread_attribs,
335 PTHREAD_CREATE_DETACHED) == 0)
336 return 0;
340 return -1;
343 /* Close the threads subsystem. */
344 static inline int
345 __gthread_objc_close_thread_system (void)
347 if (__gthread_active_p ()
348 && __gthrw_(pthread_key_delete) (_objc_thread_storage) == 0
349 && __gthrw_(pthread_attr_destroy) (&_objc_thread_attribs) == 0)
350 return 0;
352 return -1;
355 /* Backend thread functions */
357 /* Create a new thread of execution. */
358 static inline objc_thread_t
359 __gthread_objc_thread_detach (void (*func)(void *), void *arg)
361 objc_thread_t thread_id;
362 pthread_t new_thread_handle;
364 if (!__gthread_active_p ())
365 return NULL;
367 if (!(__gthrw_(pthread_create) (&new_thread_handle, NULL, (void *) func, arg)))
368 thread_id = (objc_thread_t) new_thread_handle;
369 else
370 thread_id = NULL;
372 return thread_id;
375 /* Set the current thread's priority. */
376 static inline int
377 __gthread_objc_thread_set_priority (int priority)
379 if (!__gthread_active_p ())
380 return -1;
381 else
383 #ifdef _POSIX_PRIORITY_SCHEDULING
384 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
385 pthread_t thread_id = __gthrw_(pthread_self) ();
386 int policy;
387 struct sched_param params;
388 int priority_min, priority_max;
390 if (__gthrw_(pthread_getschedparam) (thread_id, &policy, &params) == 0)
392 if ((priority_max = __gthrw_(sched_get_priority_max) (policy)) == -1)
393 return -1;
395 if ((priority_min = __gthrw_(sched_get_priority_min) (policy)) == -1)
396 return -1;
398 if (priority > priority_max)
399 priority = priority_max;
400 else if (priority < priority_min)
401 priority = priority_min;
402 params.sched_priority = priority;
405 * The solaris 7 and several other man pages incorrectly state that
406 * this should be a pointer to policy but pthread.h is universally
407 * at odds with this.
409 if (__gthrw_(pthread_setschedparam) (thread_id, policy, &params) == 0)
410 return 0;
412 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
413 #endif /* _POSIX_PRIORITY_SCHEDULING */
414 return -1;
418 /* Return the current thread's priority. */
419 static inline int
420 __gthread_objc_thread_get_priority (void)
422 #ifdef _POSIX_PRIORITY_SCHEDULING
423 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
424 if (__gthread_active_p ())
426 int policy;
427 struct sched_param params;
429 if (__gthrw_(pthread_getschedparam) (__gthrw_(pthread_self) (), &policy, &params) == 0)
430 return params.sched_priority;
431 else
432 return -1;
434 else
435 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
436 #endif /* _POSIX_PRIORITY_SCHEDULING */
437 return OBJC_THREAD_INTERACTIVE_PRIORITY;
440 /* Yield our process time to another thread. */
441 static inline void
442 __gthread_objc_thread_yield (void)
444 if (__gthread_active_p ())
445 __gthrw_(sched_yield) ();
448 /* Terminate the current thread. */
449 static inline int
450 __gthread_objc_thread_exit (void)
452 if (__gthread_active_p ())
453 /* exit the thread */
454 __gthrw_(pthread_exit) (&__objc_thread_exit_status);
456 /* Failed if we reached here */
457 return -1;
460 /* Returns an integer value which uniquely describes a thread. */
461 static inline objc_thread_t
462 __gthread_objc_thread_id (void)
464 if (__gthread_active_p ())
465 return (objc_thread_t) __gthrw_(pthread_self) ();
466 else
467 return (objc_thread_t) 1;
470 /* Sets the thread's local storage pointer. */
471 static inline int
472 __gthread_objc_thread_set_data (void *value)
474 if (__gthread_active_p ())
475 return __gthrw_(pthread_setspecific) (_objc_thread_storage, value);
476 else
478 thread_local_storage = value;
479 return 0;
483 /* Returns the thread's local storage pointer. */
484 static inline void *
485 __gthread_objc_thread_get_data (void)
487 if (__gthread_active_p ())
488 return __gthrw_(pthread_getspecific) (_objc_thread_storage);
489 else
490 return thread_local_storage;
493 /* Backend mutex functions */
495 /* Allocate a mutex. */
496 static inline int
497 __gthread_objc_mutex_allocate (objc_mutex_t mutex)
499 if (__gthread_active_p ())
501 mutex->backend = objc_malloc (sizeof (pthread_mutex_t));
503 if (__gthrw_(pthread_mutex_init) ((pthread_mutex_t *) mutex->backend, NULL))
505 objc_free (mutex->backend);
506 mutex->backend = NULL;
507 return -1;
511 return 0;
514 /* Deallocate a mutex. */
515 static inline int
516 __gthread_objc_mutex_deallocate (objc_mutex_t mutex)
518 if (__gthread_active_p ())
520 int count;
523 * Posix Threads specifically require that the thread be unlocked
524 * for __gthrw_(pthread_mutex_destroy) to work.
529 count = __gthrw_(pthread_mutex_unlock) ((pthread_mutex_t *) mutex->backend);
530 if (count < 0)
531 return -1;
533 while (count);
535 if (__gthrw_(pthread_mutex_destroy) ((pthread_mutex_t *) mutex->backend))
536 return -1;
538 objc_free (mutex->backend);
539 mutex->backend = NULL;
541 return 0;
544 /* Grab a lock on a mutex. */
545 static inline int
546 __gthread_objc_mutex_lock (objc_mutex_t mutex)
548 if (__gthread_active_p ()
549 && __gthrw_(pthread_mutex_lock) ((pthread_mutex_t *) mutex->backend) != 0)
551 return -1;
554 return 0;
557 /* Try to grab a lock on a mutex. */
558 static inline int
559 __gthread_objc_mutex_trylock (objc_mutex_t mutex)
561 if (__gthread_active_p ()
562 && __gthrw_(pthread_mutex_trylock) ((pthread_mutex_t *) mutex->backend) != 0)
564 return -1;
567 return 0;
570 /* Unlock the mutex */
571 static inline int
572 __gthread_objc_mutex_unlock (objc_mutex_t mutex)
574 if (__gthread_active_p ()
575 && __gthrw_(pthread_mutex_unlock) ((pthread_mutex_t *) mutex->backend) != 0)
577 return -1;
580 return 0;
583 /* Backend condition mutex functions */
585 /* Allocate a condition. */
586 static inline int
587 __gthread_objc_condition_allocate (objc_condition_t condition)
589 if (__gthread_active_p ())
591 condition->backend = objc_malloc (sizeof (pthread_cond_t));
593 if (__gthrw_(pthread_cond_init) ((pthread_cond_t *) condition->backend, NULL))
595 objc_free (condition->backend);
596 condition->backend = NULL;
597 return -1;
601 return 0;
604 /* Deallocate a condition. */
605 static inline int
606 __gthread_objc_condition_deallocate (objc_condition_t condition)
608 if (__gthread_active_p ())
610 if (__gthrw_(pthread_cond_destroy) ((pthread_cond_t *) condition->backend))
611 return -1;
613 objc_free (condition->backend);
614 condition->backend = NULL;
616 return 0;
619 /* Wait on the condition */
620 static inline int
621 __gthread_objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex)
623 if (__gthread_active_p ())
624 return __gthrw_(pthread_cond_wait) ((pthread_cond_t *) condition->backend,
625 (pthread_mutex_t *) mutex->backend);
626 else
627 return 0;
630 /* Wake up all threads waiting on this condition. */
631 static inline int
632 __gthread_objc_condition_broadcast (objc_condition_t condition)
634 if (__gthread_active_p ())
635 return __gthrw_(pthread_cond_broadcast) ((pthread_cond_t *) condition->backend);
636 else
637 return 0;
640 /* Wake up one thread waiting on this condition. */
641 static inline int
642 __gthread_objc_condition_signal (objc_condition_t condition)
644 if (__gthread_active_p ())
645 return __gthrw_(pthread_cond_signal) ((pthread_cond_t *) condition->backend);
646 else
647 return 0;
650 #else /* _LIBOBJC */
652 static inline int
653 __gthread_create (__gthread_t *__threadid, void *(*__func) (void*),
654 void *__args)
656 return __gthrw_(pthread_create) (__threadid, NULL, __func, __args);
659 static inline int
660 __gthread_join (__gthread_t __threadid, void **__value_ptr)
662 return __gthrw_(pthread_join) (__threadid, __value_ptr);
665 static inline int
666 __gthread_detach (__gthread_t __threadid)
668 return __gthrw_(pthread_detach) (__threadid);
671 static inline int
672 __gthread_equal (__gthread_t __t1, __gthread_t __t2)
674 return __gthrw_(pthread_equal) (__t1, __t2);
677 static inline __gthread_t
678 __gthread_self (void)
680 return __gthrw_(pthread_self) ();
683 static inline int
684 __gthread_yield (void)
686 return __gthrw_(sched_yield) ();
689 static inline int
690 __gthread_once (__gthread_once_t *__once, void (*__func) (void))
692 if (__gthread_active_p ())
693 return __gthrw_(pthread_once) (__once, __func);
694 else
695 return -1;
698 static inline int
699 __gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
701 return __gthrw_(pthread_key_create) (__key, __dtor);
704 static inline int
705 __gthread_key_delete (__gthread_key_t __key)
707 return __gthrw_(pthread_key_delete) (__key);
710 static inline void *
711 __gthread_getspecific (__gthread_key_t __key)
713 return __gthrw_(pthread_getspecific) (__key);
716 static inline int
717 __gthread_setspecific (__gthread_key_t __key, const void *__ptr)
719 return __gthrw_(pthread_setspecific) (__key, __ptr);
722 static inline int
723 __gthread_mutex_destroy (__gthread_mutex_t *__mutex)
725 if (__gthread_active_p ())
726 return __gthrw_(pthread_mutex_destroy) (__mutex);
727 else
728 return 0;
731 static inline int
732 __gthread_mutex_lock (__gthread_mutex_t *__mutex)
734 if (__gthread_active_p ())
735 return __gthrw_(pthread_mutex_lock) (__mutex);
736 else
737 return 0;
740 static inline int
741 __gthread_mutex_trylock (__gthread_mutex_t *__mutex)
743 if (__gthread_active_p ())
744 return __gthrw_(pthread_mutex_trylock) (__mutex);
745 else
746 return 0;
749 #ifdef _POSIX_TIMEOUTS
750 #if _POSIX_TIMEOUTS >= 0
751 static inline int
752 __gthread_mutex_timedlock (__gthread_mutex_t *__mutex,
753 const __gthread_time_t *__abs_timeout)
755 if (__gthread_active_p ())
756 return __gthrw_(pthread_mutex_timedlock) (__mutex, __abs_timeout);
757 else
758 return 0;
760 #endif
761 #endif
763 static inline int
764 __gthread_mutex_unlock (__gthread_mutex_t *__mutex)
766 if (__gthread_active_p ())
767 return __gthrw_(pthread_mutex_unlock) (__mutex);
768 else
769 return 0;
772 #ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
773 static inline int
774 __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
776 if (__gthread_active_p ())
778 pthread_mutexattr_t __attr;
779 int __r;
781 __r = __gthrw_(pthread_mutexattr_init) (&__attr);
782 if (!__r)
783 __r = __gthrw_(pthread_mutexattr_settype) (&__attr,
784 PTHREAD_MUTEX_RECURSIVE);
785 if (!__r)
786 __r = __gthrw_(pthread_mutex_init) (__mutex, &__attr);
787 if (!__r)
788 __r = __gthrw_(pthread_mutexattr_destroy) (&__attr);
789 return __r;
791 return 0;
793 #endif
795 static inline int
796 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
798 return __gthread_mutex_lock (__mutex);
801 static inline int
802 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
804 return __gthread_mutex_trylock (__mutex);
807 #ifdef _POSIX_TIMEOUTS
808 #if _POSIX_TIMEOUTS >= 0
809 static inline int
810 __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *__mutex,
811 const __gthread_time_t *__abs_timeout)
813 return __gthread_mutex_timedlock (__mutex, __abs_timeout);
815 #endif
816 #endif
818 static inline int
819 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
821 return __gthread_mutex_unlock (__mutex);
824 static inline int
825 __gthread_cond_broadcast (__gthread_cond_t *__cond)
827 return __gthrw_(pthread_cond_broadcast) (__cond);
830 static inline int
831 __gthread_cond_signal (__gthread_cond_t *__cond)
833 return __gthrw_(pthread_cond_signal) (__cond);
836 static inline int
837 __gthread_cond_wait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex)
839 return __gthrw_(pthread_cond_wait) (__cond, __mutex);
842 static inline int
843 __gthread_cond_timedwait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex,
844 const __gthread_time_t *__abs_timeout)
846 return __gthrw_(pthread_cond_timedwait) (__cond, __mutex, __abs_timeout);
849 static inline int
850 __gthread_cond_wait_recursive (__gthread_cond_t *__cond,
851 __gthread_recursive_mutex_t *__mutex)
853 return __gthread_cond_wait (__cond, __mutex);
856 static inline int
857 __gthread_cond_timedwait_recursive (__gthread_cond_t *__cond,
858 __gthread_recursive_mutex_t *__mutex,
859 const __gthread_time_t *__abs_timeout)
861 return __gthread_cond_timedwait (__cond, __mutex, __abs_timeout);
864 static inline int
865 __gthread_cond_destroy (__gthread_cond_t* __cond)
867 return __gthrw_(pthread_cond_destroy) (__cond);
870 #endif /* _LIBOBJC */
872 #endif /* ! _GLIBCXX_GCC_GTHR_POSIX_H */