diff options
author | Doug Kwan <dougkwan@google.com> | 2007-10-05 05:35:46 +0000 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2007-10-05 01:35:46 -0400 |
commit | afd82ef5ab97b47cbb9413da64a8bf6929caf25a (patch) | |
tree | 7199ead87b016c417595eb8799a0e2e438399c58 /gcc | |
parent | 90e965bb845a73148758d4639058a59ad0801a06 (diff) | |
download | gcc-afd82ef5ab97b47cbb9413da64a8bf6929caf25a.zip gcc-afd82ef5ab97b47cbb9413da64a8bf6929caf25a.tar.gz gcc-afd82ef5ab97b47cbb9413da64a8bf6929caf25a.tar.bz2 |
gthr-posix.h (__gthread_cond_broadcast, [...]): Add to extend interface for POSIX conditional variables.
2007-09-13 Doug Kwan <dougkwan@google.com>
* gcc/gthr-posix.h (__gthread_cond_broadcast, __gthread_cond_wait,
__gthread_cond_wait_recursive): Add to extend interface for POSIX
conditional variables. (__GTHREAD_HAS_COND): Macro defined to signify
support of conditional variables.
* gcc/gthr-posix95.h (__gthread_cond_broadcast, __gthread_cond_wait,
__gthread_cond_wait_recursive): Add to extend interface for POSIX
conditional variables. (__GTHREAD_HAS_COND): Macro defined to signify
support of conditional variables.
* gcc/gthr-single.h (__gthread_cond_broadcast, __gthread_cond_wait,
__gthread_cond_wait_recursive): Add to extend interface for POSIX
conditional variables.
* gcc/gthr.h: Update comments to document new interface.
* libstdc++-v3/include/ext/concurrent.h (class __mutex,
class __recursive_mutex): Add new method gthread_mutex to access
inner gthread mutex.
[__GTHREAD_HAS_COND] (class __concurrence_broadcast_error,
class __concurrence_wait_error, class __cond): Add.
* guard.cc (recursive_push, recursive_pop): Delete.
(init_in_progress_flag, set_init_in_progress_flag): Add to
replace recursive_push and recursive_pop.
(throw_recursive_init_exception): Add.
(acquire, __cxa_guard_acquire, __cxa_guard_abort and
__cxa_guard_release): [__GTHREAD_HAS_COND] Use a conditional
for synchronization of static variable initialization.
The global mutex is only held briefly when guards are
accessed. [!__GTHREAD_HAS_COND] Fall back to the old code,
which deadlocks.
* testsuite/thread/guard.cc: Add new test. It deadlocks with the
old locking code in libstdc++-v3/libsup++/guard.cc.
From-SVN: r129030
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 15 | ||||
-rw-r--r-- | gcc/gthr-posix.h | 33 | ||||
-rw-r--r-- | gcc/gthr-posix95.h | 29 | ||||
-rw-r--r-- | gcc/gthr-single.h | 19 | ||||
-rw-r--r-- | gcc/gthr.h | 18 |
5 files changed, 108 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 35003ed..3dabeea 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,18 @@ +2007-10-04 Doug Kwan <dougkwan@google.com> + + * gthr-posix.h (__gthread_cond_broadcast, __gthread_cond_wait, + __gthread_cond_wait_recursive): Add to extend interface for POSIX + conditional variables. (__GTHREAD_HAS_COND): Macro defined to signify + support of conditional variables. + * gthr-posix95.h (__gthread_cond_broadcast, __gthread_cond_wait, + __gthread_cond_wait_recursive): Add to extend interface for POSIX + conditional variables. (__GTHREAD_HAS_COND): Macro defined to signify + support of conditional variables. + * gthr-single.h (__gthread_cond_broadcast, __gthread_cond_wait, + __gthread_cond_wait_recursive): Add to extend interface for POSIX + conditional variables. + * gthr.h: Update comments to document new interface. + 2007-10-04 Geoffrey Keating <geoffk@apple.com> * cgraphunit.c (cgraph_build_static_cdtor): Don't set diff --git a/gcc/gthr-posix.h b/gcc/gthr-posix.h index a290b6a..5c00cd3 100644 --- a/gcc/gthr-posix.h +++ b/gcc/gthr-posix.h @@ -47,6 +47,11 @@ 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; +typedef pthread_cond_t __gthread_cond_t; + +/* POSIX like conditional variables are supported. Please look at comments + in gthr.h for details. */ +#define __GTHREAD_HAS_COND 1 #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT @@ -57,6 +62,7 @@ typedef pthread_mutex_t __gthread_recursive_mutex_t; #else #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function #endif +#define __GTHREAD_COND_INIT PTHREAD_COND_INITIALIZER #if SUPPORTS_WEAK && GTHREAD_USE_WEAK # ifndef __gthrw_pragma @@ -88,6 +94,8 @@ __gthrw3(pthread_mutex_lock) __gthrw3(pthread_mutex_trylock) __gthrw3(pthread_mutex_unlock) __gthrw3(pthread_mutex_init) +__gthrw3(pthread_cond_broadcast) +__gthrw3(pthread_cond_wait) #else __gthrw(pthread_once) __gthrw(pthread_getspecific) @@ -98,6 +106,8 @@ __gthrw(pthread_mutex_lock) __gthrw(pthread_mutex_trylock) __gthrw(pthread_mutex_unlock) __gthrw(pthread_mutex_init) +__gthrw(pthread_cond_broadcast) +__gthrw(pthread_cond_wait) #endif __gthrw(pthread_key_create) @@ -110,20 +120,16 @@ __gthrw(pthread_mutexattr_destroy) #if defined(_LIBOBJC) || defined(_LIBOBJC_WEAK) /* Objective-C. */ #if defined(__osf__) && defined(_PTHREAD_USE_MANGLED_NAMES_) -__gthrw3(pthread_cond_broadcast) __gthrw3(pthread_cond_destroy) __gthrw3(pthread_cond_init) __gthrw3(pthread_cond_signal) -__gthrw3(pthread_cond_wait) __gthrw3(pthread_exit) __gthrw3(pthread_mutex_destroy) __gthrw3(pthread_self) #else -__gthrw(pthread_cond_broadcast) __gthrw(pthread_cond_destroy) __gthrw(pthread_cond_init) __gthrw(pthread_cond_signal) -__gthrw(pthread_cond_wait) __gthrw(pthread_exit) __gthrw(pthread_mutex_destroy) __gthrw(pthread_self) @@ -737,6 +743,25 @@ __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex) return __gthread_mutex_unlock (mutex); } +static inline int +__gthread_cond_broadcast (__gthread_cond_t *cond) +{ + return __gthrw_(pthread_cond_broadcast) (cond); +} + +static inline int +__gthread_cond_wait (__gthread_cond_t *cond, __gthread_mutex_t *mutex) +{ + return __gthrw_(pthread_cond_wait) (cond, mutex); +} + +static inline int +__gthread_cond_wait_recursive (__gthread_cond_t *cond, + __gthread_recursive_mutex_t *mutex) +{ + return __gthread_cond_wait (cond, mutex); +} + #endif /* _LIBOBJC */ #endif /* ! GCC_GTHR_POSIX_H */ diff --git a/gcc/gthr-posix95.h b/gcc/gthr-posix95.h index f0d1553..df250d2 100644 --- a/gcc/gthr-posix95.h +++ b/gcc/gthr-posix95.h @@ -45,6 +45,11 @@ Software Foundation, 51 Franklin Street, Fifth Floor, 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_cond_t __gthread_cond_t; + +/* POSIX like conditional variables are supported. Please look at comments + in gthr.h for details. */ +#define __GTHREAD_HAS_COND 1 typedef struct { long depth; @@ -55,6 +60,7 @@ typedef struct { #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function +#define __GTHREAD_COND_INIT PTHREAD_COND_INITIALIZER #if SUPPORTS_WEAK && GTHREAD_USE_WEAK # define __gthrw(name) \ @@ -81,14 +87,14 @@ __gthrw(pthread_mutexattr_init) __gthrw(pthread_mutexattr_destroy) __gthrw(pthread_mutex_init) +__gthrw(pthread_cond_broadcast) +__gthrw(pthread_cond_wait) #if defined(_LIBOBJC) || defined(_LIBOBJC_WEAK) /* Objective-C. */ -__gthrw(pthread_cond_broadcast) __gthrw(pthread_cond_destroy) __gthrw(pthread_cond_init) __gthrw(pthread_cond_signal) -__gthrw(pthread_cond_wait) __gthrw(pthread_exit) __gthrw(pthread_mutex_destroy) #ifdef _POSIX_PRIORITY_SCHEDULING @@ -719,6 +725,25 @@ __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex) return 0; } +static inline int +__gthread_cond_broadcast (__gthread_cond_t *cond) +{ + return __gthrw_(pthread_cond_broadcast) (cond); +} + +static inline int +__gthread_cond_wait (__gthread_cond_t *cond, __gthread_mutex_t *mutex) +{ + return __gthrw_(pthread_cond_wait) (cond, mutex); +} + +static inline int +__gthread_cond_wait_recursive (__gthread_cond_t *cond, + __gthread_recursive_mutex_t *mutex) +{ + return __gthrw_(pthread_cond_wait) (cond, mutex->actual); +} + #endif /* _LIBOBJC */ #endif /* ! GCC_GTHR_POSIX_H */ diff --git a/gcc/gthr-single.h b/gcc/gthr-single.h index c3a903d..56fd3a7 100644 --- a/gcc/gthr-single.h +++ b/gcc/gthr-single.h @@ -251,6 +251,25 @@ __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex) return __gthread_mutex_unlock (mutex); } +static inline int +__gthread_cond_broadcast (__gthread_cond_t cond) +{ + return 0; +} + +static inline int +__gthread_cond_wait (__gthread_cond_t cond, __gthread_mutex_t *mutex) +{ + return 0; +} + +static inline int +__gthread_cond_wait_recursive (__gthread_cond_t cond, + __gthread_recursive_mutex_t *mutex) +{ + return 0; +} + #endif /* _LIBOBJC */ #undef UNUSED @@ -81,6 +81,24 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA int __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex); int __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex); + The following are supported in POSIX threads only. They are required to + fix a deadlock in static initialization inside libsupc++. The header file + gthr-posix.h defines a symbol __GTHREAD_HAS_COND to signify that these extra + features are supported. + + Types: + __gthread_cond_t + + Macros: + __GTHREAD_COND_INIT + __GTHREAD_COND_INIT_FUNCTION + + Interface: + int __gthread_cond_broadcast (__gthread_cond_t *cond); + int __gthread_cond_wait (__gthread_cond_t *cond, __gthread_mutex_t *mutex); + int __gthread_cond_wait_recursive (__gthread_cond_t *cond, + __gthread_recursive_mutex_t *mutex); + All functions returning int should return zero on success or the error number. If the operation is not supported, -1 is returned. |