From c1c1d4f6239eece0857e8c6465e92c0806a7c147 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 15 Jul 2019 02:36:13 +0200 Subject: [PATCH] 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 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 | 18 +++++ lib/pthread.in.h | 16 +++-- m4/pthread.m4 | 114 -------------------------------- m4/pthread_h.m4 | 95 ++++++++++++++++++++++++++ m4/pthread_mutex_timedlock.m4 | 4 +- modules/pthread | 42 +----------- modules/pthread-h | 55 +++++++++++++++ modules/pthread_mutex_timedlock | 2 +- 8 files changed, 186 insertions(+), 160 deletions(-) delete mode 100644 m4/pthread.m4 create mode 100644 m4/pthread_h.m4 create mode 100644 modules/pthread-h diff --git a/ChangeLog b/ChangeLog index db2da4483d..bab6808e18 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2019-07-14 Bruno Haible + + 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 + 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 sched_yield: New module. diff --git a/lib/pthread.in.h b/lib/pthread.in.h index cd3cf1fd03..1801dbe2f5 100644 --- a/lib/pthread.in.h +++ b/lib/pthread.in.h @@ -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 index bccac96206..0000000000 --- a/m4/pthread.m4 +++ /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 - AC_CACHE_CHECK([whether pollutes the namespace], - [gl_cv_header_pthread_h_pollution], - [AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM( - [[#include - #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 - #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_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 - 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 index 0000000000..d55a471b39 --- /dev/null +++ b/m4/pthread_h.m4 @@ -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 + #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_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 + 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]) +]) diff --git a/m4/pthread_mutex_timedlock.m4 b/m4/pthread_mutex_timedlock.m4 index 664670f2bb..5cd9cbd7a5 100644 --- a/m4/pthread_mutex_timedlock.m4 +++ b/m4/pthread_mutex_timedlock.m4 @@ -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 ]]) diff --git a/modules/pthread b/modules/pthread index 81e2aad384..9e5a7340a4 100644 --- a/modules/pthread +++ b/modules/pthread @@ -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 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: @@ -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 index 0000000000..370552a031 --- /dev/null +++ b/modules/pthread-h @@ -0,0 +1,55 @@ +Description: +A POSIX-like . + +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 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: + + +Link: +$(LIB_PTHREAD) + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/pthread_mutex_timedlock b/modules/pthread_mutex_timedlock index 2ae39f497e..4e01c30337 100644 --- a/modules/pthread_mutex_timedlock +++ b/modules/pthread_mutex_timedlock @@ -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: -- 2.39.5