OSDN Git Service

2009-01-03 Paul Thomas <pault@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / gthr-posix95.h
index eb54c92..190b097 100644 (file)
@@ -80,13 +80,14 @@ __gthrw(pthread_create)
 __gthrw(pthread_cancel)
 __gthrw(pthread_self)
 
+__gthrw(pthread_mutex_init)
+__gthrw(pthread_mutex_destroy)
 __gthrw(pthread_mutex_lock)
 __gthrw(pthread_mutex_trylock)
 __gthrw(pthread_mutex_unlock)
 __gthrw(pthread_mutexattr_init)
 __gthrw(pthread_mutexattr_destroy)
 
-__gthrw(pthread_mutex_init)
 __gthrw(pthread_cond_broadcast)
 __gthrw(pthread_cond_wait)
 
@@ -96,7 +97,6 @@ __gthrw(pthread_cond_destroy)
 __gthrw(pthread_cond_init)
 __gthrw(pthread_cond_signal)
 __gthrw(pthread_exit)
-__gthrw(pthread_mutex_destroy)
 #ifdef _POSIX_PRIORITY_SCHEDULING
 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
 __gthrw(sched_get_priority_max)
@@ -121,9 +121,12 @@ __gthrw(pthread_setschedparam)
    it is passed so we cannot pretend that the interface is active if -pthreads
    is not specified.  On Solaris 2.5.1, the interface is not exposed at all so
    we need to play the usual game with weak symbols.  On Solaris 10 and up, a
-   working interface is always exposed.  */
+   working interface is always exposed.  On FreeBSD 6 and later, libc also
+   exposes a dummy POSIX threads interface, similar to what Solaris 2.6 up
+   to 9 does.  FreeBSD >= 700014 even provides a pthread_cancel stub in libc,
+   which means the alternate __gthread_active_p below cannot be used there.  */
 
-#if defined(__sun) && defined(__svr4__)
+#if defined(__FreeBSD__) || (defined(__sun) && defined(__svr4__))
 
 static volatile int __gthread_active = -1;
 
@@ -166,7 +169,7 @@ __gthread_active_p (void)
   return __gthread_active_latest_value != 0;
 }
 
-#else /* not Solaris */
+#else /* neither FreeBSD nor Solaris */
 
 static inline int
 __gthread_active_p (void)
@@ -176,7 +179,7 @@ __gthread_active_p (void)
   return __gthread_active_ptr != 0;
 }
 
-#endif /* Solaris */
+#endif /* FreeBSD or Solaris */
 
 #else /* not SUPPORTS_WEAK */
 
@@ -640,6 +643,15 @@ __gthread_setspecific (__gthread_key_t key, const void *ptr)
 }
 
 static inline int
+__gthread_mutex_destroy (__gthread_mutex_t *mutex)
+{
+  if (__gthread_active_p ())
+    return __gthrw_(pthread_mutex_destroy) (mutex);
+  else
+    return 0;
+}
+
+static inline int
 __gthread_mutex_lock (__gthread_mutex_t *mutex)
 {
   if (__gthread_active_p ())
@@ -741,7 +753,7 @@ static inline int
 __gthread_cond_wait_recursive (__gthread_cond_t *cond,
                               __gthread_recursive_mutex_t *mutex)
 {
-  return __gthrw_(pthread_cond_wait) (cond, mutex->actual);
+  return __gthrw_(pthread_cond_wait) (cond, &mutex->actual);
 }
 
 #endif /* _LIBOBJC */