OSDN Git Service

Add missing ChangeLog entries.
[pf3gnuchains/gcc-fork.git] / gcc / 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
38 /* Some implementations of <pthread.h> require this to be defined.  */
39 #if !defined(_REENTRANT) && defined(__osf__)
40 #define _REENTRANT 1
41 #endif
42
43 #include <pthread.h>
44 #include <unistd.h>
45
46 typedef pthread_key_t __gthread_key_t;
47 typedef pthread_once_t __gthread_once_t;
48 typedef pthread_mutex_t __gthread_mutex_t;
49 typedef pthread_mutex_t __gthread_recursive_mutex_t;
50 typedef pthread_cond_t __gthread_cond_t;
51
52 /* POSIX like conditional variables are supported.  Please look at comments
53    in gthr.h for details. */
54 #define __GTHREAD_HAS_COND      1       
55
56 #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
57 #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
58 #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
59 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
60 #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
61 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
62 #else
63 #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
64 #endif
65 #define __GTHREAD_COND_INIT PTHREAD_COND_INITIALIZER
66
67 #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
68 # ifndef __gthrw_pragma
69 #  define __gthrw_pragma(pragma)
70 # endif
71 # define __gthrw2(name,name2,type) \
72   static __typeof(type) name __attribute__ ((__weakref__(#name2))); \
73   __gthrw_pragma(weak type)
74 # define __gthrw_(name) __gthrw_ ## name
75 #else
76 # define __gthrw2(name,name2,type)
77 # define __gthrw_(name) name
78 #endif
79
80 /* Typically, __gthrw_foo is a weak reference to symbol foo.  */
81 #define __gthrw(name) __gthrw2(__gthrw_ ## name,name,name)
82
83 /* On Tru64, /usr/include/pthread.h uses #pragma extern_prefix "__" to
84    map a subset of the POSIX pthread API to mangled versions of their
85    names.  */
86 #if defined(__osf__) && defined(_PTHREAD_USE_MANGLED_NAMES_)
87 #define __gthrw3(name) __gthrw2(__gthrw_ ## name, __ ## name, name)
88 __gthrw3(pthread_once)
89 __gthrw3(pthread_getspecific)
90 __gthrw3(pthread_setspecific)
91 __gthrw3(pthread_create)
92 __gthrw3(pthread_cancel)
93 __gthrw3(pthread_mutex_lock)
94 __gthrw3(pthread_mutex_trylock)
95 __gthrw3(pthread_mutex_unlock)
96 __gthrw3(pthread_mutex_init)
97 __gthrw3(pthread_cond_broadcast)
98 __gthrw3(pthread_cond_wait)
99 #else
100 __gthrw(pthread_once)
101 __gthrw(pthread_getspecific)
102 __gthrw(pthread_setspecific)
103 __gthrw(pthread_create)
104 __gthrw(pthread_cancel)
105 __gthrw(pthread_mutex_lock)
106 __gthrw(pthread_mutex_trylock)
107 __gthrw(pthread_mutex_unlock)
108 __gthrw(pthread_mutex_init)
109 __gthrw(pthread_cond_broadcast)
110 __gthrw(pthread_cond_wait)
111 #endif
112
113 __gthrw(pthread_key_create)
114 __gthrw(pthread_key_delete)
115 __gthrw(pthread_mutexattr_init)
116 __gthrw(pthread_mutexattr_settype)
117 __gthrw(pthread_mutexattr_destroy)
118
119
120 #if defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)
121 /* Objective-C.  */
122 #if defined(__osf__) && defined(_PTHREAD_USE_MANGLED_NAMES_)
123 __gthrw3(pthread_cond_destroy)
124 __gthrw3(pthread_cond_init)
125 __gthrw3(pthread_cond_signal)
126 __gthrw3(pthread_exit)
127 __gthrw3(pthread_mutex_destroy)
128 __gthrw3(pthread_self)
129 #else
130 __gthrw(pthread_cond_destroy)
131 __gthrw(pthread_cond_init)
132 __gthrw(pthread_cond_signal)
133 __gthrw(pthread_exit)
134 __gthrw(pthread_mutex_destroy)
135 __gthrw(pthread_self)
136 #endif /* __osf__ && _PTHREAD_USE_MANGLED_NAMES_ */
137 #ifdef _POSIX_PRIORITY_SCHEDULING
138 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
139 __gthrw(sched_get_priority_max)
140 __gthrw(sched_get_priority_min)
141 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
142 #endif /* _POSIX_PRIORITY_SCHEDULING */
143 __gthrw(sched_yield)
144 __gthrw(pthread_attr_destroy)
145 __gthrw(pthread_attr_init)
146 __gthrw(pthread_attr_setdetachstate)
147 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
148 __gthrw(pthread_getschedparam)
149 __gthrw(pthread_setschedparam)
150 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
151 #endif /* _LIBOBJC || _LIBOBJC_WEAK */
152
153 #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
154
155 /* On Solaris 2.6 up to 9, the libc exposes a POSIX threads interface even if
156    -pthreads is not specified.  The functions are dummies and most return an
157    error value.  However pthread_once returns 0 without invoking the routine
158    it is passed so we cannot pretend that the interface is active if -pthreads
159    is not specified.  On Solaris 2.5.1, the interface is not exposed at all so
160    we need to play the usual game with weak symbols.  On Solaris 10 and up, a
161    working interface is always exposed.  */
162
163 #if defined(__sun) && defined(__svr4__)
164
165 static volatile int __gthread_active = -1;
166
167 static void
168 __gthread_trigger (void)
169 {
170   __gthread_active = 1;
171 }
172
173 static inline int
174 __gthread_active_p (void)
175 {
176   static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
177   static pthread_once_t __gthread_active_once = PTHREAD_ONCE_INIT;
178
179   /* Avoid reading __gthread_active twice on the main code path.  */
180   int __gthread_active_latest_value = __gthread_active;
181
182   /* This test is not protected to avoid taking a lock on the main code
183      path so every update of __gthread_active in a threaded program must
184      be atomic with regard to the result of the test.  */
185   if (__builtin_expect (__gthread_active_latest_value < 0, 0))
186     {
187       if (__gthrw_(pthread_once))
188         {
189           /* If this really is a threaded program, then we must ensure that
190              __gthread_active has been set to 1 before exiting this block.  */
191           __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex);
192           __gthrw_(pthread_once) (&__gthread_active_once, __gthread_trigger);
193           __gthrw_(pthread_mutex_unlock) (&__gthread_active_mutex);
194         }
195
196       /* Make sure we'll never enter this block again.  */
197       if (__gthread_active < 0)
198         __gthread_active = 0;
199
200       __gthread_active_latest_value = __gthread_active;
201     }
202
203   return __gthread_active_latest_value != 0;
204 }
205
206 #else /* not Solaris */
207
208 static inline int
209 __gthread_active_p (void)
210 {
211   static void *const __gthread_active_ptr 
212     = __extension__ (void *) &__gthrw_(pthread_cancel);
213   return __gthread_active_ptr != 0;
214 }
215
216 #endif /* Solaris */
217
218 #else /* not SUPPORTS_WEAK */
219
220 /* Similar to Solaris, HP-UX 11 for PA-RISC provides stubs for pthread
221    calls in shared flavors of the HP-UX C library.  Most of the stubs
222    have no functionality.  The details are described in the "libc cumulative
223    patch" for each subversion of HP-UX 11.  There are two special interfaces
224    provided for checking whether an application is linked to a pthread
225    library or not.  However, these interfaces aren't available in early
226    libc versions.  We also can't use pthread_once as some libc versions
227    call the init function.  So, we use pthread_create to check whether it
228    is possible to create a thread or not.  The stub implementation returns
229    the error number ENOSYS.  */
230
231 #if defined(__hppa__) && defined(__hpux__)
232
233 #include <errno.h>
234
235 static volatile int __gthread_active = -1;
236
237 static void *
238 __gthread_start (void *arg __attribute__((unused)))
239 {
240   return NULL;
241 }
242
243 static void __gthread_active_init (void) __attribute__((noinline));
244 static void
245 __gthread_active_init (void)
246 {
247   static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
248   pthread_t t;
249   pthread_attr_t a;
250   int result;
251
252   __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex);
253   if (__gthread_active < 0)
254     {
255       __gthrw_(pthread_attr_init) (&a);
256       __gthrw_(pthread_attr_setdetachstate) (&a, PTHREAD_CREATE_DETACHED);
257       result = __gthrw_(pthread_create) (&t, &a, __gthread_start, NULL);
258       if (result != ENOSYS)
259         __gthread_active = 1;
260       else
261         __gthread_active = 0;
262       __gthrw_(pthread_attr_destroy) (&a);
263     }
264   __gthrw_(pthread_mutex_unlock) (&__gthread_active_mutex);
265 }
266
267 static inline int
268 __gthread_active_p (void)
269 {
270   /* Avoid reading __gthread_active twice on the main code path.  */
271   int __gthread_active_latest_value = __gthread_active;
272
273   /* This test is not protected to avoid taking a lock on the main code
274      path so every update of __gthread_active in a threaded program must
275      be atomic with regard to the result of the test.  */
276   if (__builtin_expect (__gthread_active_latest_value < 0, 0))
277     {
278       __gthread_active_init ();
279       __gthread_active_latest_value = __gthread_active;
280     }
281
282   return __gthread_active_latest_value != 0;
283 }
284
285 #else /* not hppa-hpux */
286
287 static inline int
288 __gthread_active_p (void)
289 {
290   return 1;
291 }
292
293 #endif /* hppa-hpux */
294
295 #endif /* SUPPORTS_WEAK */
296
297 #ifdef _LIBOBJC
298
299 /* This is the config.h file in libobjc/ */
300 #include <config.h>
301
302 #ifdef HAVE_SCHED_H
303 # include <sched.h>
304 #endif
305
306 /* Key structure for maintaining thread specific storage */
307 static pthread_key_t _objc_thread_storage;
308 static pthread_attr_t _objc_thread_attribs;
309
310 /* Thread local storage for a single thread */
311 static void *thread_local_storage = NULL;
312
313 /* Backend initialization functions */
314
315 /* Initialize the threads subsystem.  */
316 static inline int
317 __gthread_objc_init_thread_system (void)
318 {
319   if (__gthread_active_p ())
320     {
321       /* Initialize the thread storage key.  */
322       if (__gthrw_(pthread_key_create) (&_objc_thread_storage, NULL) == 0)
323         {
324           /* The normal default detach state for threads is
325            * PTHREAD_CREATE_JOINABLE which causes threads to not die
326            * when you think they should.  */
327           if (__gthrw_(pthread_attr_init) (&_objc_thread_attribs) == 0
328               && __gthrw_(pthread_attr_setdetachstate) (&_objc_thread_attribs,
329                                               PTHREAD_CREATE_DETACHED) == 0)
330             return 0;
331         }
332     }
333
334   return -1;
335 }
336
337 /* Close the threads subsystem.  */
338 static inline int
339 __gthread_objc_close_thread_system (void)
340 {
341   if (__gthread_active_p ()
342       && __gthrw_(pthread_key_delete) (_objc_thread_storage) == 0
343       && __gthrw_(pthread_attr_destroy) (&_objc_thread_attribs) == 0)
344     return 0;
345
346   return -1;
347 }
348
349 /* Backend thread functions */
350
351 /* Create a new thread of execution.  */
352 static inline objc_thread_t
353 __gthread_objc_thread_detach (void (*func)(void *), void *arg)
354 {
355   objc_thread_t thread_id;
356   pthread_t new_thread_handle;
357
358   if (!__gthread_active_p ())
359     return NULL;
360
361   if (!(__gthrw_(pthread_create) (&new_thread_handle, NULL, (void *) func, arg)))
362     thread_id = (objc_thread_t) new_thread_handle;
363   else
364     thread_id = NULL;
365
366   return thread_id;
367 }
368
369 /* Set the current thread's priority.  */
370 static inline int
371 __gthread_objc_thread_set_priority (int priority)
372 {
373   if (!__gthread_active_p ())
374     return -1;
375   else
376     {
377 #ifdef _POSIX_PRIORITY_SCHEDULING
378 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
379       pthread_t thread_id = __gthrw_(pthread_self) ();
380       int policy;
381       struct sched_param params;
382       int priority_min, priority_max;
383
384       if (__gthrw_(pthread_getschedparam) (thread_id, &policy, &params) == 0)
385         {
386           if ((priority_max = __gthrw_(sched_get_priority_max) (policy)) == -1)
387             return -1;
388
389           if ((priority_min = __gthrw_(sched_get_priority_min) (policy)) == -1)
390             return -1;
391
392           if (priority > priority_max)
393             priority = priority_max;
394           else if (priority < priority_min)
395             priority = priority_min;
396           params.sched_priority = priority;
397
398           /*
399            * The solaris 7 and several other man pages incorrectly state that
400            * this should be a pointer to policy but pthread.h is universally
401            * at odds with this.
402            */
403           if (__gthrw_(pthread_setschedparam) (thread_id, policy, &params) == 0)
404             return 0;
405         }
406 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
407 #endif /* _POSIX_PRIORITY_SCHEDULING */
408       return -1;
409     }
410 }
411
412 /* Return the current thread's priority.  */
413 static inline int
414 __gthread_objc_thread_get_priority (void)
415 {
416 #ifdef _POSIX_PRIORITY_SCHEDULING
417 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
418   if (__gthread_active_p ())
419     {
420       int policy;
421       struct sched_param params;
422
423       if (__gthrw_(pthread_getschedparam) (__gthrw_(pthread_self) (), &policy, &params) == 0)
424         return params.sched_priority;
425       else
426         return -1;
427     }
428   else
429 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
430 #endif /* _POSIX_PRIORITY_SCHEDULING */
431     return OBJC_THREAD_INTERACTIVE_PRIORITY;
432 }
433
434 /* Yield our process time to another thread.  */
435 static inline void
436 __gthread_objc_thread_yield (void)
437 {
438   if (__gthread_active_p ())
439     __gthrw_(sched_yield) ();
440 }
441
442 /* Terminate the current thread.  */
443 static inline int
444 __gthread_objc_thread_exit (void)
445 {
446   if (__gthread_active_p ())
447     /* exit the thread */
448     __gthrw_(pthread_exit) (&__objc_thread_exit_status);
449
450   /* Failed if we reached here */
451   return -1;
452 }
453
454 /* Returns an integer value which uniquely describes a thread.  */
455 static inline objc_thread_t
456 __gthread_objc_thread_id (void)
457 {
458   if (__gthread_active_p ())
459     return (objc_thread_t) __gthrw_(pthread_self) ();
460   else
461     return (objc_thread_t) 1;
462 }
463
464 /* Sets the thread's local storage pointer.  */
465 static inline int
466 __gthread_objc_thread_set_data (void *value)
467 {
468   if (__gthread_active_p ())
469     return __gthrw_(pthread_setspecific) (_objc_thread_storage, value);
470   else
471     {
472       thread_local_storage = value;
473       return 0;
474     }
475 }
476
477 /* Returns the thread's local storage pointer.  */
478 static inline void *
479 __gthread_objc_thread_get_data (void)
480 {
481   if (__gthread_active_p ())
482     return __gthrw_(pthread_getspecific) (_objc_thread_storage);
483   else
484     return thread_local_storage;
485 }
486
487 /* Backend mutex functions */
488
489 /* Allocate a mutex.  */
490 static inline int
491 __gthread_objc_mutex_allocate (objc_mutex_t mutex)
492 {
493   if (__gthread_active_p ())
494     {
495       mutex->backend = objc_malloc (sizeof (pthread_mutex_t));
496
497       if (__gthrw_(pthread_mutex_init) ((pthread_mutex_t *) mutex->backend, NULL))
498         {
499           objc_free (mutex->backend);
500           mutex->backend = NULL;
501           return -1;
502         }
503     }
504
505   return 0;
506 }
507
508 /* Deallocate a mutex.  */
509 static inline int
510 __gthread_objc_mutex_deallocate (objc_mutex_t mutex)
511 {
512   if (__gthread_active_p ())
513     {
514       int count;
515
516       /*
517        * Posix Threads specifically require that the thread be unlocked
518        * for __gthrw_(pthread_mutex_destroy) to work.
519        */
520
521       do
522         {
523           count = __gthrw_(pthread_mutex_unlock) ((pthread_mutex_t *) mutex->backend);
524           if (count < 0)
525             return -1;
526         }
527       while (count);
528
529       if (__gthrw_(pthread_mutex_destroy) ((pthread_mutex_t *) mutex->backend))
530         return -1;
531
532       objc_free (mutex->backend);
533       mutex->backend = NULL;
534     }
535   return 0;
536 }
537
538 /* Grab a lock on a mutex.  */
539 static inline int
540 __gthread_objc_mutex_lock (objc_mutex_t mutex)
541 {
542   if (__gthread_active_p ()
543       && __gthrw_(pthread_mutex_lock) ((pthread_mutex_t *) mutex->backend) != 0)
544     {
545       return -1;
546     }
547
548   return 0;
549 }
550
551 /* Try to grab a lock on a mutex.  */
552 static inline int
553 __gthread_objc_mutex_trylock (objc_mutex_t mutex)
554 {
555   if (__gthread_active_p ()
556       && __gthrw_(pthread_mutex_trylock) ((pthread_mutex_t *) mutex->backend) != 0)
557     {
558       return -1;
559     }
560
561   return 0;
562 }
563
564 /* Unlock the mutex */
565 static inline int
566 __gthread_objc_mutex_unlock (objc_mutex_t mutex)
567 {
568   if (__gthread_active_p ()
569       && __gthrw_(pthread_mutex_unlock) ((pthread_mutex_t *) mutex->backend) != 0)
570     {
571       return -1;
572     }
573
574   return 0;
575 }
576
577 /* Backend condition mutex functions */
578
579 /* Allocate a condition.  */
580 static inline int
581 __gthread_objc_condition_allocate (objc_condition_t condition)
582 {
583   if (__gthread_active_p ())
584     {
585       condition->backend = objc_malloc (sizeof (pthread_cond_t));
586
587       if (__gthrw_(pthread_cond_init) ((pthread_cond_t *) condition->backend, NULL))
588         {
589           objc_free (condition->backend);
590           condition->backend = NULL;
591           return -1;
592         }
593     }
594
595   return 0;
596 }
597
598 /* Deallocate a condition.  */
599 static inline int
600 __gthread_objc_condition_deallocate (objc_condition_t condition)
601 {
602   if (__gthread_active_p ())
603     {
604       if (__gthrw_(pthread_cond_destroy) ((pthread_cond_t *) condition->backend))
605         return -1;
606
607       objc_free (condition->backend);
608       condition->backend = NULL;
609     }
610   return 0;
611 }
612
613 /* Wait on the condition */
614 static inline int
615 __gthread_objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex)
616 {
617   if (__gthread_active_p ())
618     return __gthrw_(pthread_cond_wait) ((pthread_cond_t *) condition->backend,
619                               (pthread_mutex_t *) mutex->backend);
620   else
621     return 0;
622 }
623
624 /* Wake up all threads waiting on this condition.  */
625 static inline int
626 __gthread_objc_condition_broadcast (objc_condition_t condition)
627 {
628   if (__gthread_active_p ())
629     return __gthrw_(pthread_cond_broadcast) ((pthread_cond_t *) condition->backend);
630   else
631     return 0;
632 }
633
634 /* Wake up one thread waiting on this condition.  */
635 static inline int
636 __gthread_objc_condition_signal (objc_condition_t condition)
637 {
638   if (__gthread_active_p ())
639     return __gthrw_(pthread_cond_signal) ((pthread_cond_t *) condition->backend);
640   else
641     return 0;
642 }
643
644 #else /* _LIBOBJC */
645
646 static inline int
647 __gthread_once (__gthread_once_t *once, void (*func) (void))
648 {
649   if (__gthread_active_p ())
650     return __gthrw_(pthread_once) (once, func);
651   else
652     return -1;
653 }
654
655 static inline int
656 __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
657 {
658   return __gthrw_(pthread_key_create) (key, dtor);
659 }
660
661 static inline int
662 __gthread_key_delete (__gthread_key_t key)
663 {
664   return __gthrw_(pthread_key_delete) (key);
665 }
666
667 static inline void *
668 __gthread_getspecific (__gthread_key_t key)
669 {
670   return __gthrw_(pthread_getspecific) (key);
671 }
672
673 static inline int
674 __gthread_setspecific (__gthread_key_t key, const void *ptr)
675 {
676   return __gthrw_(pthread_setspecific) (key, ptr);
677 }
678
679 static inline int
680 __gthread_mutex_lock (__gthread_mutex_t *mutex)
681 {
682   if (__gthread_active_p ())
683     return __gthrw_(pthread_mutex_lock) (mutex);
684   else
685     return 0;
686 }
687
688 static inline int
689 __gthread_mutex_trylock (__gthread_mutex_t *mutex)
690 {
691   if (__gthread_active_p ())
692     return __gthrw_(pthread_mutex_trylock) (mutex);
693   else
694     return 0;
695 }
696
697 static inline int
698 __gthread_mutex_unlock (__gthread_mutex_t *mutex)
699 {
700   if (__gthread_active_p ())
701     return __gthrw_(pthread_mutex_unlock) (mutex);
702   else
703     return 0;
704 }
705
706 #ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
707 static inline int
708 __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *mutex)
709 {
710   if (__gthread_active_p ())
711     {
712       pthread_mutexattr_t attr;
713       int r;
714
715       r = __gthrw_(pthread_mutexattr_init) (&attr);
716       if (!r)
717         r = __gthrw_(pthread_mutexattr_settype) (&attr, PTHREAD_MUTEX_RECURSIVE);
718       if (!r)
719         r = __gthrw_(pthread_mutex_init) (mutex, &attr);
720       if (!r)
721         r = __gthrw_(pthread_mutexattr_destroy) (&attr);
722       return r;
723     }
724   return 0;
725 }
726 #endif
727
728 static inline int
729 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex)
730 {
731   return __gthread_mutex_lock (mutex);
732 }
733
734 static inline int
735 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex)
736 {
737   return __gthread_mutex_trylock (mutex);
738 }
739
740 static inline int
741 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
742 {
743   return __gthread_mutex_unlock (mutex);
744 }
745
746 static inline int
747 __gthread_cond_broadcast (__gthread_cond_t *cond)
748 {
749   return __gthrw_(pthread_cond_broadcast) (cond);
750 }
751
752 static inline int
753 __gthread_cond_wait (__gthread_cond_t *cond, __gthread_mutex_t *mutex)
754 {
755   return __gthrw_(pthread_cond_wait) (cond, mutex);
756 }
757
758 static inline int
759 __gthread_cond_wait_recursive (__gthread_cond_t *cond,
760                                __gthread_recursive_mutex_t *mutex)
761 {
762   return __gthread_cond_wait (cond, mutex);
763 }
764
765 #endif /* _LIBOBJC */
766
767 #endif /* ! GCC_GTHR_POSIX_H */