summaryrefslogtreecommitdiffstats
path: root/gcc/gthr-posix.h
diff options
context:
space:
mode:
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>2006-10-31 17:54:58 +0000
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>2006-10-31 17:54:58 +0000
commit2f9d7fddd64d160025a657e9f5949b5575fd4525 (patch)
tree274d7a9848d373cc18d1f3edae2892b3119c8f28 /gcc/gthr-posix.h
parent0326143c40c1671c2ace9370e1a79d29db3717c6 (diff)
downloadppe42-gcc-2f9d7fddd64d160025a657e9f5949b5575fd4525.tar.gz
ppe42-gcc-2f9d7fddd64d160025a657e9f5949b5575fd4525.zip
PR target/24071
* gthr-posix.h (__gthread_active_p): New implementation on Solaris. * gthr-posix95.h (__gthread_active_p): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@118259 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/gthr-posix.h')
-rw-r--r--gcc/gthr-posix.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/gcc/gthr-posix.h b/gcc/gthr-posix.h
index 62f83b3ffbc..fb58be94ea6 100644
--- a/gcc/gthr-posix.h
+++ b/gcc/gthr-posix.h
@@ -142,6 +142,59 @@ __gthrw(pthread_setschedparam)
#if SUPPORTS_WEAK && GTHREAD_USE_WEAK
+/* On Solaris 2.6 up to 9, the libc exposes a POSIX threads interface even if
+ -pthreads is not specified. The functions are dummies and most return an
+ error value. However pthread_once returns 0 without invoking the routine
+ 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. */
+
+#if defined(__sun) && defined(__svr4__)
+
+static volatile int __gthread_active = -1;
+
+static void
+__gthread_trigger (void)
+{
+ __gthread_active = 1;
+}
+
+static inline int
+__gthread_active_p (void)
+{
+ static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
+ static pthread_once_t __gthread_active_once = PTHREAD_ONCE_INIT;
+
+ /* Avoid reading __gthread_active twice on the main code path. */
+ int __gthread_active_latest_value = __gthread_active;
+
+ /* This test is not protected to avoid taking a lock on the main code
+ path so every update of __gthread_active in a threaded program must
+ be atomic with regard to the result of the test. */
+ if (__builtin_expect (__gthread_active_latest_value < 0, 0))
+ {
+ if (__gthrw_(pthread_once))
+ {
+ /* If this really is a threaded program, then we must ensure that
+ __gthread_active has been set to 1 before exiting this block. */
+ __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex);
+ __gthrw_(pthread_once) (&__gthread_active_once, __gthread_trigger);
+ __gthrw_(pthread_mutex_unlock) (&__gthread_active_mutex);
+ }
+
+ /* Make sure we'll never enter this block again. */
+ if (__gthread_active < 0)
+ __gthread_active = 0;
+
+ __gthread_active_latest_value = __gthread_active;
+ }
+
+ return __gthread_active_latest_value != 0;
+}
+
+#else /* not Solaris */
+
static inline int
__gthread_active_p (void)
{
@@ -150,6 +203,8 @@ __gthread_active_p (void)
return __gthread_active_ptr != 0;
}
+#endif /* Solaris */
+
#else /* not SUPPORTS_WEAK */
static inline int
OpenPOWER on IntegriCloud