gthr-posix.h

00001 /* Threads compatibility routines for libgcc2 and libobjc.  */
00002 /* Compile this one with gcc.  */
00003 /* Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
00004    2008, 2009 Free Software Foundation, Inc.
00005 
00006 This file is part of GCC.
00007 
00008 GCC is free software; you can redistribute it and/or modify it under
00009 the terms of the GNU General Public License as published by the Free
00010 Software Foundation; either version 3, or (at your option) any later
00011 version.
00012 
00013 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
00014 WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 Under Section 7 of GPL version 3, you are granted additional
00019 permissions described in the GCC Runtime Library Exception, version
00020 3.1, as published by the Free Software Foundation.
00021 
00022 You should have received a copy of the GNU General Public License and
00023 a copy of the GCC Runtime Library Exception along with this program;
00024 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00025 <http://www.gnu.org/licenses/>.  */
00026 
00027 #ifndef _GLIBCXX_GCC_GTHR_POSIX_H
00028 #define _GLIBCXX_GCC_GTHR_POSIX_H
00029 
00030 /* POSIX threads specific definitions.
00031    Easy, since the interface is just one-to-one mapping.  */
00032 
00033 #define __GTHREADS 1
00034 #define __GTHREADS_CXX0X 1
00035 
00036 /* Some implementations of <pthread.h> require this to be defined.  */
00037 #if !defined(_REENTRANT) && defined(__osf__)
00038 #define _REENTRANT 1
00039 #endif
00040 
00041 #include <pthread.h>
00042 #include <unistd.h>
00043 
00044 typedef pthread_t __gthread_t;
00045 typedef pthread_key_t __gthread_key_t;
00046 typedef pthread_once_t __gthread_once_t;
00047 typedef pthread_mutex_t __gthread_mutex_t;
00048 typedef pthread_mutex_t __gthread_recursive_mutex_t;
00049 typedef pthread_cond_t __gthread_cond_t;
00050 typedef struct timespec __gthread_time_t;
00051 
00052 /* POSIX like conditional variables are supported.  Please look at comments
00053    in gthr.h for details. */
00054 #define __GTHREAD_HAS_COND  1   
00055 
00056 #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
00057 #define __GTHREAD_MUTEX_INIT_FUNCTION2 __gthread_mutex_init_function2
00058 #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
00059 #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
00060 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
00061 #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
00062 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
00063 #else
00064 #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
00065 #endif
00066 #define __GTHREAD_COND_INIT PTHREAD_COND_INITIALIZER
00067 #define __GTHREAD_TIME_INIT {0,0}
00068 
00069 #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
00070 # ifndef __gthrw_pragma
00071 #  define __gthrw_pragma(pragma)
00072 # endif
00073 # define __gthrw2(name,name2,type) \
00074   static __typeof(type) name __attribute__ ((__weakref__(#name2))); \
00075   __gthrw_pragma(weak type)
00076 # define __gthrw_(name) __gthrw_ ## name
00077 #else
00078 # define __gthrw2(name,name2,type)
00079 # define __gthrw_(name) name
00080 #endif
00081 
00082 /* Typically, __gthrw_foo is a weak reference to symbol foo.  */
00083 #define __gthrw(name) __gthrw2(__gthrw_ ## name,name,name)
00084 
00085 /* On Tru64, /usr/include/pthread.h uses #pragma extern_prefix "__" to
00086    map a subset of the POSIX pthread API to mangled versions of their
00087    names.  */
00088 #if defined(__osf__) && defined(_PTHREAD_USE_MANGLED_NAMES_)
00089 #define __gthrw3(name) __gthrw2(__gthrw_ ## name, __ ## name, name)
00090 __gthrw3(pthread_once)
00091 __gthrw3(pthread_getspecific)
00092 __gthrw3(pthread_setspecific)
00093 
00094 __gthrw3(pthread_create)
00095 __gthrw3(pthread_join)
00096 __gthrw3(pthread_detach)
00097 __gthrw3(pthread_equal)
00098 __gthrw3(pthread_self)
00099 __gthrw3(pthread_cancel)
00100 __gthrw3(sched_yield)
00101 
00102 __gthrw3(pthread_mutex_lock)
00103 __gthrw3(pthread_mutex_trylock)
00104 #ifdef _POSIX_TIMEOUTS
00105 #if _POSIX_TIMEOUTS >= 0
00106 __gthrw3(pthread_mutex_timedlock)
00107 #endif
00108 #endif /* _POSIX_TIMEOUTS */
00109 __gthrw3(pthread_mutex_unlock)
00110 __gthrw3(pthread_mutex_init)
00111 __gthrw3(pthread_mutex_destroy)
00112 
00113 __gthrw3(pthread_cond_broadcast)
00114 __gthrw3(pthread_cond_signal)
00115 __gthrw3(pthread_cond_wait)
00116 __gthrw3(pthread_cond_timedwait)
00117 __gthrw3(pthread_cond_destroy)
00118 #else
00119 __gthrw(pthread_once)
00120 __gthrw(pthread_getspecific)
00121 __gthrw(pthread_setspecific)
00122 
00123 __gthrw(pthread_create)
00124 __gthrw(pthread_join)
00125 __gthrw(pthread_equal)
00126 __gthrw(pthread_self)
00127 __gthrw(pthread_detach)
00128 __gthrw(pthread_cancel)
00129 __gthrw(sched_yield)
00130 
00131 __gthrw(pthread_mutex_lock)
00132 __gthrw(pthread_mutex_trylock)
00133 #ifdef _POSIX_TIMEOUTS
00134 #if _POSIX_TIMEOUTS >= 0
00135 __gthrw(pthread_mutex_timedlock)
00136 #endif
00137 #endif /* _POSIX_TIMEOUTS */
00138 __gthrw(pthread_mutex_unlock)
00139 __gthrw(pthread_mutex_init)
00140 __gthrw(pthread_mutex_destroy)
00141 
00142 __gthrw(pthread_cond_broadcast)
00143 __gthrw(pthread_cond_signal)
00144 __gthrw(pthread_cond_wait)
00145 __gthrw(pthread_cond_timedwait)
00146 __gthrw(pthread_cond_destroy)
00147 #endif
00148 
00149 __gthrw(pthread_key_create)
00150 __gthrw(pthread_key_delete)
00151 __gthrw(pthread_mutexattr_init)
00152 __gthrw(pthread_mutexattr_settype)
00153 __gthrw(pthread_mutexattr_destroy)
00154 
00155 
00156 #if defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)
00157 /* Objective-C.  */
00158 #if defined(__osf__) && defined(_PTHREAD_USE_MANGLED_NAMES_)
00159 __gthrw3(pthread_cond_init)
00160 __gthrw3(pthread_exit)
00161 #else
00162 __gthrw(pthread_cond_init)
00163 __gthrw(pthread_exit)
00164 #endif /* __osf__ && _PTHREAD_USE_MANGLED_NAMES_ */
00165 #ifdef _POSIX_PRIORITY_SCHEDULING
00166 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
00167 __gthrw(sched_get_priority_max)
00168 __gthrw(sched_get_priority_min)
00169 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
00170 #endif /* _POSIX_PRIORITY_SCHEDULING */
00171 __gthrw(pthread_attr_destroy)
00172 __gthrw(pthread_attr_init)
00173 __gthrw(pthread_attr_setdetachstate)
00174 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
00175 __gthrw(pthread_getschedparam)
00176 __gthrw(pthread_setschedparam)
00177 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
00178 #endif /* _LIBOBJC || _LIBOBJC_WEAK */
00179 
00180 #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
00181 
00182 /* On Solaris 2.6 up to 9, the libc exposes a POSIX threads interface even if
00183    -pthreads is not specified.  The functions are dummies and most return an
00184    error value.  However pthread_once returns 0 without invoking the routine
00185    it is passed so we cannot pretend that the interface is active if -pthreads
00186    is not specified.  On Solaris 2.5.1, the interface is not exposed at all so
00187    we need to play the usual game with weak symbols.  On Solaris 10 and up, a
00188    working interface is always exposed.  On FreeBSD 6 and later, libc also
00189    exposes a dummy POSIX threads interface, similar to what Solaris 2.6 up
00190    to 9 does.  FreeBSD >= 700014 even provides a pthread_cancel stub in libc,
00191    which means the alternate __gthread_active_p below cannot be used there.  */
00192 
00193 #if defined(__FreeBSD__) || (defined(__sun) && defined(__svr4__))
00194 
00195 static volatile int __gthread_active = -1;
00196 
00197 static void
00198 __gthread_trigger (void)
00199 {
00200   __gthread_active = 1;
00201 }
00202 
00203 static inline int
00204 __gthread_active_p (void)
00205 {
00206   static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
00207   static pthread_once_t __gthread_active_once = PTHREAD_ONCE_INIT;
00208 
00209   /* Avoid reading __gthread_active twice on the main code path.  */
00210   int __gthread_active_latest_value = __gthread_active;
00211 
00212   /* This test is not protected to avoid taking a lock on the main code
00213      path so every update of __gthread_active in a threaded program must
00214      be atomic with regard to the result of the test.  */
00215   if (__builtin_expect (__gthread_active_latest_value < 0, 0))
00216     {
00217       if (__gthrw_(pthread_once))
00218     {
00219       /* If this really is a threaded program, then we must ensure that
00220          __gthread_active has been set to 1 before exiting this block.  */
00221       __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex);
00222       __gthrw_(pthread_once) (&__gthread_active_once, __gthread_trigger);
00223       __gthrw_(pthread_mutex_unlock) (&__gthread_active_mutex);
00224     }
00225 
00226       /* Make sure we'll never enter this block again.  */
00227       if (__gthread_active < 0)
00228     __gthread_active = 0;
00229 
00230       __gthread_active_latest_value = __gthread_active;
00231     }
00232 
00233   return __gthread_active_latest_value != 0;
00234 }
00235 
00236 #else /* neither FreeBSD nor Solaris */
00237 
00238 static inline int
00239 __gthread_active_p (void)
00240 {
00241   static void *const __gthread_active_ptr 
00242     = __extension__ (void *) &__gthrw_(pthread_cancel);
00243   return __gthread_active_ptr != 0;
00244 }
00245 
00246 #endif /* FreeBSD or Solaris */
00247 
00248 #else /* not __GXX_WEAK__ */
00249 
00250 /* Similar to Solaris, HP-UX 11 for PA-RISC provides stubs for pthread
00251    calls in shared flavors of the HP-UX C library.  Most of the stubs
00252    have no functionality.  The details are described in the "libc cumulative
00253    patch" for each subversion of HP-UX 11.  There are two special interfaces
00254    provided for checking whether an application is linked to a shared pthread
00255    library or not.  However, these interfaces aren't available in early
00256    libpthread libraries.  We also need a test that works for archive
00257    libraries.  We can't use pthread_once as some libc versions call the
00258    init function.  We also can't use pthread_create or pthread_attr_init
00259    as these create a thread and thereby prevent changing the default stack
00260    size.  The function pthread_default_stacksize_np is available in both
00261    the archive and shared versions of libpthread.   It can be used to
00262    determine the default pthread stack size.  There is a stub in some
00263    shared libc versions which returns a zero size if pthreads are not
00264    active.  We provide an equivalent stub to handle cases where libc
00265    doesn't provide one.  */
00266 
00267 #if defined(__hppa__) && defined(__hpux__)
00268 
00269 static volatile int __gthread_active = -1;
00270 
00271 static inline int
00272 __gthread_active_p (void)
00273 {
00274   /* Avoid reading __gthread_active twice on the main code path.  */
00275   int __gthread_active_latest_value = __gthread_active;
00276   size_t __s;
00277 
00278   if (__builtin_expect (__gthread_active_latest_value < 0, 0))
00279     {
00280       pthread_default_stacksize_np (0, &__s);
00281       __gthread_active = __s ? 1 : 0;
00282       __gthread_active_latest_value = __gthread_active;
00283     }
00284 
00285   return __gthread_active_latest_value != 0;
00286 }
00287 
00288 #else /* not hppa-hpux */
00289 
00290 static inline int
00291 __gthread_active_p (void)
00292 {
00293   return 1;
00294 }
00295 
00296 #endif /* hppa-hpux */
00297 
00298 #endif /* __GXX_WEAK__ */
00299 
00300 #ifdef _LIBOBJC
00301 
00302 /* This is the config.h file in libobjc/ */
00303 #include <config.h>
00304 
00305 #ifdef HAVE_SCHED_H
00306 # include <sched.h>
00307 #endif
00308 
00309 /* Key structure for maintaining thread specific storage */
00310 static pthread_key_t _objc_thread_storage;
00311 static pthread_attr_t _objc_thread_attribs;
00312 
00313 /* Thread local storage for a single thread */
00314 static void *thread_local_storage = NULL;
00315 
00316 /* Backend initialization functions */
00317 
00318 /* Initialize the threads subsystem.  */
00319 static inline int
00320 __gthread_objc_init_thread_system (void)
00321 {
00322   if (__gthread_active_p ())
00323     {
00324       /* Initialize the thread storage key.  */
00325       if (__gthrw_(pthread_key_create) (&_objc_thread_storage, NULL) == 0)
00326     {
00327       /* The normal default detach state for threads is
00328        * PTHREAD_CREATE_JOINABLE which causes threads to not die
00329        * when you think they should.  */
00330       if (__gthrw_(pthread_attr_init) (&_objc_thread_attribs) == 0
00331           && __gthrw_(pthread_attr_setdetachstate) (&_objc_thread_attribs,
00332                           PTHREAD_CREATE_DETACHED) == 0)
00333         return 0;
00334     }
00335     }
00336 
00337   return -1;
00338 }
00339 
00340 /* Close the threads subsystem.  */
00341 static inline int
00342 __gthread_objc_close_thread_system (void)
00343 {
00344   if (__gthread_active_p ()
00345       && __gthrw_(pthread_key_delete) (_objc_thread_storage) == 0
00346       && __gthrw_(pthread_attr_destroy) (&_objc_thread_attribs) == 0)
00347     return 0;
00348 
00349   return -1;
00350 }
00351 
00352 /* Backend thread functions */
00353 
00354 /* Create a new thread of execution.  */
00355 static inline objc_thread_t
00356 __gthread_objc_thread_detach (void (*func)(void *), void *arg)
00357 {
00358   objc_thread_t thread_id;
00359   pthread_t new_thread_handle;
00360 
00361   if (!__gthread_active_p ())
00362     return NULL;
00363 
00364   if (!(__gthrw_(pthread_create) (&new_thread_handle, NULL, (void *) func, arg)))
00365     thread_id = (objc_thread_t) new_thread_handle;
00366   else
00367     thread_id = NULL;
00368 
00369   return thread_id;
00370 }
00371 
00372 /* Set the current thread's priority.  */
00373 static inline int
00374 __gthread_objc_thread_set_priority (int priority)
00375 {
00376   if (!__gthread_active_p ())
00377     return -1;
00378   else
00379     {
00380 #ifdef _POSIX_PRIORITY_SCHEDULING
00381 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
00382       pthread_t thread_id = __gthrw_(pthread_self) ();
00383       int policy;
00384       struct sched_param params;
00385       int priority_min, priority_max;
00386 
00387       if (__gthrw_(pthread_getschedparam) (thread_id, &policy, &params) == 0)
00388     {
00389       if ((priority_max = __gthrw_(sched_get_priority_max) (policy)) == -1)
00390         return -1;
00391 
00392       if ((priority_min = __gthrw_(sched_get_priority_min) (policy)) == -1)
00393         return -1;
00394 
00395       if (priority > priority_max)
00396         priority = priority_max;
00397       else if (priority < priority_min)
00398         priority = priority_min;
00399       params.sched_priority = priority;
00400 
00401       /*
00402        * The solaris 7 and several other man pages incorrectly state that
00403        * this should be a pointer to policy but pthread.h is universally
00404        * at odds with this.
00405        */
00406       if (__gthrw_(pthread_setschedparam) (thread_id, policy, &params) == 0)
00407         return 0;
00408     }
00409 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
00410 #endif /* _POSIX_PRIORITY_SCHEDULING */
00411       return -1;
00412     }
00413 }
00414 
00415 /* Return the current thread's priority.  */
00416 static inline int
00417 __gthread_objc_thread_get_priority (void)
00418 {
00419 #ifdef _POSIX_PRIORITY_SCHEDULING
00420 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
00421   if (__gthread_active_p ())
00422     {
00423       int policy;
00424       struct sched_param params;
00425 
00426       if (__gthrw_(pthread_getschedparam) (__gthrw_(pthread_self) (), &policy, &params) == 0)
00427     return params.sched_priority;
00428       else
00429     return -1;
00430     }
00431   else
00432 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
00433 #endif /* _POSIX_PRIORITY_SCHEDULING */
00434     return OBJC_THREAD_INTERACTIVE_PRIORITY;
00435 }
00436 
00437 /* Yield our process time to another thread.  */
00438 static inline void
00439 __gthread_objc_thread_yield (void)
00440 {
00441   if (__gthread_active_p ())
00442     __gthrw_(sched_yield) ();
00443 }
00444 
00445 /* Terminate the current thread.  */
00446 static inline int
00447 __gthread_objc_thread_exit (void)
00448 {
00449   if (__gthread_active_p ())
00450     /* exit the thread */
00451     __gthrw_(pthread_exit) (&__objc_thread_exit_status);
00452 
00453   /* Failed if we reached here */
00454   return -1;
00455 }
00456 
00457 /* Returns an integer value which uniquely describes a thread.  */
00458 static inline objc_thread_t
00459 __gthread_objc_thread_id (void)
00460 {
00461   if (__gthread_active_p ())
00462     return (objc_thread_t) __gthrw_(pthread_self) ();
00463   else
00464     return (objc_thread_t) 1;
00465 }
00466 
00467 /* Sets the thread's local storage pointer.  */
00468 static inline int
00469 __gthread_objc_thread_set_data (void *value)
00470 {
00471   if (__gthread_active_p ())
00472     return __gthrw_(pthread_setspecific) (_objc_thread_storage, value);
00473   else
00474     {
00475       thread_local_storage = value;
00476       return 0;
00477     }
00478 }
00479 
00480 /* Returns the thread's local storage pointer.  */
00481 static inline void *
00482 __gthread_objc_thread_get_data (void)
00483 {
00484   if (__gthread_active_p ())
00485     return __gthrw_(pthread_getspecific) (_objc_thread_storage);
00486   else
00487     return thread_local_storage;
00488 }
00489 
00490 /* Backend mutex functions */
00491 
00492 /* Allocate a mutex.  */
00493 static inline int
00494 __gthread_objc_mutex_allocate (objc_mutex_t mutex)
00495 {
00496   if (__gthread_active_p ())
00497     {
00498       mutex->backend = objc_malloc (sizeof (pthread_mutex_t));
00499 
00500       if (__gthrw_(pthread_mutex_init) ((pthread_mutex_t *) mutex->backend, NULL))
00501     {
00502       objc_free (mutex->backend);
00503       mutex->backend = NULL;
00504       return -1;
00505     }
00506     }
00507 
00508   return 0;
00509 }
00510 
00511 /* Deallocate a mutex.  */
00512 static inline int
00513 __gthread_objc_mutex_deallocate (objc_mutex_t mutex)
00514 {
00515   if (__gthread_active_p ())
00516     {
00517       int count;
00518 
00519       /*
00520        * Posix Threads specifically require that the thread be unlocked
00521        * for __gthrw_(pthread_mutex_destroy) to work.
00522        */
00523 
00524       do
00525     {
00526       count = __gthrw_(pthread_mutex_unlock) ((pthread_mutex_t *) mutex->backend);
00527       if (count < 0)
00528         return -1;
00529     }
00530       while (count);
00531 
00532       if (__gthrw_(pthread_mutex_destroy) ((pthread_mutex_t *) mutex->backend))
00533     return -1;
00534 
00535       objc_free (mutex->backend);
00536       mutex->backend = NULL;
00537     }
00538   return 0;
00539 }
00540 
00541 /* Grab a lock on a mutex.  */
00542 static inline int
00543 __gthread_objc_mutex_lock (objc_mutex_t mutex)
00544 {
00545   if (__gthread_active_p ()
00546       && __gthrw_(pthread_mutex_lock) ((pthread_mutex_t *) mutex->backend) != 0)
00547     {
00548       return -1;
00549     }
00550 
00551   return 0;
00552 }
00553 
00554 /* Try to grab a lock on a mutex.  */
00555 static inline int
00556 __gthread_objc_mutex_trylock (objc_mutex_t mutex)
00557 {
00558   if (__gthread_active_p ()
00559       && __gthrw_(pthread_mutex_trylock) ((pthread_mutex_t *) mutex->backend) != 0)
00560     {
00561       return -1;
00562     }
00563 
00564   return 0;
00565 }
00566 
00567 /* Unlock the mutex */
00568 static inline int
00569 __gthread_objc_mutex_unlock (objc_mutex_t mutex)
00570 {
00571   if (__gthread_active_p ()
00572       && __gthrw_(pthread_mutex_unlock) ((pthread_mutex_t *) mutex->backend) != 0)
00573     {
00574       return -1;
00575     }
00576 
00577   return 0;
00578 }
00579 
00580 /* Backend condition mutex functions */
00581 
00582 /* Allocate a condition.  */
00583 static inline int
00584 __gthread_objc_condition_allocate (objc_condition_t condition)
00585 {
00586   if (__gthread_active_p ())
00587     {
00588       condition->backend = objc_malloc (sizeof (pthread_cond_t));
00589 
00590       if (__gthrw_(pthread_cond_init) ((pthread_cond_t *) condition->backend, NULL))
00591     {
00592       objc_free (condition->backend);
00593       condition->backend = NULL;
00594       return -1;
00595     }
00596     }
00597 
00598   return 0;
00599 }
00600 
00601 /* Deallocate a condition.  */
00602 static inline int
00603 __gthread_objc_condition_deallocate (objc_condition_t condition)
00604 {
00605   if (__gthread_active_p ())
00606     {
00607       if (__gthrw_(pthread_cond_destroy) ((pthread_cond_t *) condition->backend))
00608     return -1;
00609 
00610       objc_free (condition->backend);
00611       condition->backend = NULL;
00612     }
00613   return 0;
00614 }
00615 
00616 /* Wait on the condition */
00617 static inline int
00618 __gthread_objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex)
00619 {
00620   if (__gthread_active_p ())
00621     return __gthrw_(pthread_cond_wait) ((pthread_cond_t *) condition->backend,
00622                   (pthread_mutex_t *) mutex->backend);
00623   else
00624     return 0;
00625 }
00626 
00627 /* Wake up all threads waiting on this condition.  */
00628 static inline int
00629 __gthread_objc_condition_broadcast (objc_condition_t condition)
00630 {
00631   if (__gthread_active_p ())
00632     return __gthrw_(pthread_cond_broadcast) ((pthread_cond_t *) condition->backend);
00633   else
00634     return 0;
00635 }
00636 
00637 /* Wake up one thread waiting on this condition.  */
00638 static inline int
00639 __gthread_objc_condition_signal (objc_condition_t condition)
00640 {
00641   if (__gthread_active_p ())
00642     return __gthrw_(pthread_cond_signal) ((pthread_cond_t *) condition->backend);
00643   else
00644     return 0;
00645 }
00646 
00647 #else /* _LIBOBJC */
00648 
00649 static inline int
00650 __gthread_create (__gthread_t *__threadid, void *(*__func) (void*),
00651           void *__args)
00652 {
00653   return __gthrw_(pthread_create) (__threadid, NULL, __func, __args);
00654 }
00655 
00656 static inline int
00657 __gthread_join (__gthread_t __threadid, void **__value_ptr)
00658 {
00659   return __gthrw_(pthread_join) (__threadid, __value_ptr);
00660 }
00661 
00662 static inline int
00663 __gthread_detach (__gthread_t __threadid)
00664 {
00665   return __gthrw_(pthread_detach) (__threadid);
00666 }
00667 
00668 static inline int
00669 __gthread_equal (__gthread_t __t1, __gthread_t __t2)
00670 {
00671   return __gthrw_(pthread_equal) (__t1, __t2);
00672 }
00673 
00674 static inline __gthread_t
00675 __gthread_self (void)
00676 {
00677   return __gthrw_(pthread_self) ();
00678 }
00679 
00680 static inline int
00681 __gthread_yield (void)
00682 {
00683   return __gthrw_(sched_yield) ();
00684 }
00685 
00686 static inline int
00687 __gthread_once (__gthread_once_t *__once, void (*__func) (void))
00688 {
00689   if (__gthread_active_p ())
00690     return __gthrw_(pthread_once) (__once, __func);
00691   else
00692     return -1;
00693 }
00694 
00695 static inline int
00696 __gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
00697 {
00698   return __gthrw_(pthread_key_create) (__key, __dtor);
00699 }
00700 
00701 static inline int
00702 __gthread_key_delete (__gthread_key_t __key)
00703 {
00704   return __gthrw_(pthread_key_delete) (__key);
00705 }
00706 
00707 static inline void *
00708 __gthread_getspecific (__gthread_key_t __key)
00709 {
00710   return __gthrw_(pthread_getspecific) (__key);
00711 }
00712 
00713 static inline int
00714 __gthread_setspecific (__gthread_key_t __key, const void *__ptr)
00715 {
00716   return __gthrw_(pthread_setspecific) (__key, __ptr);
00717 }
00718 
00719 static inline void
00720 __gthread_mutex_init_function2 (__gthread_mutex_t *__mutex)
00721 {
00722   if (__gthread_active_p ())
00723     __gthrw_(pthread_mutex_init) (__mutex, NULL);
00724 }
00725 
00726 static inline int
00727 __gthread_mutex_destroy (__gthread_mutex_t *__mutex)
00728 {
00729   if (__gthread_active_p ())
00730     return __gthrw_(pthread_mutex_destroy) (__mutex);
00731   else
00732     return 0;
00733 }
00734 
00735 static inline int
00736 __gthread_mutex_lock (__gthread_mutex_t *__mutex)
00737 {
00738   if (__gthread_active_p ())
00739     return __gthrw_(pthread_mutex_lock) (__mutex);
00740   else
00741     return 0;
00742 }
00743 
00744 static inline int
00745 __gthread_mutex_trylock (__gthread_mutex_t *__mutex)
00746 {
00747   if (__gthread_active_p ())
00748     return __gthrw_(pthread_mutex_trylock) (__mutex);
00749   else
00750     return 0;
00751 }
00752 
00753 #ifdef _POSIX_TIMEOUTS
00754 #if _POSIX_TIMEOUTS >= 0
00755 static inline int
00756 __gthread_mutex_timedlock (__gthread_mutex_t *__mutex,
00757                const __gthread_time_t *__abs_timeout)
00758 {
00759   if (__gthread_active_p ())
00760     return __gthrw_(pthread_mutex_timedlock) (__mutex, __abs_timeout);
00761   else
00762     return 0;
00763 }
00764 #endif
00765 #endif
00766 
00767 static inline int
00768 __gthread_mutex_unlock (__gthread_mutex_t *__mutex)
00769 {
00770   if (__gthread_active_p ())
00771     return __gthrw_(pthread_mutex_unlock) (__mutex);
00772   else
00773     return 0;
00774 }
00775 
00776 #ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
00777 static inline int
00778 __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
00779 {
00780   if (__gthread_active_p ())
00781     {
00782       pthread_mutexattr_t __attr;
00783       int __r;
00784 
00785       __r = __gthrw_(pthread_mutexattr_init) (&__attr);
00786       if (!__r)
00787     __r = __gthrw_(pthread_mutexattr_settype) (&__attr,
00788                            PTHREAD_MUTEX_RECURSIVE);
00789       if (!__r)
00790     __r = __gthrw_(pthread_mutex_init) (__mutex, &__attr);
00791       if (!__r)
00792     __r = __gthrw_(pthread_mutexattr_destroy) (&__attr);
00793       return __r;
00794     }
00795   return 0;
00796 }
00797 #endif
00798 
00799 static inline int
00800 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
00801 {
00802   return __gthread_mutex_lock (__mutex);
00803 }
00804 
00805 static inline int
00806 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
00807 {
00808   return __gthread_mutex_trylock (__mutex);
00809 }
00810 
00811 #ifdef _POSIX_TIMEOUTS
00812 #if _POSIX_TIMEOUTS >= 0
00813 static inline int
00814 __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *__mutex,
00815                      const __gthread_time_t *__abs_timeout)
00816 {
00817   return __gthread_mutex_timedlock (__mutex, __abs_timeout);
00818 }
00819 #endif
00820 #endif
00821 
00822 static inline int
00823 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
00824 {
00825   return __gthread_mutex_unlock (__mutex);
00826 }
00827 
00828 static inline int
00829 __gthread_cond_broadcast (__gthread_cond_t *__cond)
00830 {
00831   return __gthrw_(pthread_cond_broadcast) (__cond);
00832 }
00833 
00834 static inline int
00835 __gthread_cond_signal (__gthread_cond_t *__cond)
00836 {
00837   return __gthrw_(pthread_cond_signal) (__cond);
00838 }
00839 
00840 static inline int
00841 __gthread_cond_wait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex)
00842 {
00843   return __gthrw_(pthread_cond_wait) (__cond, __mutex);
00844 }
00845 
00846 static inline int
00847 __gthread_cond_timedwait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex,
00848               const __gthread_time_t *__abs_timeout)
00849 {
00850   return __gthrw_(pthread_cond_timedwait) (__cond, __mutex, __abs_timeout);
00851 }
00852 
00853 static inline int
00854 __gthread_cond_wait_recursive (__gthread_cond_t *__cond,
00855                    __gthread_recursive_mutex_t *__mutex)
00856 {
00857   return __gthread_cond_wait (__cond, __mutex);
00858 }
00859 
00860 static inline int
00861 __gthread_cond_timedwait_recursive (__gthread_cond_t *__cond,
00862                     __gthread_recursive_mutex_t *__mutex,
00863                     const __gthread_time_t *__abs_timeout)
00864 {
00865   return __gthread_cond_timedwait (__cond, __mutex, __abs_timeout);
00866 }
00867 
00868 static inline int
00869 __gthread_cond_destroy (__gthread_cond_t* __cond)
00870 {
00871   return __gthrw_(pthread_cond_destroy) (__cond);
00872 }
00873 
00874 #endif /* _LIBOBJC */
00875 
00876 #endif /* ! _GLIBCXX_GCC_GTHR_POSIX_H */

Generated on 19 Jun 2018 for libstdc++ by  doxygen 1.6.1