pthread-h: New module.
authorBruno Haible <bruno@clisp.org>
Mon, 15 Jul 2019 00:36:13 +0000 (02:36 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 15 Jul 2019 00:36:13 +0000 (02:36 +0200)
* 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.

ChangeLog
lib/pthread.in.h
m4/pthread.m4 [deleted file]
m4/pthread_h.m4 [new file with mode: 0644]
m4/pthread_mutex_timedlock.m4
modules/pthread
modules/pthread-h [new file with mode: 0644]
modules/pthread_mutex_timedlock

index db2da4483d488dd765b36b8c503ddb1f9ef9d44d..bab6808e1895860807e5af67a3b7f08faca7e69e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+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.
index cd3cf1fd03961c933a42cd24ed0d306bb1a4527c..1801dbe2f5ef5db67025854328fd086d40a3d2f2 100644 (file)
@@ -138,7 +138,9 @@ _GL_INLINE_HEADER_BEGIN
 
 #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
@@ -268,7 +270,9 @@ pthread_mutex_unlock (pthread_mutex_t *mutex)
   return 0;
 }
 
-#  define GNULIB_defined_pthread_functions 1
+#   define GNULIB_defined_pthread_functions 1
+#  endif
+
 # endif
 
 #else
@@ -293,7 +297,9 @@ _GL_WARN_ON_USE (pthread_mutex_timedlock, "pthread_mutex_timedlock is unportable
 
 #if ! @HAVE_PTHREAD_SPINLOCK_T@
 
-# if !GNULIB_defined_pthread_spinlock_t
+# if @GNULIB_PTHREAD@
+
+#  if !GNULIB_defined_pthread_spinlock_t
 
 /* Approximate spinlocks with mutexes.  */
 
@@ -329,7 +335,9 @@ pthread_spin_unlock (pthread_spinlock_t *lock)
   return pthread_mutex_unlock (lock);
 }
 
-#  define GNULIB_defined_pthread_spinlock_t 1
+#   define GNULIB_defined_pthread_spinlock_t 1
+#  endif
+
 # endif
 
 #endif
diff --git a/m4/pthread.m4 b/m4/pthread.m4
deleted file mode 100644 (file)
index bccac96..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-# 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])
-])
diff --git a/m4/pthread_h.m4 b/m4/pthread_h.m4
new file mode 100644 (file)
index 0000000..d55a471
--- /dev/null
@@ -0,0 +1,95 @@
+# 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])
+])
index 664670f2bb2a7ad406e6581fb0f875d30eb9c326..5cd9cbd7a5c4c823a32c17d1facc2d09255db1e7 100644 (file)
@@ -1,4 +1,4 @@
-# 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,
@@ -6,7 +6,7 @@ dnl with or without modifications, as long as this notice is preserved.
 
 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>]])
index 81e2aad3847923fb7d056cdc03d6ff16b11ffe0a..9e5a7340a426d62515ed259cad9c5578d3ea2817 100644 (file)
@@ -1,55 +1,19 @@
 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>
@@ -61,4 +25,4 @@ License:
 LGPLv2+
 
 Maintainer:
-Glen Lenker and Paul Eggert
+Paul Eggert
diff --git a/modules/pthread-h b/modules/pthread-h
new file mode 100644 (file)
index 0000000..370552a
--- /dev/null
@@ -0,0 +1,55 @@
+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
index 2ae39f497edd2363b48a3c55935623b9e8dc5efd..4e01c3033763c76737c2942ee5b583dd330416ee 100644 (file)
@@ -6,7 +6,7 @@ lib/pthread_mutex_timedlock.c
 m4/pthread_mutex_timedlock.m4
 
 Depends-on:
-pthread
+pthread-h
 nanosleep       [test $HAVE_PTHREAD_T = 1 && test $HAVE_PTHREAD_MUTEX_TIMEDLOCK = 0]
 
 configure.ac: