+2019-07-14 Bruno Haible <bruno@clisp.org>
+
+ pthread-cond: New module.
+ * lib/pthread.in.h (pthread_cond_destroy, pthread_cond_init,
+ pthread_cond_signal, pthread_cond_wait): Remove inline definitions.
+ * lib/pthread-cond.c: New file.
+ * m4/pthread-cond.m4: New file.
+ * modules/pthread-cond: New file.
+ * doc/posix-functions/pthread_cond_init.texi: Mention the new module.
+ * doc/posix-functions/pthread_condattr_init.texi: Likewise.
+ * doc/posix-functions/pthread_condattr_destroy.texi: Likewise.
+ * doc/posix-functions/pthread_cond_wait.texi: Likewise.
+ * doc/posix-functions/pthread_cond_timedwait.texi: Likewise.
+ * doc/posix-functions/pthread_cond_signal.texi: Likewise.
+ * doc/posix-functions/pthread_cond_broadcast.texi: Likewise.
+ * doc/posix-functions/pthread_cond_destroy.texi: Likewise.
+
2019-07-14 Bruno Haible <bruno@clisp.org>
pthread-rwlock: New module.
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_broadcast.html}
-Gnulib module: ---
+Gnulib module: pthread-cond
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, HP-UX 11, mingw, MSVC 14.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_destroy.html}
-Gnulib module: ---
+Gnulib module: pthread-cond
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, HP-UX 11, mingw, MSVC 14.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_init.html}
-Gnulib module: ---
+Gnulib module: pthread-cond
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, mingw, MSVC 14.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_signal.html}
-Gnulib module: ---
+Gnulib module: pthread-cond
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, mingw, MSVC 14.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_timedwait.html}
-Gnulib module: ---
+Gnulib module: pthread-cond
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, HP-UX 11, mingw, MSVC 14.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_wait.html}
-Gnulib module: ---
+Gnulib module: pthread-cond
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, mingw, MSVC 14.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_condattr_destroy.html}
-Gnulib module: ---
+Gnulib module: pthread-cond
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, HP-UX 11, mingw, MSVC 14.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_condattr_init.html}
-Gnulib module: ---
+Gnulib module: pthread-cond
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, HP-UX 11, mingw, MSVC 14.
@end itemize
--- /dev/null
+/* POSIX condition variables.
+ Copyright (C) 2010-2019 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <https://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert, 2010, and Bruno Haible <bruno@clisp.org>, 2019. */
+
+#include <config.h>
+
+/* Specification. */
+#include <pthread.h>
+
+#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS
+# include "windows-thread.h"
+#else
+# include <errno.h>
+# include <limits.h>
+# include <sys/time.h>
+# include <time.h>
+#endif
+
+#if ((defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS) || !HAVE_PTHREAD_H
+
+int
+pthread_condattr_init (pthread_condattr_t *attr)
+{
+ *attr = 0;
+ return 0;
+}
+
+int
+pthread_condattr_destroy (pthread_condattr_t *attr _GL_UNUSED)
+{
+ return 0;
+}
+
+#endif
+
+#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS
+/* Use Windows threads. */
+
+int
+pthread_cond_init (pthread_cond_t *cond,
+ const pthread_condattr_t *attr _GL_UNUSED)
+{
+ return glwthread_cond_init (cond);
+}
+
+int
+pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)
+{
+ return glwthread_cond_wait (cond, mutex,
+ (int (*) (void *)) pthread_mutex_lock,
+ (int (*) (void *)) pthread_mutex_unlock);
+}
+
+int
+pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
+ const struct timespec *abstime)
+{
+ return glwthread_cond_timedwait (cond, mutex,
+ (int (*) (void *)) pthread_mutex_lock,
+ (int (*) (void *)) pthread_mutex_unlock,
+ abstime);
+}
+
+int
+pthread_cond_signal (pthread_cond_t *cond)
+{
+ return glwthread_cond_signal (cond);
+}
+
+int
+pthread_cond_broadcast (pthread_cond_t *cond)
+{
+ return glwthread_cond_broadcast (cond);
+}
+
+int
+pthread_cond_destroy (pthread_cond_t *cond)
+{
+ return glwthread_cond_destroy (cond);
+}
+
+#elif HAVE_PTHREAD_H
+/* Provide workarounds for POSIX threads. */
+
+#else
+/* Provide a dummy implementation for single-threaded applications. */
+
+int
+pthread_cond_init (pthread_cond_t *cond _GL_UNUSED,
+ const pthread_condattr_t *attr _GL_UNUSED)
+{
+ /* COND is never seriously used. */
+ return 0;
+}
+
+int
+pthread_cond_wait (pthread_cond_t *cond _GL_UNUSED,
+ pthread_mutex_t *mutex _GL_UNUSED)
+{
+ /* No other thread can signal this condition variable.
+ Wait endlessly. */
+ for (;;)
+ {
+ struct timespec duration;
+
+ duration.tv_sec = 86400;
+ duration.tv_usec = 0;
+ nanosleep (&duration, NULL);
+ }
+}
+
+int
+pthread_cond_timedwait (pthread_cond_t *cond _GL_UNUSED,
+ pthread_mutex_t *mutex _GL_UNUSED,
+ const struct timespec *abstime)
+{
+ /* No other thread can signal this condition variable.
+ Wait until ABSTIME is reached. */
+ for (;;)
+ {
+ struct timeval currtime;
+ unsigned long remaining;
+ struct timespec duration;
+
+ gettimeofday (&currtime, NULL);
+
+ if (currtime.tv_sec > abstime->tv_sec)
+ remaining = 0;
+ else
+ {
+ unsigned long seconds = abstime->tv_sec - currtime.tv_sec;
+ remaining = seconds * 1000000000;
+ if (remaining / 1000000000 != seconds) /* overflow? */
+ remaining = ULONG_MAX;
+ else
+ {
+ long nanoseconds =
+ abstime->tv_nsec - currtime.tv_usec * 1000;
+ if (nanoseconds >= 0)
+ {
+ remaining += nanoseconds;
+ if (remaining < nanoseconds) /* overflow? */
+ remaining = ULONG_MAX;
+ }
+ else
+ {
+ if (remaining >= - nanoseconds)
+ remaining -= (- nanoseconds);
+ else
+ remaining = 0;
+ }
+ }
+ }
+ if (remaining == 0)
+ return ETIMEDOUT;
+
+ /* Sleep up to REMAINING ns. */
+ duration.tv_sec = remaining / 1000000000;
+ duration.tv_nsec = remaining % 1000000000;
+ nanosleep (&duration, NULL);
+ }
+}
+
+int
+pthread_cond_signal (pthread_cond_t *cond _GL_UNUSED)
+{
+ /* No threads can currently be blocked on COND. */
+ return 0;
+}
+
+int
+pthread_cond_broadcast (pthread_cond_t *cond _GL_UNUSED)
+{
+ /* No threads can currently be blocked on COND. */
+ return 0;
+}
+
+int
+pthread_cond_destroy (pthread_cond_t *cond _GL_UNUSED)
+{
+ /* COND is never seriously used. */
+ return 0;
+}
+
+#endif
#endif
-#if ! @HAVE_PTHREAD_T@
-
-# if @GNULIB_PTHREAD@
-
-# if !GNULIB_defined_pthread_functions
-
-/* Provide substitutes for the thread functions that should work
- adequately on a single-threaded implementation, where
- pthread_create always fails. The goal is to let programs compile
- on non-pthread hosts with minimal runtime overhead.
-
- Omit interfaces that have not been analyzed and for which we do not
- know what to do, so that they elicit a compile-time error for
- now. */
-
-_GL_PTHREAD_INLINE int
-pthread_cond_destroy (pthread_cond_t *cond)
-{
- /* COND is never seriously used. */
- return 0;
-}
-
-_GL_PTHREAD_INLINE int
-pthread_cond_init (pthread_cond_t *restrict cond,
- pthread_condattr_t const *restrict attr)
-{
- /* COND is never seriously used. */
- return 0;
-}
-
-_GL_PTHREAD_INLINE int
-pthread_cond_signal (pthread_cond_t *cond)
-{
- /* No threads can currently be blocked on COND. */
- return 0;
-}
-
-_GL_PTHREAD_INLINE int
-pthread_cond_wait (pthread_cond_t *restrict cond,
- pthread_mutex_t *restrict mutex)
-{
- /* Properly-written applications never come here. */
- abort ();
- return 0;
-}
-
-# define GNULIB_defined_pthread_functions 1
-# endif
-
-# endif
-
-#endif
-
#if ! @HAVE_PTHREAD_SPINLOCK_T@
# if @GNULIB_PTHREAD@
--- /dev/null
+# pthread-cond.m4 serial 1
+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,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_PTHREAD_COND],
+[
+ AC_REQUIRE([gl_PTHREAD_H])
+ AC_REQUIRE([AC_CANONICAL_HOST])
+
+ if { case "$host_os" in mingw*) true;; *) false;; esac; } \
+ && test $gl_threads_api = windows; then
+ dnl Choose function names that don't conflict with the mingw-w64 winpthreads
+ dnl library.
+ REPLACE_PTHREAD_COND_INIT=1
+ REPLACE_PTHREAD_CONDATTR_INIT=1
+ REPLACE_PTHREAD_CONDATTR_DESTROY=1
+ REPLACE_PTHREAD_COND_WAIT=1
+ REPLACE_PTHREAD_COND_TIMEDWAIT=1
+ REPLACE_PTHREAD_COND_SIGNAL=1
+ REPLACE_PTHREAD_COND_BROADCAST=1
+ REPLACE_PTHREAD_COND_DESTROY=1
+ else
+ if test $HAVE_PTHREAD_H = 0; then
+ HAVE_PTHREAD_COND_INIT=1
+ HAVE_PTHREAD_CONDATTR_INIT=1
+ HAVE_PTHREAD_CONDATTR_DESTROY=1
+ HAVE_PTHREAD_COND_WAIT=1
+ HAVE_PTHREAD_COND_TIMEDWAIT=1
+ HAVE_PTHREAD_COND_SIGNAL=1
+ HAVE_PTHREAD_COND_BROADCAST=1
+ HAVE_PTHREAD_COND_DESTROY=1
+ fi
+ fi
+])
--- /dev/null
+Description:
+POSIX condition variables.
+
+Files:
+lib/pthread-cond.c
+m4/pthread-cond.m4
+
+Depends-on:
+pthread-h
+windows-cond [test $gl_threads_api = windows]
+pthread-mutex [test $gl_threads_api = windows]
+
+configure.ac:
+gl_PTHREAD_COND
+if test $HAVE_PTHREAD_COND_INIT = 0 || test $REPLACE_PTHREAD_COND_INIT = 1; then
+ AC_LIBOBJ([pthread-cond])
+fi
+gl_PTHREAD_MODULE_INDICATOR([pthread-cond])
+
+Makefile.am:
+
+Include:
+<pthread.h>
+
+Link:
+$(LIBMULTITHREAD)
+
+License:
+LGPLv2+
+
+Maintainer:
+all