* 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.
+2019-06-20 Bruno Haible <bruno@clisp.org>
+
+ 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.
+
2019-06-20 Bruno Haible <bruno@clisp.org>
tls tests: Small improvements.
#include <time.h>
#include "glthread/lock.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
+
#ifndef _GL_INLINE_HEADER_BEGIN
#error "Please include config.h first."
#endif
# if !PTHREAD_IN_USE_DETECTION_HARD
# 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
# pragma weak pth_timeout
# pragma weak pth_cancel
-# define pth_in_use() (pth_cancel != NULL)
+# define pth_in_use() (pth_cancel != NULL || c11_threads_in_use ())
# else
# pragma weak cond_broadcast
# pragma weak cond_destroy
# pragma weak thr_suspend
-# define thread_in_use() (thr_suspend != NULL)
+# define thread_in_use() (thr_suspend != NULL || c11_threads_in_use ())
# else
#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
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
# 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
# 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
#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
+
#ifndef _GL_INLINE_HEADER_BEGIN
#error "Please include config.h first."
#endif
# if !PTHREAD_IN_USE_DETECTION_HARD
# 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
# pragma weak pth_exit
# pragma weak pth_cancel
-# define pth_in_use() (pth_cancel != NULL)
+# define pth_in_use() (pth_cancel != NULL || c11_threads_in_use ())
# else
# pragma weak thr_exit
# pragma weak thr_suspend
-# define thread_in_use() (thr_suspend != NULL)
+# define thread_in_use() (thr_suspend != NULL || c11_threads_in_use ())
# else
#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
# if !PTHREAD_IN_USE_DETECTION_HARD
# 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
# pragma weak pth_key_delete
# pragma weak pth_cancel
-# define pth_in_use() (pth_cancel != NULL)
+# define pth_in_use() (pth_cancel != NULL || c11_threads_in_use ())
# else
# pragma weak thr_setspecific
# pragma weak thr_suspend
-# define thread_in_use() (thr_suspend != NULL)
+# define thread_in_use() (thr_suspend != NULL || c11_threads_in_use ())
# else
-# threadlib.m4 serial 17
+# threadlib.m4 serial 18
dnl Copyright (C) 2005-2019 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
*" -static "*) gl_cv_have_weak=no ;;
esac
])
+ if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
+ dnl If we use weak symbols to implement pthread_in_use / pth_in_use /
+ gnl thread_in_use, we also need to test whether the ISO C 11 thrd_create
+ dnl facility is in use.
+ AC_CHECK_HEADERS_ONCE([threads.h])
+ :
+ fi
if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then
# On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that
# it groks <pthread.h>. It's added above, in gl_THREADLIB_EARLY_BODY.