+2019-07-14 Bruno Haible <bruno@clisp.org>
+
+ pthread-mutex: New module.
+ * lib/pthread.in.h (pthread_mutexattr_destroy, pthread_mutexattr_init,
+ pthread_mutexattr_settype, pthread_mutex_destroy, pthread_mutex_init,
+ pthread_mutex_lock, pthread_mutex_trylock, pthread_mutex_timedlock,
+ pthread_mutex_unlock): Remove inline definitions.
+ * lib/pthread-mutex.c: New file.
+ * m4/pthread-mutex.m4: New file.
+ * modules/pthread-mutex: New file.
+ * doc/posix-functions/pthread_mutex_init.texi: Mention the new module.
+ * doc/posix-functions/pthread_mutexattr_init.texi: Likewise.
+ * doc/posix-functions/pthread_mutexattr_gettype.texi: Likewise.
+ * doc/posix-functions/pthread_mutexattr_settype.texi: Likewise.
+ * doc/posix-functions/pthread_mutexattr_getrobust.texi: Likewise.
+ * doc/posix-functions/pthread_mutexattr_setrobust.texi: Likewise.
+ * doc/posix-functions/pthread_mutexattr_destroy.texi: Likewise.
+ * doc/posix-functions/pthread_mutex_lock.texi: Likewise.
+ * doc/posix-functions/pthread_mutex_trylock.texi: Likewise.
+ * doc/posix-functions/pthread_mutex_timedlock.texi: Likewise.
+ * doc/posix-functions/pthread_mutex_unlock.texi: Likewise.
+ * doc/posix-functions/pthread_mutex_destroy.texi: Likewise.
+
2019-07-14 Bruno Haible <bruno@clisp.org>
pthread-once: New module.
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_destroy.html}
-Gnulib module: ---
+Gnulib module: pthread-mutex
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_mutex_init.html}
-Gnulib module: ---
+Gnulib module: pthread-mutex
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_mutex_lock.html}
-Gnulib module: ---
+Gnulib module: pthread-mutex
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
This function is missing on some platforms:
Mac OS X 10.5, FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, mingw, MSVC 14, Android 4.4.
But the provided replacement is just a dummy on some of these platforms:
-Minix 3.1.8, HP-UX 11, mingw, MSVC 14.
+Minix 3.1.8.
@end itemize
Portability problems not fixed by Gnulib:
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_trylock.html}
-Gnulib module: ---
+Gnulib module: pthread-mutex
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_mutex_unlock.html}
-Gnulib module: ---
+Gnulib module: pthread-mutex
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_mutexattr_destroy.html}
-Gnulib module: ---
+Gnulib module: pthread-mutex
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_mutexattr_getrobust.html}
-Gnulib module: ---
+Gnulib module: pthread-mutex
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+glibc 2.11, Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, Cygwin, mingw, MSVC 14, Android 9.0.
+But the provided replacement is just a dummy.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-glibc 2.11, Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, Cygwin, mingw, MSVC 14, Android 9.0.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_gettype.html}
-Gnulib module: ---
+Gnulib module: pthread-mutex
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_mutexattr_init.html}
-Gnulib module: ---
+Gnulib module: pthread-mutex
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_mutexattr_setrobust.html}
-Gnulib module: ---
+Gnulib module: pthread-mutex
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+glibc 2.11, Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, Cygwin, mingw, MSVC 14, Android 9.0.
+But the provided replacement is just a dummy.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-glibc 2.11, Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, Cygwin, mingw, MSVC 14, Android 9.0.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_settype.html}
-Gnulib module: ---
+Gnulib module: pthread-mutex
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 mutexes (locks).
+ 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-timedmutex.h"
+# include "windows-timedrecmutex.h"
+#else
+# include <stdlib.h>
+#endif
+
+#if ((defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS) || !HAVE_PTHREAD_H
+
+int
+pthread_mutexattr_init (pthread_mutexattr_t *attr)
+{
+ *attr = (PTHREAD_MUTEX_STALLED << 2) | PTHREAD_MUTEX_DEFAULT;
+ return 0;
+}
+
+int
+pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int *typep)
+{
+ *typep = *attr & (PTHREAD_MUTEX_DEFAULT | PTHREAD_MUTEX_NORMAL
+ | PTHREAD_MUTEX_ERRORCHECK | PTHREAD_MUTEX_RECURSIVE);
+ return 0;
+}
+
+int
+pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type)
+{
+ if (!(type == PTHREAD_MUTEX_DEFAULT
+ || type == PTHREAD_MUTEX_NORMAL
+ || type == PTHREAD_MUTEX_ERRORCHECK
+ || type == PTHREAD_MUTEX_RECURSIVE))
+ return EINVAL;
+ *attr ^= (*attr ^ type)
+ & (PTHREAD_MUTEX_DEFAULT | PTHREAD_MUTEX_NORMAL
+ | PTHREAD_MUTEX_ERRORCHECK | PTHREAD_MUTEX_RECURSIVE);
+ return 0;
+}
+
+int
+pthread_mutexattr_getrobust (const pthread_mutexattr_t *attr, int *robustp)
+{
+ *robustp = (*attr >> 2) & (PTHREAD_MUTEX_STALLED | PTHREAD_MUTEX_ROBUST);
+ return 0;
+}
+
+int
+pthread_mutexattr_setrobust (pthread_mutexattr_t *attr, int robust)
+{
+ if (!(robust == PTHREAD_MUTEX_STALLED || robust == PTHREAD_MUTEX_ROBUST))
+ return EINVAL;
+ *attr ^= (*attr ^ (robust << 2))
+ & ((PTHREAD_MUTEX_STALLED | PTHREAD_MUTEX_ROBUST) << 2);
+ return 0;
+}
+
+int
+pthread_mutexattr_destroy (pthread_mutexattr_t *attr _GL_UNUSED)
+{
+ return 0;
+}
+
+#endif
+
+#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS
+/* Use Windows threads. */
+
+int
+pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
+{
+ /* This implementation does not support PTHREAD_MUTEX_ERRORCHECK
+ and ignores the 'robust' attribute. */
+ if (attr != NULL
+ && (*attr & (PTHREAD_MUTEX_DEFAULT | PTHREAD_MUTEX_NORMAL
+ | PTHREAD_MUTEX_ERRORCHECK | PTHREAD_MUTEX_RECURSIVE))
+ == PTHREAD_MUTEX_RECURSIVE)
+ {
+ mutex->type = 2;
+ return glwthread_timedrecmutex_init (&mutex->u.u_timedrecmutex);
+ }
+ else
+ {
+ mutex->type = 1;
+ return glwthread_timedmutex_init (&mutex->u.u_timedmutex);
+ }
+}
+
+int
+pthread_mutex_lock (pthread_mutex_t *mutex)
+{
+ switch (mutex->type)
+ {
+ case 1:
+ return glwthread_timedmutex_lock (&mutex->u.u_timedmutex);
+ case 2:
+ return glwthread_timedrecmutex_lock (&mutex->u.u_timedrecmutex);
+ default:
+ abort ();
+ }
+}
+
+int
+pthread_mutex_trylock (pthread_mutex_t *mutex)
+{
+ switch (mutex->type)
+ {
+ case 1:
+ return glwthread_timedmutex_trylock (&mutex->u.u_timedmutex);
+ case 2:
+ return glwthread_timedrecmutex_trylock (&mutex->u.u_timedrecmutex);
+ default:
+ abort ();
+ }
+}
+
+int
+pthread_mutex_timedlock (pthread_mutex_t *mutex, const struct timespec *abstime)
+{
+ switch (mutex->type)
+ {
+ case 1:
+ return glwthread_timedmutex_timedlock (&mutex->u.u_timedmutex, abstime);
+ case 2:
+ return glwthread_timedrecmutex_timedlock (&mutex->u.u_timedrecmutex,
+ abstime);
+ default:
+ abort ();
+ }
+}
+
+int
+pthread_mutex_unlock (pthread_mutex_t *mutex)
+{
+ switch (mutex->type)
+ {
+ case 1:
+ return glwthread_timedmutex_unlock (&mutex->u.u_timedmutex);
+ case 2:
+ return glwthread_timedrecmutex_unlock (&mutex->u.u_timedrecmutex);
+ default:
+ abort ();
+ }
+}
+
+int
+pthread_mutex_destroy (pthread_mutex_t *mutex)
+{
+ switch (mutex->type)
+ {
+ case 1:
+ return glwthread_timedmutex_destroy (&mutex->u.u_timedmutex);
+ case 2:
+ return glwthread_timedrecmutex_destroy (&mutex->u.u_timedrecmutex);
+ default:
+ abort ();
+ }
+}
+
+#elif HAVE_PTHREAD_H
+/* Provide workarounds for POSIX threads. */
+
+/* pthread_mutex_timedlock is defined by the 'pthread_mutex_timedlock'
+ module. */
+
+#else
+/* Provide a dummy implementation for single-threaded applications. */
+
+int
+pthread_mutex_init (pthread_mutex_t *mutex _GL_UNUSED,
+ const pthread_mutexattr_t *attr _GL_UNUSED)
+{
+ /* MUTEX is never seriously used. */
+ return 0;
+}
+
+int
+pthread_mutex_lock (pthread_mutex_t *mutex _GL_UNUSED)
+{
+ /* There is only one thread, so it always gets the lock. This
+ implementation does not support PTHREAD_MUTEX_ERRORCHECK. */
+ return 0;
+}
+
+int
+pthread_mutex_trylock (pthread_mutex_t *mutex _GL_UNUSED)
+{
+ /* There is only one thread, so it always gets the lock. This
+ implementation does not support PTHREAD_MUTEX_ERRORCHECK. */
+ return 0;
+}
+
+int
+pthread_mutex_timedlock (pthread_mutex_t *mutex _GL_UNUSED,
+ const struct timespec *abstime _GL_UNUSED)
+{
+ /* There is only one thread, so it always gets the lock. This
+ implementation does not support PTHREAD_MUTEX_ERRORCHECK. */
+ return 0;
+}
+
+int
+pthread_mutex_unlock (pthread_mutex_t *mutex _GL_UNUSED)
+{
+ /* There is only one thread, so it always unlocks successfully.
+ This implementation does not support robust mutexes or
+ PTHREAD_MUTEX_ERRORCHECK. */
+ return 0;
+}
+
+int
+pthread_mutex_destroy (pthread_mutex_t *mutex _GL_UNUSED)
+{
+ /* MUTEX is never seriously used. */
+ return 0;
+}
+
+#endif
return 0;
}
-_GL_PTHREAD_INLINE int
-pthread_mutexattr_destroy (pthread_mutexattr_t *attr)
-{
- return 0;
-}
-
-_GL_PTHREAD_INLINE int
-pthread_mutexattr_init (pthread_mutexattr_t *attr)
-{
- return 0;
-}
-
-_GL_PTHREAD_INLINE int
-pthread_mutexattr_settype (pthread_mutexattr_t *attr, int attr_type)
-{
- return 0;
-}
-
-_GL_PTHREAD_INLINE int
-pthread_mutex_destroy (pthread_mutex_t *mutex)
-{
- /* MUTEX is never seriously used. */
- return 0;
-}
-
-_GL_PTHREAD_INLINE int
-pthread_mutex_init (pthread_mutex_t *restrict mutex,
- pthread_mutexattr_t const *restrict attr)
-{
- /* MUTEX is never seriously used. */
- return 0;
-}
-
-_GL_PTHREAD_INLINE int
-pthread_mutex_lock (pthread_mutex_t *mutex)
-{
- /* There is only one thread, so it always gets the lock. This
- implementation does not support PTHREAD_MUTEX_ERRORCHECK. */
- return 0;
-}
-
-_GL_PTHREAD_INLINE int
-pthread_mutex_trylock (pthread_mutex_t *mutex)
-{
- return pthread_mutex_lock (mutex);
-}
-
-_GL_PTHREAD_INLINE int
-pthread_mutex_timedlock (pthread_mutex_t *mutex, const struct timespec *abstime)
-{
- /* There is only one thread, so it always gets the lock. This
- implementation does not support PTHREAD_MUTEX_ERRORCHECK. */
- return 0;
-}
-
-_GL_PTHREAD_INLINE int
-pthread_mutex_unlock (pthread_mutex_t *mutex)
-{
- /* There is only one thread, so it always unlocks successfully.
- This implementation does not support robust mutexes or
- PTHREAD_MUTEX_ERRORCHECK. */
- return 0;
-}
-
# define GNULIB_defined_pthread_functions 1
# endif
--- /dev/null
+# pthread-mutex.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_MUTEX],
+[
+ 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_MUTEX_INIT=1
+ REPLACE_PTHREAD_MUTEXATTR_INIT=1
+ REPLACE_PTHREAD_MUTEXATTR_GETTYPE=1
+ REPLACE_PTHREAD_MUTEXATTR_SETTYPE=1
+ REPLACE_PTHREAD_MUTEXATTR_GETROBUST=1
+ REPLACE_PTHREAD_MUTEXATTR_SETROBUST=1
+ REPLACE_PTHREAD_MUTEXATTR_DESTROY=1
+ REPLACE_PTHREAD_MUTEX_LOCK=1
+ REPLACE_PTHREAD_MUTEX_TRYLOCK=1
+ REPLACE_PTHREAD_MUTEX_TIMEDLOCK=1
+ REPLACE_PTHREAD_MUTEX_UNLOCK=1
+ REPLACE_PTHREAD_MUTEX_DESTROY=1
+ else
+ if test $HAVE_PTHREAD_H = 0; then
+ HAVE_PTHREAD_MUTEX_INIT=0
+ HAVE_PTHREAD_MUTEXATTR_INIT=0
+ HAVE_PTHREAD_MUTEXATTR_GETTYPE=0
+ HAVE_PTHREAD_MUTEXATTR_SETTYPE=0
+ HAVE_PTHREAD_MUTEXATTR_GETROBUST=0
+ HAVE_PTHREAD_MUTEXATTR_SETROBUST=0
+ HAVE_PTHREAD_MUTEXATTR_DESTROY=0
+ HAVE_PTHREAD_MUTEX_LOCK=0
+ HAVE_PTHREAD_MUTEX_TRYLOCK=0
+ dnl HAVE_PTHREAD_MUTEX_TIMEDLOCK is set in pthread_mutex_timedlock.m4.
+ HAVE_PTHREAD_MUTEX_UNLOCK=0
+ HAVE_PTHREAD_MUTEX_DESTROY=0
+ fi
+ fi
+])
--- /dev/null
+Description:
+POSIX mutexes (locks).
+
+Files:
+lib/pthread-mutex.c
+m4/pthread-mutex.m4
+
+Depends-on:
+pthread-h
+pthread_mutex_timedlock [test $gl_threads_api = posix]
+windows-timedmutex [test $gl_threads_api = windows]
+windows-timedrecmutex [test $gl_threads_api = windows]
+
+configure.ac:
+gl_PTHREAD_MUTEX
+if test $HAVE_PTHREAD_MUTEX_INIT = 0 || test $REPLACE_PTHREAD_MUTEX_INIT = 1; then
+ AC_LIBOBJ([pthread-mutex])
+fi
+gl_PTHREAD_MODULE_INDICATOR([pthread-mutex])
+
+Makefile.am:
+
+Include:
+<pthread.h>
+
+Link:
+$(LIBTHREAD) or $(LIBMULTITHREAD)
+
+License:
+LGPLv2+
+
+Maintainer:
+all