summaryrefslogtreecommitdiff
path: root/lib/glthread/lock.h
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2019-06-20 03:54:56 +0200
committerBruno Haible <bruno@clisp.org>2019-06-20 03:59:07 +0200
commit79c2545308000d2120009a76bea4f36f06f16b1b (patch)
tree8acbf5d44d2160038130e4f65f40fc0d00e774c4 /lib/glthread/lock.h
parent97ae5364457c30ea826fa5e6c0c0a41c73a30c38 (diff)
downloadgnulib-79c2545308000d2120009a76bea4f36f06f16b1b.tar.gz
thread, lock, cond, tls: Recognize C11 multithreaded applications.
* m4/threadlib.m4 (gl_THREADLIB_BODY): Test for <threads.h>. * lib/glthread/thread.h (c11_threads_in_use): New macro. (pthread_in_use, pth_in_use, thread_in_use): Use it. * lib/glthread/lock.h (c11_threads_in_use): New macro. (pthread_in_use, pth_in_use, thread_in_use): Use it. * lib/glthread/cond.h (c11_threads_in_use): New macro. (pthread_in_use, pth_in_use, thread_in_use): Use it. * lib/glthread/tls.h (c11_threads_in_use): New macro. (pthread_in_use, pth_in_use, thread_in_use): Use it.
Diffstat (limited to 'lib/glthread/lock.h')
-rw-r--r--lib/glthread/lock.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/glthread/lock.h b/lib/glthread/lock.h
index 6e1fdf8c62..cc6fb5e60d 100644
--- a/lib/glthread/lock.h
+++ b/lib/glthread/lock.h
@@ -81,6 +81,16 @@
#include <errno.h>
#include <stdlib.h>
+#if !defined c11_threads_in_use
+# if HAVE_THREADS_H && (USE_POSIX_THREADS_WEAK || USE_PTH_THREADS_WEAK || USE_SOLARIS_THREADS_WEAK)
+# include <threads.h>
+# pragma weak thrd_exit
+# define c11_threads_in_use() (thrd_exit != NULL)
+# else
+# define c11_threads_in_use() 0
+# endif
+#endif
+
/* ========================================================================= */
#if USE_POSIX_THREADS
@@ -156,7 +166,8 @@ extern int glthread_in_use (void);
pthread_rwlockattr_init
*/
# pragma weak pthread_mutexattr_gettype
-# define pthread_in_use() (pthread_mutexattr_gettype != NULL)
+# define pthread_in_use() \
+ (pthread_mutexattr_gettype != NULL || c11_threads_in_use ())
# endif
# else
@@ -421,7 +432,7 @@ extern "C" {
# pragma weak pth_cond_notify
# pragma weak pth_cancel
-# define pth_in_use() (pth_cancel != NULL)
+# define pth_in_use() (pth_cancel != NULL || c11_threads_in_use ())
# else
@@ -572,7 +583,7 @@ extern "C" {
# pragma weak thr_self
# pragma weak thr_suspend
-# define thread_in_use() (thr_suspend != NULL)
+# define thread_in_use() (thr_suspend != NULL || c11_threads_in_use ())
# else