X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=blobdiff_plain;f=gcc%2Fgthr-posix.h;h=9b56b5aec51176b2076814f6df5766567b6f3ad5;hp=e2b5a5739990ccc6cb2fc1569088b87702170230;hb=10fec8206407ff88fc7c07e09dcc8fea94eaa101;hpb=a55f666d97f9a33369f124946e6f22c023335692 diff --git a/gcc/gthr-posix.h b/gcc/gthr-posix.h index e2b5a573999..9b56b5aec51 100644 --- a/gcc/gthr-posix.h +++ b/gcc/gthr-posix.h @@ -1,6 +1,6 @@ /* Threads compatibility routines for libgcc2 and libobjc. */ /* Compile this one with gcc. */ -/* Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003 +/* Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GCC. @@ -46,9 +46,17 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA typedef pthread_key_t __gthread_key_t; typedef pthread_once_t __gthread_once_t; typedef pthread_mutex_t __gthread_mutex_t; +typedef pthread_mutex_t __gthread_recursive_mutex_t; #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT +#if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER) +#define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER +#elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) +#define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP +#else +#define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function +#endif #if SUPPORTS_WEAK && GTHREAD_USE_WEAK @@ -58,10 +66,16 @@ typedef pthread_mutex_t __gthread_mutex_t; #pragma weak pthread_getspecific #pragma weak pthread_setspecific #pragma weak pthread_create +#pragma weak pthread_cancel #pragma weak pthread_mutex_lock #pragma weak pthread_mutex_trylock #pragma weak pthread_mutex_unlock +#pragma weak pthread_mutexattr_init +#pragma weak pthread_mutexattr_settype +#pragma weak pthread_mutexattr_destroy + +#pragma weak pthread_mutex_init #if defined(_LIBOBJC) || defined(_LIBOBJC_WEAK) /* Objective-C. */ @@ -71,7 +85,6 @@ typedef pthread_mutex_t __gthread_mutex_t; #pragma weak pthread_cond_signal #pragma weak pthread_cond_wait #pragma weak pthread_exit -#pragma weak pthread_mutex_init #pragma weak pthread_mutex_destroy #pragma weak pthread_self #ifdef _POSIX_PRIORITY_SCHEDULING @@ -93,7 +106,8 @@ typedef pthread_mutex_t __gthread_mutex_t; static inline int __gthread_active_p (void) { - static void *const __gthread_active_ptr = (void *) &pthread_create; + static void *const __gthread_active_ptr + = __extension__ (void *) &pthread_cancel; return __gthread_active_ptr != 0; } @@ -131,7 +145,7 @@ __gthread_objc_init_thread_system (void) { if (__gthread_active_p ()) { - /* Initialize the thread storage key */ + /* Initialize the thread storage key. */ if (pthread_key_create (&_objc_thread_storage, NULL) == 0) { /* The normal default detach state for threads is @@ -516,6 +530,45 @@ __gthread_mutex_unlock (__gthread_mutex_t *mutex) return 0; } +#ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP +static inline int +__gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *mutex) +{ + if (__gthread_active_p ()) + { + pthread_mutexattr_t attr; + int r; + + r = pthread_mutexattr_init (&attr); + if (!r) + r = pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); + if (!r) + r = pthread_mutex_init (mutex, &attr); + if (!r) + r = pthread_mutexattr_destroy (&attr); + return r; + } +} +#endif + +static inline int +__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex) +{ + return __gthread_mutex_lock (mutex); +} + +static inline int +__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex) +{ + return __gthread_mutex_trylock (mutex); +} + +static inline int +__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex) +{ + return __gthread_mutex_unlock (mutex); +} + #endif /* _LIBOBJC */ #endif /* ! GCC_GTHR_POSIX_H */