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
#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
__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)
__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)
#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)
{
static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_t t;
+ pthread_attr_t a;
int result;
__gthrw_(pthread_mutex_lock) (&__gthread_active_mutex);
if (__gthread_active < 0)
{
- result = __gthrw_(pthread_create) (&t, NULL, __gthread_start, NULL);
+ __gthrw_(pthread_attr_init) (&a);
+ __gthrw_(pthread_attr_setdetachstate) (&a, PTHREAD_CREATE_DETACHED);
+ result = __gthrw_(pthread_create) (&t, &a, __gthread_start, NULL);
if (result != ENOSYS)
- {
- __gthread_active = 1;
- if (!result)
- __gthrw_(pthread_join) (t, NULL);
- }
+ __gthread_active = 1;
else
__gthread_active = 0;
+ __gthrw_(pthread_attr_destroy) (&a);
}
__gthrw_(pthread_mutex_unlock) (&__gthread_active_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 */