+2019-07-14 Bruno Haible <bruno@clisp.org>
+
+ pthread-h: New module.
+ * lib/pthread.in.h: Define replacement functions only if GNULIB_PTHREAD
+ is 1.
+ * m4/pthread_h.m4: Renamed from m4/pthread.m4.
+ (gl_PTHREAD_H): Renamed from gl_PTHREAD_CHECK. Don't test whether
+ <pthread.h> pollutes the namespace; instead, prepare for generating a
+ pthread.h always. Substitute HAVE_PTHREAD_H here.
+ (gl_PTHREAD_H_DEFAULTS): Renamed from gl_PTHREAD_DEFAULTS. Initialize
+ GNULIB_PTHREAD. Don't initialize HAVE_PTHREAD_H here.
+ * modules/pthread-h: New file, based on modules/pthread.
+ * modules/pthread: Rely on 'pthread-h'.
+ * m4/pthread_mutex_timedlock.m4 (gl_FUNC_PTHREAD_MUTEX_TIMEDLOCK):
+ Update.
+ * modules/pthread_mutex_timedlock (Depends-on): Add pthread-h. Remove
+ pthread.
+
2019-07-14 Bruno Haible <bruno@clisp.org>
sched_yield: New module.
#if ! @HAVE_PTHREAD_T@
-# if !GNULIB_defined_pthread_functions
+# if @GNULIB_PTHREAD@
+
+# if !GNULIB_defined_pthread_functions
/* Provide substitutes for the thread functions that should work
adequately on a single-threaded implementation, where
return 0;
}
-# define GNULIB_defined_pthread_functions 1
+# define GNULIB_defined_pthread_functions 1
+# endif
+
# endif
#else
#if ! @HAVE_PTHREAD_SPINLOCK_T@
-# if !GNULIB_defined_pthread_spinlock_t
+# if @GNULIB_PTHREAD@
+
+# if !GNULIB_defined_pthread_spinlock_t
/* Approximate spinlocks with mutexes. */
return pthread_mutex_unlock (lock);
}
-# define GNULIB_defined_pthread_spinlock_t 1
+# define GNULIB_defined_pthread_spinlock_t 1
+# endif
+
# endif
#endif
+++ /dev/null
-# pthread.m4 serial 11
-dnl Copyright (C) 2009-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,
-dnl with or without modifications, as long as this notice is preserved.
-
-AC_DEFUN([gl_PTHREAD_CHECK],
-[
- AC_REQUIRE([gl_PTHREAD_DEFAULTS])
- gl_CHECK_NEXT_HEADERS([pthread.h])
- if test $ac_cv_header_pthread_h = yes; then
- HAVE_PTHREAD_H=1
- # mingw 3.0 uses winpthreads which installs broken macros via <pthread.h>
- AC_CACHE_CHECK([whether <pthread.h> pollutes the namespace],
- [gl_cv_header_pthread_h_pollution],
- [AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
- [[#include <pthread.h>
- #if defined strtok_r || defined localtime_r
- #error
- break me
- #endif
- ]])],
- [gl_cv_header_pthread_h_pollution=no],
- [gl_cv_header_pthread_h_pollution=yes])])
- else
- HAVE_PTHREAD_H=0
- fi
-
- AC_CHECK_TYPES([pthread_t, pthread_spinlock_t], [], [],
- [AC_INCLUDES_DEFAULT[
- #if HAVE_PTHREAD_H
- #include <pthread.h>
- #endif]])
- if test $ac_cv_type_pthread_t != yes; then
- HAVE_PTHREAD_T=0
- fi
- if test $ac_cv_type_pthread_spinlock_t != yes; then
- HAVE_PTHREAD_SPINLOCK_T=0
- fi
-
- if test $HAVE_PTHREAD_H = 0 || test $HAVE_PTHREAD_T = 0 || test $HAVE_PTHREAD_SPINLOCK_T = 0; then
- PTHREAD_H='pthread.h'
- elif test $gl_cv_header_pthread_h_pollution = yes; then
- PTHREAD_H='pthread.h'
- else
- PTHREAD_H=
- fi
- AC_SUBST([PTHREAD_H])
- AM_CONDITIONAL([GL_GENERATE_PTHREAD_H], [test -n "$PTHREAD_H"])
-
- dnl Check for declarations of anything we want to poison if the
- dnl corresponding gnulib module is not in use, if it is not common
- dnl enough to be declared everywhere.
- gl_WARN_ON_USE_PREPARE([[#include <pthread.h>
- ]], [pthread_mutex_timedlock])
-
- LIB_PTHREAD=
- if test $ac_cv_header_pthread_h = yes; then
- dnl We cannot use AC_SEARCH_LIBS here, because on OSF/1 5.1 pthread_join
- dnl is defined as a macro which expands to __phread_join, and libpthread
- dnl contains a definition for __phread_join but none for pthread_join.
- dnl Also, FreeBSD 9 puts pthread_create in libpthread and pthread_join
- dnl in libc, whereas on IRIX 6.5 the reverse is true; so check for both.
- AC_CACHE_CHECK([for library containing pthread_create and pthread_join],
- [gl_cv_lib_pthread],
- [gl_saved_libs=$LIBS
- gl_cv_lib_pthread=
- for gl_lib_prefix in '' '-pthread' '-lpthread'; do
- LIBS="$gl_lib_prefix $gl_saved_libs"
- AC_LINK_IFELSE(
- [AC_LANG_PROGRAM(
- [[#include <pthread.h>
- void *noop (void *p) { return p; }]],
- [[pthread_t pt;
- void *arg = 0;
- pthread_create (&pt, 0, noop, arg);
- pthread_join (pthread_self (), &arg);]])],
- [if test -z "$gl_lib_prefix"; then
- gl_cv_lib_pthread="none required"
- else
- gl_cv_lib_pthread=$gl_lib_prefix
- fi])
- test -n "$gl_cv_lib_pthread" && break
- done
- LIBS="$gl_saved_libs"
- ])
- if test "$gl_cv_lib_pthread" != "none required"; then
- LIB_PTHREAD="$gl_cv_lib_pthread"
- fi
- fi
- AC_SUBST([LIB_PTHREAD])
-
- AC_REQUIRE([AC_C_RESTRICT])
-])
-
-AC_DEFUN([gl_PTHREAD_MODULE_INDICATOR],
-[
- dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
- AC_REQUIRE([gl_PTHREAD_DEFAULTS])
- gl_MODULE_INDICATOR_SET_VARIABLE([$1])
- dnl Define it also as a C macro, for the benefit of the unit tests.
- gl_MODULE_INDICATOR_FOR_TESTS([$1])
-])
-
-AC_DEFUN([gl_PTHREAD_DEFAULTS],
-[
- GNULIB_PTHREAD_MUTEX_TIMEDLOCK=0; AC_SUBST([GNULIB_PTHREAD_MUTEX_TIMEDLOCK])
- dnl Assume proper GNU behavior unless another module says otherwise.
- HAVE_PTHREAD_H=1; AC_SUBST([HAVE_PTHREAD_H])
- HAVE_PTHREAD_T=1; AC_SUBST([HAVE_PTHREAD_T])
- HAVE_PTHREAD_SPINLOCK_T=1; AC_SUBST([HAVE_PTHREAD_SPINLOCK_T])
- HAVE_PTHREAD_MUTEX_TIMEDLOCK=1; AC_SUBST([HAVE_PTHREAD_MUTEX_TIMEDLOCK])
-])
--- /dev/null
+# pthread_h.m4 serial 1
+dnl Copyright (C) 2009-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,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_PTHREAD_H],
+[
+ dnl Use AC_REQUIRE here, so that the default behavior below is expanded
+ dnl once only, before all statements that occur in other macros.
+ AC_REQUIRE([gl_PTHREAD_H_DEFAULTS])
+
+ gl_CHECK_NEXT_HEADERS([pthread.h])
+ if test $ac_cv_header_pthread_h = yes; then
+ HAVE_PTHREAD_H=1
+ else
+ HAVE_PTHREAD_H=0
+ fi
+ AC_SUBST([HAVE_PTHREAD_H])
+
+ AC_CHECK_TYPES([pthread_t, pthread_spinlock_t], [], [],
+ [AC_INCLUDES_DEFAULT[
+ #if HAVE_PTHREAD_H
+ #include <pthread.h>
+ #endif]])
+ if test $ac_cv_type_pthread_t != yes; then
+ HAVE_PTHREAD_T=0
+ fi
+ if test $ac_cv_type_pthread_spinlock_t != yes; then
+ HAVE_PTHREAD_SPINLOCK_T=0
+ fi
+
+ dnl Check for declarations of anything we want to poison if the
+ dnl corresponding gnulib module is not in use, if it is not common
+ dnl enough to be declared everywhere.
+ gl_WARN_ON_USE_PREPARE([[#include <pthread.h>
+ ]], [pthread_mutex_timedlock])
+
+ AC_REQUIRE([AC_C_RESTRICT])
+
+ LIB_PTHREAD=
+ if test $ac_cv_header_pthread_h = yes; then
+ dnl We cannot use AC_SEARCH_LIBS here, because on OSF/1 5.1 pthread_join
+ dnl is defined as a macro which expands to __phread_join, and libpthread
+ dnl contains a definition for __phread_join but none for pthread_join.
+ dnl Also, FreeBSD 9 puts pthread_create in libpthread and pthread_join
+ dnl in libc, whereas on IRIX 6.5 the reverse is true; so check for both.
+ AC_CACHE_CHECK([for library containing pthread_create and pthread_join],
+ [gl_cv_lib_pthread],
+ [gl_saved_libs=$LIBS
+ gl_cv_lib_pthread=
+ for gl_lib_prefix in '' '-pthread' '-lpthread'; do
+ LIBS="$gl_lib_prefix $gl_saved_libs"
+ AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <pthread.h>
+ void *noop (void *p) { return p; }]],
+ [[pthread_t pt;
+ void *arg = 0;
+ pthread_create (&pt, 0, noop, arg);
+ pthread_join (pthread_self (), &arg);]])],
+ [if test -z "$gl_lib_prefix"; then
+ gl_cv_lib_pthread="none required"
+ else
+ gl_cv_lib_pthread=$gl_lib_prefix
+ fi])
+ test -n "$gl_cv_lib_pthread" && break
+ done
+ LIBS="$gl_saved_libs"
+ ])
+ if test "$gl_cv_lib_pthread" != "none required"; then
+ LIB_PTHREAD="$gl_cv_lib_pthread"
+ fi
+ fi
+ AC_SUBST([LIB_PTHREAD])
+])
+
+AC_DEFUN([gl_PTHREAD_MODULE_INDICATOR],
+[
+ dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+ AC_REQUIRE([gl_PTHREAD_H_DEFAULTS])
+ gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+ dnl Define it also as a C macro, for the benefit of the unit tests.
+ gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_PTHREAD_H_DEFAULTS],
+[
+ GNULIB_PTHREAD=0; AC_SUBST([GNULIB_PTHREAD])
+ GNULIB_PTHREAD_MUTEX_TIMEDLOCK=0; AC_SUBST([GNULIB_PTHREAD_MUTEX_TIMEDLOCK])
+ dnl Assume proper GNU behavior unless another module says otherwise.
+ HAVE_PTHREAD_MUTEX_TIMEDLOCK=1; AC_SUBST([HAVE_PTHREAD_MUTEX_TIMEDLOCK])
+ HAVE_PTHREAD_SPINLOCK_T=1; AC_SUBST([HAVE_PTHREAD_SPINLOCK_T])
+ HAVE_PTHREAD_T=1; AC_SUBST([HAVE_PTHREAD_T])
+])
-# pthread_mutex_timedlock.m4 serial 1
+# pthread_mutex_timedlock.m4 serial 2
dnl Copyright (C) 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,
AC_DEFUN([gl_FUNC_PTHREAD_MUTEX_TIMEDLOCK],
[
- AC_REQUIRE([gl_PTHREAD_DEFAULTS])
+ AC_REQUIRE([gl_PTHREAD_H_DEFAULTS])
AC_CHECK_DECL([pthread_mutex_timedlock], , [HAVE_PTHREAD_MUTEX_TIMEDLOCK=0],
[[#include <pthread.h>]])
Description:
-Implement a trivial subset of the pthreads library.
+Implement the most essential subset of the pthreads library.
Files:
lib/pthread.c
-lib/pthread.in.h
-m4/pthread.m4
Depends-on:
-extensions
-extern-inline
-sched
-time
-
-configure.ac-early:
-AC_DEFINE([_REENTRANT], 1, [For thread-safety on OSF/1, Solaris.])
-AC_DEFINE([_THREAD_SAFE], 1, [For thread-safety on AIX, FreeBSD.])
+pthread-h
configure.ac:
-gl_PTHREAD_CHECK
if test $HAVE_PTHREAD_H = 0 || test $HAVE_PTHREAD_T = 0 || test $HAVE_PTHREAD_SPINLOCK_T = 0; then
AC_LIBOBJ([pthread])
fi
gl_MODULE_INDICATOR([pthread])
Makefile.am:
-BUILT_SOURCES += $(PTHREAD_H)
-
-# We need the following in order to create <pthread.h> when the system
-# doesn't have one that works with the given compiler.
-if GL_GENERATE_PTHREAD_H
-pthread.h: pthread.in.h $(top_builddir)/config.status
- $(AM_V_GEN)rm -f $@-t $@ && \
- { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
- sed -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \
- -e 's|@''HAVE_PTHREAD_H''@|$(HAVE_PTHREAD_H)|g' \
- -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
- -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
- -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
- -e 's|@''NEXT_PTHREAD_H''@|$(NEXT_PTHREAD_H)|g' \
- -e 's/@''GNULIB_PTHREAD_MUTEX_TIMEDLOCK''@/$(GNULIB_PTHREAD_MUTEX_TIMEDLOCK)/g' \
- -e 's|@''HAVE_PTHREAD_T''@|$(HAVE_PTHREAD_T)|g' \
- -e 's|@''HAVE_PTHREAD_SPINLOCK_T''@|$(HAVE_PTHREAD_SPINLOCK_T)|g' \
- -e 's|@''HAVE_PTHREAD_MUTEX_TIMEDLOCK''@|$(HAVE_PTHREAD_MUTEX_TIMEDLOCK)|g' \
- < $(srcdir)/pthread.in.h; \
- } > $@-t && \
- mv $@-t $@
-else
-pthread.h: $(top_builddir)/config.status
- rm -f $@
-endif
-MOSTLYCLEANFILES += pthread.h pthread.h-t
Include:
<pthread.h>
LGPLv2+
Maintainer:
-Glen Lenker and Paul Eggert
+Paul Eggert
--- /dev/null
+Description:
+A POSIX-like <pthread.h>.
+
+Files:
+lib/pthread.in.h
+m4/pthread_h.m4
+
+Depends-on:
+extensions
+extern-inline
+sched
+time
+
+configure.ac-early:
+AC_DEFINE([_REENTRANT], 1, [For thread-safety on OSF/1, Solaris.])
+AC_DEFINE([_THREAD_SAFE], 1, [For thread-safety on AIX, FreeBSD.])
+
+configure.ac:
+gl_PTHREAD_H
+
+Makefile.am:
+BUILT_SOURCES += pthread.h
+
+# We need the following in order to create <pthread.h> when the system
+# doesn't have one that works with the given compiler.
+pthread.h: pthread.in.h $(top_builddir)/config.status
+ $(AM_V_GEN)rm -f $@-t $@ && \
+ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+ sed -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \
+ -e 's|@''HAVE_PTHREAD_H''@|$(HAVE_PTHREAD_H)|g' \
+ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+ -e 's|@''NEXT_PTHREAD_H''@|$(NEXT_PTHREAD_H)|g' \
+ -e 's/@''GNULIB_PTHREAD''@/$(GNULIB_PTHREAD)/g' \
+ -e 's/@''GNULIB_PTHREAD_MUTEX_TIMEDLOCK''@/$(GNULIB_PTHREAD_MUTEX_TIMEDLOCK)/g' \
+ -e 's|@''HAVE_PTHREAD_MUTEX_TIMEDLOCK''@|$(HAVE_PTHREAD_MUTEX_TIMEDLOCK)|g' \
+ -e 's|@''HAVE_PTHREAD_SPINLOCK_T''@|$(HAVE_PTHREAD_SPINLOCK_T)|g' \
+ -e 's|@''HAVE_PTHREAD_T''@|$(HAVE_PTHREAD_T)|g' \
+ < $(srcdir)/pthread.in.h; \
+ } > $@-t && \
+ mv $@-t $@
+MOSTLYCLEANFILES += pthread.h pthread.h-t
+
+Include:
+<pthread.h>
+
+Link:
+$(LIB_PTHREAD)
+
+License:
+LGPLv2+
+
+Maintainer:
+all
m4/pthread_mutex_timedlock.m4
Depends-on:
-pthread
+pthread-h
nanosleep [test $HAVE_PTHREAD_T = 1 && test $HAVE_PTHREAD_MUTEX_TIMEDLOCK = 0]
configure.ac: