Here's a fix, to make it compile on mingw when module 'pthread-h' is used *without* the modules 'pthread-thread', ..., 'pthread-spin'.
2019-07-24 Bruno Haible <br...@clisp.org> pthread-h: Fix definitions of types and macros on mingw. * lib/pthread.in.h (pthread_t, pthread_attr_t, PTHREAD_CREATE_JOINABLE, PTHREAD_CREATE_DETACHED): Define also when module 'pthread-thread' is not in use. (pthread_once_t, PTHREAD_ONCE_INIT): Define also when module 'pthread-once' is not in use. (pthread_mutex_t, pthread_mutexattr_t, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_DEFAULT, PTHREAD_MUTEX_NORMAL, PTHREAD_MUTEX_ERRORCHECK, PTHREAD_MUTEX_RECURSIVE): Define also when module 'pthread-mutex' is not in use. (pthread_rwlock_t, pthread_rwlockattr_t, PTHREAD_RWLOCK_INITIALIZER): Define also when module 'pthread-rwlock' is not in use. (pthread_cond_t, pthread_condattr_t, PTHREAD_COND_INITIALIZER): Define also when module 'pthread-cond' is not in use. (pthread_key_t, PTHREAD_DESTRUCTOR_ITERATIONS): Define also when module 'pthread-tss' is not in use. (pthread_spinlock_t): Define also when module 'pthread-spin' is not in use. diff --git a/lib/pthread.in.h b/lib/pthread.in.h index c8963c8..4fc22bf 100644 --- a/lib/pthread.in.h +++ b/lib/pthread.in.h @@ -79,16 +79,28 @@ /* =========== Thread types and macros =========== */ -#if @GNULIB_PTHREAD_THREAD@ && (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS -# include "windows-thread.h" -# if @HAVE_PTHREAD_T@ -# define pthread_t rpl_pthread_t -# define pthread_attr_t rpl_pthread_attr_t -# endif -# if !GNULIB_defined_pthread_thread_types +#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS +# if @GNULIB_PTHREAD_THREAD@ +# include "windows-thread.h" +# if @HAVE_PTHREAD_T@ +# define pthread_t rpl_pthread_t +# define pthread_attr_t rpl_pthread_attr_t +# endif +# if !GNULIB_defined_pthread_thread_types typedef glwthread_thread_t pthread_t; typedef unsigned int pthread_attr_t; -# define GNULIB_defined_pthread_thread_types 1 +# define GNULIB_defined_pthread_thread_types 1 +# endif +# else +# if @HAVE_PTHREAD_T@ +# define pthread_t rpl_pthread_t +# define pthread_attr_t rpl_pthread_attr_t +# endif +# if !GNULIB_defined_pthread_thread_types +typedef int pthread_t; +typedef unsigned int pthread_attr_t; +# define GNULIB_defined_pthread_thread_types 1 +# endif # endif # undef PTHREAD_CREATE_JOINABLE # undef PTHREAD_CREATE_DETACHED @@ -110,17 +122,29 @@ typedef unsigned int pthread_attr_t; /* =========== Once-only control (initialization) types and macros ========== */ -#if @GNULIB_PTHREAD_ONCE@ && (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS -# include "windows-once.h" -# if @HAVE_PTHREAD_T@ -# define pthread_once_t rpl_pthread_once_t -# endif -# if !GNULIB_defined_pthread_once_types +#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS +# if @GNULIB_PTHREAD_ONCE@ +# include "windows-once.h" +# if @HAVE_PTHREAD_T@ +# define pthread_once_t rpl_pthread_once_t +# endif +# if !GNULIB_defined_pthread_once_types typedef glwthread_once_t pthread_once_t; -# define GNULIB_defined_pthread_once_types 1 +# define GNULIB_defined_pthread_once_types 1 +# endif +# undef PTHREAD_ONCE_INIT +# define PTHREAD_ONCE_INIT GLWTHREAD_ONCE_INIT +# else +# if @HAVE_PTHREAD_T@ +# define pthread_once_t rpl_pthread_once_t +# endif +# if !GNULIB_defined_pthread_once_types +typedef int pthread_once_t; +# define GNULIB_defined_pthread_once_types 1 +# endif +# undef PTHREAD_ONCE_INIT +# define PTHREAD_ONCE_INIT { 0 } # endif -# undef PTHREAD_ONCE_INIT -# define PTHREAD_ONCE_INIT GLWTHREAD_ONCE_INIT #else # if !@HAVE_PTHREAD_T@ # if !GNULIB_defined_pthread_once_types @@ -134,14 +158,15 @@ typedef int pthread_once_t; /* =========== Mutex types and macros =========== */ -#if @GNULIB_PTHREAD_MUTEX@ && (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS -# include "windows-timedmutex.h" -# include "windows-timedrecmutex.h" -# if @HAVE_PTHREAD_T@ -# define pthread_mutex_t rpl_pthread_mutex_t -# define pthread_mutexattr_t rpl_pthread_mutexattr_t -# endif -# if !GNULIB_defined_pthread_mutex_types +#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS +# if @GNULIB_PTHREAD_MUTEX@ +# include "windows-timedmutex.h" +# include "windows-timedrecmutex.h" +# if @HAVE_PTHREAD_T@ +# define pthread_mutex_t rpl_pthread_mutex_t +# define pthread_mutexattr_t rpl_pthread_mutexattr_t +# endif +# if !GNULIB_defined_pthread_mutex_types typedef struct { int type; @@ -154,10 +179,23 @@ typedef struct } pthread_mutex_t; typedef unsigned int pthread_mutexattr_t; -# define GNULIB_defined_pthread_mutex_types 1 +# define GNULIB_defined_pthread_mutex_types 1 +# endif +# undef PTHREAD_MUTEX_INITIALIZER +# define PTHREAD_MUTEX_INITIALIZER { 1, { GLWTHREAD_TIMEDMUTEX_INIT } } +# else +# if @HAVE_PTHREAD_T@ +# define pthread_mutex_t rpl_pthread_mutex_t +# define pthread_mutexattr_t rpl_pthread_mutexattr_t +# endif +# if !GNULIB_defined_pthread_mutex_types +typedef int pthread_mutex_t; +typedef unsigned int pthread_mutexattr_t; +# define GNULIB_defined_pthread_mutex_types 1 +# endif +# undef PTHREAD_MUTEX_INITIALIZER +# define PTHREAD_MUTEX_INITIALIZER { 0 } # endif -# undef PTHREAD_MUTEX_INITIALIZER -# define PTHREAD_MUTEX_INITIALIZER { 1, { GLWTHREAD_TIMEDMUTEX_INIT } } # undef PTHREAD_MUTEX_DEFAULT # undef PTHREAD_MUTEX_NORMAL # undef PTHREAD_MUTEX_ERRORCHECK @@ -194,19 +232,33 @@ typedef unsigned int pthread_mutexattr_t; /* =========== Read-write lock types and macros =========== */ -#if @GNULIB_PTHREAD_RWLOCK@ && (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS -# include "windows-timedrwlock.h" -# if @HAVE_PTHREAD_T@ -# define pthread_rwlock_t rpl_pthread_rwlock_t -# define pthread_rwlockattr_t rpl_pthread_rwlockattr_t -# endif -# if !GNULIB_defined_pthread_rwlock_types +#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS +# if @GNULIB_PTHREAD_RWLOCK@ +# include "windows-timedrwlock.h" +# if @HAVE_PTHREAD_T@ +# define pthread_rwlock_t rpl_pthread_rwlock_t +# define pthread_rwlockattr_t rpl_pthread_rwlockattr_t +# endif +# if !GNULIB_defined_pthread_rwlock_types typedef glwthread_timedrwlock_t pthread_rwlock_t; typedef unsigned int pthread_rwlockattr_t; -# define GNULIB_defined_pthread_rwlock_types 1 +# define GNULIB_defined_pthread_rwlock_types 1 +# endif +# undef PTHREAD_RWLOCK_INITIALIZER +# define PTHREAD_RWLOCK_INITIALIZER GLWTHREAD_TIMEDRWLOCK_INIT +# else +# if @HAVE_PTHREAD_T@ +# define pthread_rwlock_t rpl_pthread_rwlock_t +# define pthread_rwlockattr_t rpl_pthread_rwlockattr_t +# endif +# if !GNULIB_defined_pthread_rwlock_types +typedef int pthread_rwlock_t; +typedef unsigned int pthread_rwlockattr_t; +# define GNULIB_defined_pthread_rwlock_types 1 +# endif +# undef PTHREAD_RWLOCK_INITIALIZER +# define PTHREAD_RWLOCK_INITIALIZER { 0 } # endif -# undef PTHREAD_RWLOCK_INITIALIZER -# define PTHREAD_RWLOCK_INITIALIZER GLWTHREAD_TIMEDRWLOCK_INIT #elif @GNULIB_PTHREAD_RWLOCK@ && @REPLACE_PTHREAD_RWLOCK_INIT@ /* i.e. PTHREAD_RWLOCK_UNIMPLEMENTED */ # if @HAVE_PTHREAD_T@ # define pthread_rwlock_t rpl_pthread_rwlock_t @@ -242,19 +294,33 @@ typedef unsigned int pthread_rwlockattr_t; /* =========== Condition variable types and macros =========== */ -#if @GNULIB_PTHREAD_COND@ && (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS -# include "windows-cond.h" -# if @HAVE_PTHREAD_T@ -# define pthread_cond_t rpl_pthread_cond_t -# define pthread_condattr_t rpl_pthread_condattr_t -# endif -# if !GNULIB_defined_pthread_cond_types +#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS +# if @GNULIB_PTHREAD_COND@ +# include "windows-cond.h" +# if @HAVE_PTHREAD_T@ +# define pthread_cond_t rpl_pthread_cond_t +# define pthread_condattr_t rpl_pthread_condattr_t +# endif +# if !GNULIB_defined_pthread_cond_types typedef glwthread_cond_t pthread_cond_t; typedef unsigned int pthread_condattr_t; -# define GNULIB_defined_pthread_cond_types 1 +# define GNULIB_defined_pthread_cond_types 1 +# endif +# undef PTHREAD_COND_INITIALIZER +# define PTHREAD_COND_INITIALIZER GLWTHREAD_COND_INIT +# else +# if @HAVE_PTHREAD_T@ +# define pthread_cond_t rpl_pthread_cond_t +# define pthread_condattr_t rpl_pthread_condattr_t +# endif +# if !GNULIB_defined_pthread_cond_types +typedef int pthread_cond_t; +typedef unsigned int pthread_condattr_t; +# define GNULIB_defined_pthread_cond_types 1 +# endif +# undef PTHREAD_COND_INITIALIZER +# define PTHREAD_COND_INITIALIZER { 0 } # endif -# undef PTHREAD_COND_INITIALIZER -# define PTHREAD_COND_INITIALIZER GLWTHREAD_COND_INIT #else # if !@HAVE_PTHREAD_T@ # if !GNULIB_defined_pthread_cond_types @@ -269,17 +335,29 @@ typedef unsigned int pthread_condattr_t; /* =========== Thread-specific storage types and macros =========== */ -#if @GNULIB_PTHREAD_TSS@ && (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS -# include "windows-tls.h" -# if @HAVE_PTHREAD_T@ -# define pthread_key_t rpl_pthread_key_t -# endif -# if !GNULIB_defined_pthread_tss_types +#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS +# if @GNULIB_PTHREAD_TSS@ +# include "windows-tls.h" +# if @HAVE_PTHREAD_T@ +# define pthread_key_t rpl_pthread_key_t +# endif +# if !GNULIB_defined_pthread_tss_types typedef glwthread_tls_key_t pthread_key_t; -# define GNULIB_defined_pthread_tss_types 1 +# define GNULIB_defined_pthread_tss_types 1 +# endif +# undef PTHREAD_DESTRUCTOR_ITERATIONS +# define PTHREAD_DESTRUCTOR_ITERATIONS GLWTHREAD_DESTRUCTOR_ITERATIONS +# else +# if @HAVE_PTHREAD_T@ +# define pthread_key_t rpl_pthread_key_t +# endif +# if !GNULIB_defined_pthread_tss_types +typedef void ** pthread_key_t; +# define GNULIB_defined_pthread_tss_types 1 +# endif +# undef PTHREAD_DESTRUCTOR_ITERATIONS +# define PTHREAD_DESTRUCTOR_ITERATIONS 0 # endif -# undef PTHREAD_DESTRUCTOR_ITERATIONS -# define PTHREAD_DESTRUCTOR_ITERATIONS GLWTHREAD_DESTRUCTOR_ITERATIONS #else # if !@HAVE_PTHREAD_T@ # if !GNULIB_defined_pthread_tss_types @@ -293,14 +371,24 @@ typedef void ** pthread_key_t; /* =========== Spinlock types and macros =========== */ -#if @GNULIB_PTHREAD_SPIN@ && (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS -# include "windows-spin.h" -# if @HAVE_PTHREAD_T@ -# define pthread_spinlock_t rpl_pthread_spinlock_t -# endif -# if !GNULIB_defined_pthread_spin_types +#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS +# if @GNULIB_PTHREAD_SPIN@ +# include "windows-spin.h" +# if @HAVE_PTHREAD_T@ +# define pthread_spinlock_t rpl_pthread_spinlock_t +# endif +# if !GNULIB_defined_pthread_spin_types typedef glwthread_spinlock_t pthread_spinlock_t; -# define GNULIB_defined_pthread_spin_types 1 +# define GNULIB_defined_pthread_spin_types 1 +# endif +# else +# if @HAVE_PTHREAD_T@ +# define pthread_spinlock_t rpl_pthread_spinlock_t +# endif +# if !GNULIB_defined_pthread_spin_types +typedef pthread_mutex_t pthread_spinlock_t; +# define GNULIB_defined_pthread_spin_types 1 +# endif # endif # undef PTHREAD_PROCESS_PRIVATE # undef PTHREAD_PROCESS_SHARED