110d565efSmrg /* Threads compatibility routines for libgcc2 and libobjc. */
210d565efSmrg /* Compile this one with gcc. */
3*ec02198aSmrg /* Copyright (C) 1997-2020 Free Software Foundation, Inc.
410d565efSmrg
510d565efSmrg This file is part of GCC.
610d565efSmrg
710d565efSmrg GCC is free software; you can redistribute it and/or modify it under
810d565efSmrg the terms of the GNU General Public License as published by the Free
910d565efSmrg Software Foundation; either version 3, or (at your option) any later
1010d565efSmrg version.
1110d565efSmrg
1210d565efSmrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
1310d565efSmrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
1410d565efSmrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1510d565efSmrg for more details.
1610d565efSmrg
1710d565efSmrg Under Section 7 of GPL version 3, you are granted additional
1810d565efSmrg permissions described in the GCC Runtime Library Exception, version
1910d565efSmrg 3.1, as published by the Free Software Foundation.
2010d565efSmrg
2110d565efSmrg You should have received a copy of the GNU General Public License and
2210d565efSmrg a copy of the GCC Runtime Library Exception along with this program;
2310d565efSmrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
2410d565efSmrg <http://www.gnu.org/licenses/>. */
2510d565efSmrg
2610d565efSmrg #ifndef GCC_GTHR_DCE_H
2710d565efSmrg #define GCC_GTHR_DCE_H
2810d565efSmrg
2910d565efSmrg /* If _DCE_THREADS is not defined, then we're building the single
3010d565efSmrg threaded version of the libraries and do not want to reference
3110d565efSmrg anything related to pthreads or dce. */
3210d565efSmrg #ifndef _DCE_THREADS
3310d565efSmrg #include "gthr-single.h"
3410d565efSmrg #else
3510d565efSmrg /* DCE threads interface.
3610d565efSmrg DCE threads are based on POSIX threads draft 4, and many things
3710d565efSmrg have changed since then. */
3810d565efSmrg
3910d565efSmrg /* Make sure CONST_CAST2 (original in system.h) is defined. */
4010d565efSmrg #ifndef CONST_CAST2
4110d565efSmrg #ifdef __cplusplus
4210d565efSmrg #define CONST_CAST2(TOTYPE,FROMTYPE,X) (const_cast<TOTYPE> (X))
4310d565efSmrg #else
4410d565efSmrg #define CONST_CAST2(TOTYPE,FROMTYPE,X) ((__extension__(union {FROMTYPE _q; TOTYPE _nq;})(X))._nq)
4510d565efSmrg #endif
4610d565efSmrg #endif
4710d565efSmrg
4810d565efSmrg #define __GTHREADS 1
4910d565efSmrg
5010d565efSmrg #include <pthread.h>
5110d565efSmrg
5210d565efSmrg typedef pthread_key_t __gthread_key_t;
5310d565efSmrg typedef pthread_once_t __gthread_once_t;
5410d565efSmrg typedef pthread_mutex_t __gthread_mutex_t;
5510d565efSmrg typedef pthread_mutex_t __gthread_recursive_mutex_t;
5610d565efSmrg
5710d565efSmrg #define __GTHREAD_ONCE_INIT pthread_once_init
5810d565efSmrg
5910d565efSmrg #define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
6010d565efSmrg #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
6110d565efSmrg
6210d565efSmrg #define __GTHREAD_MUTEX_INIT_DEFAULT pthread_once_init
6310d565efSmrg
6410d565efSmrg #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
6510d565efSmrg # define __gthrw(name) \
6610d565efSmrg static __typeof(name) __gthrw_ ## name __attribute__ ((__weakref__(#name)));
6710d565efSmrg # define __gthrw_(name) __gthrw_ ## name
6810d565efSmrg #else
6910d565efSmrg # define __gthrw(name)
7010d565efSmrg # define __gthrw_(name) name
7110d565efSmrg #endif
7210d565efSmrg
7310d565efSmrg __gthrw(pthread_once)
__gthrw(pthread_keycreate)7410d565efSmrg __gthrw(pthread_keycreate)
7510d565efSmrg __gthrw(pthread_getspecific)
7610d565efSmrg __gthrw(pthread_setspecific)
7710d565efSmrg __gthrw(pthread_create)
7810d565efSmrg __gthrw(pthread_mutex_init)
7910d565efSmrg __gthrw(pthread_mutex_destroy)
8010d565efSmrg __gthrw(pthread_mutex_lock)
8110d565efSmrg __gthrw(pthread_mutex_trylock)
8210d565efSmrg __gthrw(pthread_mutex_unlock)
8310d565efSmrg __gthrw(pthread_mutexattr_create)
8410d565efSmrg __gthrw(pthread_mutexattr_setkind_np)
8510d565efSmrg __gthrw(pthread_mutexattr_delete)
8610d565efSmrg
8710d565efSmrg #ifdef _LIBOBJC
8810d565efSmrg /* Objective-C. */
8910d565efSmrg __gthrw(pthread_cond_broadcast)
9010d565efSmrg __gthrw(pthread_cond_destroy)
9110d565efSmrg __gthrw(pthread_cond_init)
9210d565efSmrg __gthrw(pthread_cond_signal)
9310d565efSmrg __gthrw(pthread_cond_wait)
9410d565efSmrg __gthrw(pthread_exit)
9510d565efSmrg
9610d565efSmrg #ifdef pthread_getunique_np
9710d565efSmrg # define __gthrw_pthread_getunique_np pthread_getunique_np
9810d565efSmrg #else
9910d565efSmrg __gthrw(pthread_getunique_np)
10010d565efSmrg # define __gthrw_pthread_getunique_np __gthrw_(pthread_getunique_np)
10110d565efSmrg #endif
10210d565efSmrg
10310d565efSmrg __gthrw(pthread_mutex_destroy)
10410d565efSmrg __gthrw(pthread_self)
10510d565efSmrg __gthrw(pthread_yield)
10610d565efSmrg #endif
10710d565efSmrg
10810d565efSmrg #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
10910d565efSmrg
11010d565efSmrg static inline int
11110d565efSmrg __gthread_active_p (void)
11210d565efSmrg {
11310d565efSmrg static void *const __gthread_active_ptr = (void *) &__gthrw_(pthread_create);
11410d565efSmrg return __gthread_active_ptr != 0;
11510d565efSmrg }
11610d565efSmrg
11710d565efSmrg #else /* not SUPPORTS_WEAK */
11810d565efSmrg
11910d565efSmrg static inline int
12010d565efSmrg __gthread_active_p (void)
12110d565efSmrg {
12210d565efSmrg return 1;
12310d565efSmrg }
12410d565efSmrg
12510d565efSmrg #endif /* SUPPORTS_WEAK */
12610d565efSmrg
12710d565efSmrg #ifdef _LIBOBJC
12810d565efSmrg
12910d565efSmrg /* Key structure for maintaining thread specific storage */
13010d565efSmrg static pthread_key_t _objc_thread_storage;
13110d565efSmrg
13210d565efSmrg /* Thread local storage for a single thread */
13310d565efSmrg static void *thread_local_storage = NULL;
13410d565efSmrg
13510d565efSmrg /* Backend initialization functions */
13610d565efSmrg
13710d565efSmrg /* Initialize the threads subsystem. */
13810d565efSmrg static inline int
__gthread_objc_init_thread_system(void)13910d565efSmrg __gthread_objc_init_thread_system (void)
14010d565efSmrg {
14110d565efSmrg if (__gthread_active_p ())
14210d565efSmrg /* Initialize the thread storage key. */
14310d565efSmrg return __gthrw_(pthread_keycreate) (&_objc_thread_storage, NULL);
14410d565efSmrg else
14510d565efSmrg return -1;
14610d565efSmrg }
14710d565efSmrg
14810d565efSmrg /* Close the threads subsystem. */
14910d565efSmrg static inline int
__gthread_objc_close_thread_system(void)15010d565efSmrg __gthread_objc_close_thread_system (void)
15110d565efSmrg {
15210d565efSmrg if (__gthread_active_p ())
15310d565efSmrg return 0;
15410d565efSmrg else
15510d565efSmrg return -1;
15610d565efSmrg }
15710d565efSmrg
15810d565efSmrg /* Backend thread functions */
15910d565efSmrg
16010d565efSmrg /* Create a new thread of execution. */
16110d565efSmrg static inline objc_thread_t
__gthread_objc_thread_detach(void (* func)(void *),void * arg)16210d565efSmrg __gthread_objc_thread_detach (void (*func)(void *), void *arg)
16310d565efSmrg {
16410d565efSmrg objc_thread_t thread_id;
16510d565efSmrg pthread_t new_thread_handle;
16610d565efSmrg
16710d565efSmrg if (!__gthread_active_p ())
16810d565efSmrg return NULL;
16910d565efSmrg
17010d565efSmrg if (!(__gthrw_(pthread_create) (&new_thread_handle, pthread_attr_default,
17110d565efSmrg (void *) func, arg)))
17210d565efSmrg {
17310d565efSmrg /* ??? May not work! (64bit) */
17410d565efSmrg thread_id = *(objc_thread_t *) &new_thread_handle;
17510d565efSmrg pthread_detach (&new_thread_handle); /* Fully detach thread. */
17610d565efSmrg }
17710d565efSmrg else
17810d565efSmrg thread_id = NULL;
17910d565efSmrg
18010d565efSmrg return thread_id;
18110d565efSmrg }
18210d565efSmrg
18310d565efSmrg /* Set the current thread's priority. */
18410d565efSmrg static inline int
__gthread_objc_thread_set_priority(int priority)18510d565efSmrg __gthread_objc_thread_set_priority (int priority)
18610d565efSmrg {
18710d565efSmrg int sys_priority = 0;
18810d565efSmrg
18910d565efSmrg if (!__gthread_active_p ())
19010d565efSmrg return -1;
19110d565efSmrg
19210d565efSmrg switch (priority)
19310d565efSmrg {
19410d565efSmrg case OBJC_THREAD_INTERACTIVE_PRIORITY:
19510d565efSmrg sys_priority = (PRI_FG_MIN_NP + PRI_FG_MAX_NP) / 2;
19610d565efSmrg break;
19710d565efSmrg default:
19810d565efSmrg case OBJC_THREAD_BACKGROUND_PRIORITY:
19910d565efSmrg sys_priority = (PRI_BG_MIN_NP + PRI_BG_MAX_NP) / 2;
20010d565efSmrg break;
20110d565efSmrg case OBJC_THREAD_LOW_PRIORITY:
20210d565efSmrg sys_priority = (PRI_BG_MIN_NP + PRI_BG_MAX_NP) / 2;
20310d565efSmrg break;
20410d565efSmrg }
20510d565efSmrg
20610d565efSmrg /* Change the priority. */
20710d565efSmrg if (pthread_setprio (__gthrw_(pthread_self) (), sys_priority) >= 0)
20810d565efSmrg return 0;
20910d565efSmrg else
21010d565efSmrg /* Failed */
21110d565efSmrg return -1;
21210d565efSmrg }
21310d565efSmrg
21410d565efSmrg /* Return the current thread's priority. */
21510d565efSmrg static inline int
__gthread_objc_thread_get_priority(void)21610d565efSmrg __gthread_objc_thread_get_priority (void)
21710d565efSmrg {
21810d565efSmrg int sys_priority;
21910d565efSmrg
22010d565efSmrg if (__gthread_active_p ())
22110d565efSmrg {
22210d565efSmrg if ((sys_priority = pthread_getprio (__gthrw_(pthread_self) ())) >= 0)
22310d565efSmrg {
22410d565efSmrg if (sys_priority >= PRI_FG_MIN_NP
22510d565efSmrg && sys_priority <= PRI_FG_MAX_NP)
22610d565efSmrg return OBJC_THREAD_INTERACTIVE_PRIORITY;
22710d565efSmrg if (sys_priority >= PRI_BG_MIN_NP
22810d565efSmrg && sys_priority <= PRI_BG_MAX_NP)
22910d565efSmrg return OBJC_THREAD_BACKGROUND_PRIORITY;
23010d565efSmrg return OBJC_THREAD_LOW_PRIORITY;
23110d565efSmrg }
23210d565efSmrg
23310d565efSmrg /* Failed */
23410d565efSmrg return -1;
23510d565efSmrg }
23610d565efSmrg else
23710d565efSmrg return OBJC_THREAD_INTERACTIVE_PRIORITY;
23810d565efSmrg }
23910d565efSmrg
24010d565efSmrg /* Yield our process time to another thread. */
24110d565efSmrg static inline void
__gthread_objc_thread_yield(void)24210d565efSmrg __gthread_objc_thread_yield (void)
24310d565efSmrg {
24410d565efSmrg if (__gthread_active_p ())
24510d565efSmrg __gthrw_(pthread_yield) ();
24610d565efSmrg }
24710d565efSmrg
24810d565efSmrg /* Terminate the current thread. */
24910d565efSmrg static inline int
__gthread_objc_thread_exit(void)25010d565efSmrg __gthread_objc_thread_exit (void)
25110d565efSmrg {
25210d565efSmrg if (__gthread_active_p ())
25310d565efSmrg /* exit the thread */
25410d565efSmrg __gthrw_(pthread_exit) (&__objc_thread_exit_status);
25510d565efSmrg
25610d565efSmrg /* Failed if we reached here */
25710d565efSmrg return -1;
25810d565efSmrg }
25910d565efSmrg
26010d565efSmrg /* Returns an integer value which uniquely describes a thread. */
26110d565efSmrg static inline objc_thread_t
__gthread_objc_thread_id(void)26210d565efSmrg __gthread_objc_thread_id (void)
26310d565efSmrg {
26410d565efSmrg if (__gthread_active_p ())
26510d565efSmrg {
26610d565efSmrg pthread_t self = __gthrw_(pthread_self) ();
26710d565efSmrg
26810d565efSmrg return (objc_thread_t) __gthrw_pthread_getunique_np (&self);
26910d565efSmrg }
27010d565efSmrg else
27110d565efSmrg return (objc_thread_t) 1;
27210d565efSmrg }
27310d565efSmrg
27410d565efSmrg /* Sets the thread's local storage pointer. */
27510d565efSmrg static inline int
__gthread_objc_thread_set_data(void * value)27610d565efSmrg __gthread_objc_thread_set_data (void *value)
27710d565efSmrg {
27810d565efSmrg if (__gthread_active_p ())
27910d565efSmrg return __gthrw_(pthread_setspecific) (_objc_thread_storage, value);
28010d565efSmrg else
28110d565efSmrg {
28210d565efSmrg thread_local_storage = value;
28310d565efSmrg return 0;
28410d565efSmrg }
28510d565efSmrg }
28610d565efSmrg
28710d565efSmrg /* Returns the thread's local storage pointer. */
28810d565efSmrg static inline void *
__gthread_objc_thread_get_data(void)28910d565efSmrg __gthread_objc_thread_get_data (void)
29010d565efSmrg {
29110d565efSmrg void *value = NULL;
29210d565efSmrg
29310d565efSmrg if (__gthread_active_p ())
29410d565efSmrg {
29510d565efSmrg if (!(__gthrw_(pthread_getspecific) (_objc_thread_storage, &value)))
29610d565efSmrg return value;
29710d565efSmrg
29810d565efSmrg return NULL;
29910d565efSmrg }
30010d565efSmrg else
30110d565efSmrg return thread_local_storage;
30210d565efSmrg }
30310d565efSmrg
30410d565efSmrg /* Backend mutex functions */
30510d565efSmrg
30610d565efSmrg /* Allocate a mutex. */
30710d565efSmrg static inline int
__gthread_objc_mutex_allocate(objc_mutex_t mutex)30810d565efSmrg __gthread_objc_mutex_allocate (objc_mutex_t mutex)
30910d565efSmrg {
31010d565efSmrg if (__gthread_active_p ())
31110d565efSmrg {
31210d565efSmrg mutex->backend = objc_malloc (sizeof (pthread_mutex_t));
31310d565efSmrg
31410d565efSmrg if (__gthrw_(pthread_mutex_init) ((pthread_mutex_t *) mutex->backend,
31510d565efSmrg pthread_mutexattr_default))
31610d565efSmrg {
31710d565efSmrg objc_free (mutex->backend);
31810d565efSmrg mutex->backend = NULL;
31910d565efSmrg return -1;
32010d565efSmrg }
32110d565efSmrg }
32210d565efSmrg
32310d565efSmrg return 0;
32410d565efSmrg }
32510d565efSmrg
32610d565efSmrg /* Deallocate a mutex. */
32710d565efSmrg static inline int
__gthread_objc_mutex_deallocate(objc_mutex_t mutex)32810d565efSmrg __gthread_objc_mutex_deallocate (objc_mutex_t mutex)
32910d565efSmrg {
33010d565efSmrg if (__gthread_active_p ())
33110d565efSmrg {
33210d565efSmrg if (__gthrw_(pthread_mutex_destroy) ((pthread_mutex_t *) mutex->backend))
33310d565efSmrg return -1;
33410d565efSmrg
33510d565efSmrg objc_free (mutex->backend);
33610d565efSmrg mutex->backend = NULL;
33710d565efSmrg }
33810d565efSmrg
33910d565efSmrg return 0;
34010d565efSmrg }
34110d565efSmrg
34210d565efSmrg /* Grab a lock on a mutex. */
34310d565efSmrg static inline int
__gthread_objc_mutex_lock(objc_mutex_t mutex)34410d565efSmrg __gthread_objc_mutex_lock (objc_mutex_t mutex)
34510d565efSmrg {
34610d565efSmrg if (__gthread_active_p ())
34710d565efSmrg return __gthrw_(pthread_mutex_lock) ((pthread_mutex_t *) mutex->backend);
34810d565efSmrg else
34910d565efSmrg return 0;
35010d565efSmrg }
35110d565efSmrg
35210d565efSmrg /* Try to grab a lock on a mutex. */
35310d565efSmrg static inline int
__gthread_objc_mutex_trylock(objc_mutex_t mutex)35410d565efSmrg __gthread_objc_mutex_trylock (objc_mutex_t mutex)
35510d565efSmrg {
35610d565efSmrg if (__gthread_active_p ()
35710d565efSmrg && __gthrw_(pthread_mutex_trylock) ((pthread_mutex_t *) mutex->backend) != 1)
35810d565efSmrg return -1;
35910d565efSmrg
36010d565efSmrg return 0;
36110d565efSmrg }
36210d565efSmrg
36310d565efSmrg /* Unlock the mutex */
36410d565efSmrg static inline int
__gthread_objc_mutex_unlock(objc_mutex_t mutex)36510d565efSmrg __gthread_objc_mutex_unlock (objc_mutex_t mutex)
36610d565efSmrg {
36710d565efSmrg if (__gthread_active_p ())
36810d565efSmrg return __gthrw_(pthread_mutex_unlock) ((pthread_mutex_t *) mutex->backend);
36910d565efSmrg else
37010d565efSmrg return 0;
37110d565efSmrg }
37210d565efSmrg
37310d565efSmrg /* Backend condition mutex functions */
37410d565efSmrg
37510d565efSmrg /* Allocate a condition. */
37610d565efSmrg static inline int
__gthread_objc_condition_allocate(objc_condition_t condition)37710d565efSmrg __gthread_objc_condition_allocate (objc_condition_t condition
37810d565efSmrg __attribute__ ((__unused__)))
37910d565efSmrg {
38010d565efSmrg if (__gthread_active_p ())
38110d565efSmrg /* Unimplemented. */
38210d565efSmrg return -1;
38310d565efSmrg else
38410d565efSmrg return 0;
38510d565efSmrg }
38610d565efSmrg
38710d565efSmrg /* Deallocate a condition. */
38810d565efSmrg static inline int
__gthread_objc_condition_deallocate(objc_condition_t condition)38910d565efSmrg __gthread_objc_condition_deallocate (objc_condition_t condition
39010d565efSmrg __attribute__ ((__unused__)))
39110d565efSmrg {
39210d565efSmrg if (__gthread_active_p ())
39310d565efSmrg /* Unimplemented. */
39410d565efSmrg return -1;
39510d565efSmrg else
39610d565efSmrg return 0;
39710d565efSmrg }
39810d565efSmrg
39910d565efSmrg /* Wait on the condition */
40010d565efSmrg static inline int
__gthread_objc_condition_wait(objc_condition_t condition,objc_mutex_t mutex)40110d565efSmrg __gthread_objc_condition_wait (objc_condition_t condition
40210d565efSmrg __attribute__ ((__unused__)),
40310d565efSmrg objc_mutex_t mutex __attribute__ ((__unused__)))
40410d565efSmrg {
40510d565efSmrg if (__gthread_active_p ())
40610d565efSmrg /* Unimplemented. */
40710d565efSmrg return -1;
40810d565efSmrg else
40910d565efSmrg return 0;
41010d565efSmrg }
41110d565efSmrg
41210d565efSmrg /* Wake up all threads waiting on this condition. */
41310d565efSmrg static inline int
__gthread_objc_condition_broadcast(objc_condition_t condition)41410d565efSmrg __gthread_objc_condition_broadcast (objc_condition_t condition
41510d565efSmrg __attribute__ ((__unused__)))
41610d565efSmrg {
41710d565efSmrg if (__gthread_active_p ())
41810d565efSmrg /* Unimplemented. */
41910d565efSmrg return -1;
42010d565efSmrg else
42110d565efSmrg return 0;
42210d565efSmrg }
42310d565efSmrg
42410d565efSmrg /* Wake up one thread waiting on this condition. */
42510d565efSmrg static inline int
__gthread_objc_condition_signal(objc_condition_t condition)42610d565efSmrg __gthread_objc_condition_signal (objc_condition_t condition
42710d565efSmrg __attribute__ ((__unused__)))
42810d565efSmrg {
42910d565efSmrg if (__gthread_active_p ())
43010d565efSmrg /* Unimplemented. */
43110d565efSmrg return -1;
43210d565efSmrg else
43310d565efSmrg return 0;
43410d565efSmrg }
43510d565efSmrg
43610d565efSmrg #else /* _LIBOBJC */
43710d565efSmrg
43810d565efSmrg static inline int
__gthread_once(__gthread_once_t * __once,void (* __func)(void))43910d565efSmrg __gthread_once (__gthread_once_t *__once, void (*__func) (void))
44010d565efSmrg {
44110d565efSmrg if (__gthread_active_p ())
44210d565efSmrg return __gthrw_(pthread_once) (__once, __func);
44310d565efSmrg else
44410d565efSmrg return -1;
44510d565efSmrg }
44610d565efSmrg
44710d565efSmrg static inline int
__gthread_key_create(__gthread_key_t * __key,void (* __dtor)(void *))44810d565efSmrg __gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
44910d565efSmrg {
45010d565efSmrg return __gthrw_(pthread_keycreate) (__key, __dtor);
45110d565efSmrg }
45210d565efSmrg
45310d565efSmrg static inline int
__gthread_key_delete(__gthread_key_t __key)45410d565efSmrg __gthread_key_delete (__gthread_key_t __key __attribute__ ((__unused__)))
45510d565efSmrg {
45610d565efSmrg /* Operation is not supported. */
45710d565efSmrg return -1;
45810d565efSmrg }
45910d565efSmrg
46010d565efSmrg static inline void *
__gthread_getspecific(__gthread_key_t __key)46110d565efSmrg __gthread_getspecific (__gthread_key_t __key)
46210d565efSmrg {
46310d565efSmrg void *__ptr;
46410d565efSmrg if (__gthrw_(pthread_getspecific) (__key, &__ptr) == 0)
46510d565efSmrg return __ptr;
46610d565efSmrg else
46710d565efSmrg return 0;
46810d565efSmrg }
46910d565efSmrg
47010d565efSmrg static inline int
__gthread_setspecific(__gthread_key_t __key,const void * __ptr)47110d565efSmrg __gthread_setspecific (__gthread_key_t __key, const void *__ptr)
47210d565efSmrg {
47310d565efSmrg return __gthrw_(pthread_setspecific)
47410d565efSmrg (__key, CONST_CAST2(void *, const void *, __ptr));
47510d565efSmrg }
47610d565efSmrg
47710d565efSmrg static inline void
__gthread_mutex_init_function(__gthread_mutex_t * __mutex)47810d565efSmrg __gthread_mutex_init_function (__gthread_mutex_t *__mutex)
47910d565efSmrg {
48010d565efSmrg if (__gthread_active_p ())
48110d565efSmrg __gthrw_(pthread_mutex_init) (__mutex, pthread_mutexattr_default);
48210d565efSmrg }
48310d565efSmrg
48410d565efSmrg static inline int
__gthread_mutex_destroy(__gthread_mutex_t * __mutex)48510d565efSmrg __gthread_mutex_destroy (__gthread_mutex_t *__mutex)
48610d565efSmrg {
48710d565efSmrg if (__gthread_active_p ())
48810d565efSmrg return __gthrw_(pthread_mutex_destroy) (__mutex);
48910d565efSmrg else
49010d565efSmrg return 0;
49110d565efSmrg }
49210d565efSmrg
49310d565efSmrg static inline int
__gthread_mutex_lock(__gthread_mutex_t * __mutex)49410d565efSmrg __gthread_mutex_lock (__gthread_mutex_t *__mutex)
49510d565efSmrg {
49610d565efSmrg if (__gthread_active_p ())
49710d565efSmrg return __gthrw_(pthread_mutex_lock) (__mutex);
49810d565efSmrg else
49910d565efSmrg return 0;
50010d565efSmrg }
50110d565efSmrg
50210d565efSmrg static inline int
__gthread_mutex_trylock(__gthread_mutex_t * __mutex)50310d565efSmrg __gthread_mutex_trylock (__gthread_mutex_t *__mutex)
50410d565efSmrg {
50510d565efSmrg if (__gthread_active_p ())
50610d565efSmrg return __gthrw_(pthread_mutex_trylock) (__mutex);
50710d565efSmrg else
50810d565efSmrg return 0;
50910d565efSmrg }
51010d565efSmrg
51110d565efSmrg static inline int
__gthread_mutex_unlock(__gthread_mutex_t * __mutex)51210d565efSmrg __gthread_mutex_unlock (__gthread_mutex_t *__mutex)
51310d565efSmrg {
51410d565efSmrg if (__gthread_active_p ())
51510d565efSmrg return __gthrw_(pthread_mutex_unlock) (__mutex);
51610d565efSmrg else
51710d565efSmrg return 0;
51810d565efSmrg }
51910d565efSmrg
52010d565efSmrg static inline int
__gthread_recursive_mutex_init_function(__gthread_recursive_mutex_t * __mutex)52110d565efSmrg __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
52210d565efSmrg {
52310d565efSmrg if (__gthread_active_p ())
52410d565efSmrg {
52510d565efSmrg pthread_mutexattr_t __attr;
52610d565efSmrg int __r;
52710d565efSmrg
52810d565efSmrg __r = __gthrw_(pthread_mutexattr_create) (&__attr);
52910d565efSmrg if (!__r)
53010d565efSmrg __r = __gthrw_(pthread_mutexattr_setkind_np) (&__attr,
53110d565efSmrg MUTEX_RECURSIVE_NP);
53210d565efSmrg if (!__r)
53310d565efSmrg __r = __gthrw_(pthread_mutex_init) (__mutex, __attr);
53410d565efSmrg if (!__r)
53510d565efSmrg __r = __gthrw_(pthread_mutexattr_delete) (&__attr);
53610d565efSmrg return __r;
53710d565efSmrg }
53810d565efSmrg return 0;
53910d565efSmrg }
54010d565efSmrg
54110d565efSmrg static inline int
__gthread_recursive_mutex_lock(__gthread_recursive_mutex_t * __mutex)54210d565efSmrg __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
54310d565efSmrg {
54410d565efSmrg return __gthread_mutex_lock (__mutex);
54510d565efSmrg }
54610d565efSmrg
54710d565efSmrg static inline int
__gthread_recursive_mutex_trylock(__gthread_recursive_mutex_t * __mutex)54810d565efSmrg __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
54910d565efSmrg {
55010d565efSmrg return __gthread_mutex_trylock (__mutex);
55110d565efSmrg }
55210d565efSmrg
55310d565efSmrg static inline int
__gthread_recursive_mutex_unlock(__gthread_recursive_mutex_t * __mutex)55410d565efSmrg __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
55510d565efSmrg {
55610d565efSmrg return __gthread_mutex_unlock (__mutex);
55710d565efSmrg }
55810d565efSmrg
55910d565efSmrg static inline int
__gthread_recursive_mutex_destroy(__gthread_recursive_mutex_t * __mutex)56010d565efSmrg __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex)
56110d565efSmrg {
56210d565efSmrg return __gthread_mutex_destroy (__mutex);
56310d565efSmrg }
56410d565efSmrg
56510d565efSmrg #endif /* _LIBOBJC */
56610d565efSmrg
56710d565efSmrg #endif
56810d565efSmrg #endif /* ! GCC_GTHR_DCE_H */
569