]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
pthread-mutex: New module.
authorBruno Haible <bruno@clisp.org>
Mon, 15 Jul 2019 00:37:44 +0000 (02:37 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 15 Jul 2019 00:37:44 +0000 (02:37 +0200)
* 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.

17 files changed:
ChangeLog
doc/posix-functions/pthread_mutex_destroy.texi
doc/posix-functions/pthread_mutex_init.texi
doc/posix-functions/pthread_mutex_lock.texi
doc/posix-functions/pthread_mutex_timedlock.texi
doc/posix-functions/pthread_mutex_trylock.texi
doc/posix-functions/pthread_mutex_unlock.texi
doc/posix-functions/pthread_mutexattr_destroy.texi
doc/posix-functions/pthread_mutexattr_getrobust.texi
doc/posix-functions/pthread_mutexattr_gettype.texi
doc/posix-functions/pthread_mutexattr_init.texi
doc/posix-functions/pthread_mutexattr_setrobust.texi
doc/posix-functions/pthread_mutexattr_settype.texi
lib/pthread-mutex.c [new file with mode: 0644]
lib/pthread.in.h
m4/pthread-mutex.m4 [new file with mode: 0644]
modules/pthread-mutex [new file with mode: 0644]

index b23cffa191d437a4afe627fc5a40d977fb256f72..7f778a9f474885f761f86d6a1531351e8ce2828d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+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.
index ce8760af9852f03da4d6aac6fa6fe61b9651916f..c5a081d2ad7059d52c5a524dd414d511fbd16ab2 100644 (file)
@@ -4,15 +4,17 @@
 
 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
index 3250347320792eff3f9f1466d9101b346458a216..fb86ed2f0291366e521bc6232836feb8d10492ba 100644 (file)
@@ -4,15 +4,17 @@
 
 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
index 1ee849aa70a52f067da57dd118a5b282e62b4876..2946aa964a4d018657c29daa0aa4a0a994c61183 100644 (file)
@@ -4,15 +4,17 @@
 
 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
index 7fa3745ad291173a197ea604b8d2f39ffeb8c326..aac3a4ce9a92e607b741d69ff1e93c9976b83818 100644 (file)
@@ -12,7 +12,7 @@ Portability problems fixed by Gnulib:
 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:
index 8da95774b555204ad48dc5b55a4eeeb6dcddfd45..84f3e0fba76c2b20d069f8742e1a2a88e28efaf0 100644 (file)
@@ -4,15 +4,17 @@
 
 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
index 608bb133225679b63b5e497086ef687fb25709f1..785254e67fd6ee8c651a5c62a601b39839b1ff41 100644 (file)
@@ -4,15 +4,17 @@
 
 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
index bf643e4ef4b650f39c47fca4898469cc42a71a00..ed9f85e59dac6e49a25b9c09256c0abe1021feee 100644 (file)
@@ -4,15 +4,17 @@
 
 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
index fe4cfdc9371f65e619d3d07831c8daec356d3faa..285e5772dbdaa511a226af7f37cdc87fdcad92ca 100644 (file)
@@ -4,15 +4,16 @@
 
 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
index f790f6e5bd611dcd21cfd852d5aa22358cc2da0b..8d38770661ea49d7f99ab0343aea85ac2fca6c5b 100644 (file)
@@ -4,15 +4,17 @@
 
 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
index 33ecf9fed84bad33ff224d48e73e0cc13e00e638..e631d8c4548acf58843a3a49835921bb73734f8d 100644 (file)
@@ -4,15 +4,17 @@
 
 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
index 31f0ff7aa52fdef93f27f63bfd5cedb037542de9..b9e5dbc72132bb317a5260b1984387081034b709 100644 (file)
@@ -4,15 +4,16 @@
 
 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
index 4ffcbe984217ea045b99eb8b903773878a8be643..82c6699d9157f049343c941167f90aed9a91c730 100644 (file)
@@ -4,15 +4,17 @@
 
 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
diff --git a/lib/pthread-mutex.c b/lib/pthread-mutex.c
new file mode 100644 (file)
index 0000000..7a6fc1a
--- /dev/null
@@ -0,0 +1,239 @@
+/* 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
index 88f349d4e504c137c966a0ab3acd0c663d46c0b7..b3e6b596aac23d8da63da2246ef6b52a4ffe70a2 100644 (file)
@@ -408,70 +408,6 @@ pthread_cond_wait (pthread_cond_t *restrict cond,
   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
 
diff --git a/m4/pthread-mutex.m4 b/m4/pthread-mutex.m4
new file mode 100644 (file)
index 0000000..c7d74f9
--- /dev/null
@@ -0,0 +1,44 @@
+# 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
+])
diff --git a/modules/pthread-mutex b/modules/pthread-mutex
new file mode 100644 (file)
index 0000000..8e64a9e
--- /dev/null
@@ -0,0 +1,33 @@
+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