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