]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
cnd: New module.
authorBruno Haible <bruno@clisp.org>
Thu, 20 Jun 2019 02:32:42 +0000 (04:32 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 20 Jun 2019 02:46:54 +0000 (04:46 +0200)
* lib/cnd.c: New file.
* modules/cnd: New file.
* doc/posix-functions/cnd_init.texi: Mention the new module.
* doc/posix-functions/cnd_wait.texi: Likewise.
* doc/posix-functions/cnd_timedwait.texi: Likewise.
* doc/posix-functions/cnd_signal.texi: Likewise.
* doc/posix-functions/cnd_broadcast.texi: Likewise.
* doc/posix-functions/cnd_destroy.texi: Likewise.

ChangeLog
doc/posix-functions/cnd_broadcast.texi
doc/posix-functions/cnd_destroy.texi
doc/posix-functions/cnd_init.texi
doc/posix-functions/cnd_signal.texi
doc/posix-functions/cnd_timedwait.texi
doc/posix-functions/cnd_wait.texi
lib/cnd.c [new file with mode: 0644]
modules/cnd [new file with mode: 0644]

index 0e73bd689bdb3039fa17c4619616bd5d7ddeda4d..68eeea7c5cefb9b75d7485257aac6ff34d4dc305 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2019-06-20  Bruno Haible  <bruno@clisp.org>
+
+       cnd: New module.
+       * lib/cnd.c: New file.
+       * modules/cnd: New file.
+       * doc/posix-functions/cnd_init.texi: Mention the new module.
+       * doc/posix-functions/cnd_wait.texi: Likewise.
+       * doc/posix-functions/cnd_timedwait.texi: Likewise.
+       * doc/posix-functions/cnd_signal.texi: Likewise.
+       * doc/posix-functions/cnd_broadcast.texi: Likewise.
+       * doc/posix-functions/cnd_destroy.texi: Likewise.
+
 2019-06-20  Bruno Haible  <bruno@clisp.org>
 
        mtx: New module.
index a11d52df913a0a61d873811d5bb2fdbde1a723b7..e44a908b2f28154a6570138d6e47698012528250 100644 (file)
@@ -10,15 +10,15 @@ Documentation:@*
 @url{https://www.gnu.org/software/libc/manual/html_node/ISO-C-Condition-Variables.html}.
 @end ifnotinfo
 
-Gnulib module: ---
+Gnulib module: cnd
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on many platforms:
+glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on many platforms:
-glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0.
 @end itemize
index 1ae39fda13a788bb332f4588b6c67a02658b4bbd..13783a3fb087d7e7b9bed6608d7dcae2c8749258 100644 (file)
@@ -10,15 +10,15 @@ Documentation:@*
 @url{https://www.gnu.org/software/libc/manual/html_node/ISO-C-Condition-Variables.html}.
 @end ifnotinfo
 
-Gnulib module: ---
+Gnulib module: cnd
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on many platforms:
+glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on many platforms:
-glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0.
 @end itemize
index 55c7489e12227e1561a63b8020656d8e72e7ed5e..a7413034eada856bd3dd9bb75a75e33770a7cba2 100644 (file)
@@ -10,15 +10,15 @@ Documentation:@*
 @url{https://www.gnu.org/software/libc/manual/html_node/ISO-C-Condition-Variables.html}.
 @end ifnotinfo
 
-Gnulib module: ---
+Gnulib module: cnd
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on many platforms:
+glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on many platforms:
-glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0.
 @end itemize
index 83071e5d3e6b7fc612c141fa52d5c7e156b62154..22e2ecce498481e6054bbfa6b95545d908769191 100644 (file)
@@ -10,15 +10,15 @@ Documentation:@*
 @url{https://www.gnu.org/software/libc/manual/html_node/ISO-C-Condition-Variables.html}.
 @end ifnotinfo
 
-Gnulib module: ---
+Gnulib module: cnd
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on many platforms:
+glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on many platforms:
-glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0.
 @end itemize
index 3fa69859d703f072ca9e4573068ec9ce019a0541..0b5f29d6f73feb030c78d499f4fcf9801bad51b9 100644 (file)
@@ -10,15 +10,15 @@ Documentation:@*
 @url{https://www.gnu.org/software/libc/manual/html_node/ISO-C-Condition-Variables.html}.
 @end ifnotinfo
 
-Gnulib module: ---
+Gnulib module: cnd
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on many platforms:
+glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on many platforms:
-glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0.
 @end itemize
index 89e9864b9c77ea2609651e9a84f9ca4bf0a72153..626a6aa4cf5517584cc231243b0915b0849c75b1 100644 (file)
@@ -10,15 +10,15 @@ Documentation:@*
 @url{https://www.gnu.org/software/libc/manual/html_node/ISO-C-Condition-Variables.html}.
 @end ifnotinfo
 
-Gnulib module: ---
+Gnulib module: cnd
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on many platforms:
+glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on many platforms:
-glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0.
 @end itemize
diff --git a/lib/cnd.c b/lib/cnd.c
new file mode 100644 (file)
index 0000000..48c4854
--- /dev/null
+++ b/lib/cnd.c
@@ -0,0 +1,185 @@
+/* ISO C 11 condition variables for multithreading.
+   Copyright (C) 2008-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 Yoann Vandoorselaere <yoann@prelude-ids.org>, 2008,
+   and Bruno Haible <bruno@clisp.org>, 2008, 2019.  */
+
+#include <config.h>
+
+#include <threads.h>
+
+#include <errno.h>
+
+#if defined _WIN32 && ! defined __CYGWIN__
+/* Use Windows threads.  */
+
+# define WIN32_LEAN_AND_MEAN  /* avoid including junk */
+# include <windows.h>
+
+# include "windows-mutex.h"
+# include "windows-recmutex.h"
+# include "windows-timedmutex.h"
+# include "windows-timedrecmutex.h"
+
+#else
+/* Use POSIX threads.  */
+
+# include <pthread.h>
+
+#endif
+
+#if defined _WIN32 && ! defined __CYGWIN__
+/* Use Windows threads.  */
+
+int
+cnd_init (cnd_t *cond)
+{
+  int err = glwthread_cond_init (cond);
+  return (err == 0 ? thrd_success :
+          err == ENOMEM ? thrd_nomem :
+          thrd_error);
+}
+
+static int
+mutex_lock (mtx_t *mutex)
+{
+  switch (mutex->type)
+    {
+    case mtx_plain:
+      return glwthread_mutex_lock (&mutex->u.u_mutex);
+    case mtx_plain | mtx_recursive:
+      return glwthread_recmutex_lock (&mutex->u.u_recmutex);
+    case mtx_timed:
+      return glwthread_timedmutex_lock (&mutex->u.u_timedmutex);
+    case mtx_timed | mtx_recursive:
+      return glwthread_timedrecmutex_lock (&mutex->u.u_timedrecmutex);
+    default:
+      abort ();
+    }
+}
+
+static int
+mutex_unlock (mtx_t *mutex)
+{
+  switch (mutex->type)
+    {
+    case mtx_plain:
+      return glwthread_mutex_unlock (&mutex->u.u_mutex);
+    case mtx_plain | mtx_recursive:
+      return glwthread_recmutex_unlock (&mutex->u.u_recmutex);
+    case mtx_timed:
+      return glwthread_timedmutex_unlock (&mutex->u.u_timedmutex);
+    case mtx_timed | mtx_recursive:
+      return glwthread_timedrecmutex_unlock (&mutex->u.u_timedrecmutex);
+    default:
+      abort ();
+    }
+}
+
+int
+cnd_wait (cnd_t *cond, mtx_t *mutex)
+{
+  int err = glwthread_cond_wait (cond, mutex,
+                                 (int (*) (void *)) mutex_lock,
+                                 (int (*) (void *)) mutex_unlock);
+  return (err == 0 ? thrd_success : thrd_error);
+}
+
+int
+cnd_timedwait (cnd_t *cond, mtx_t *mutex, const struct timespec *abstime)
+{
+  int err = glwthread_cond_timedwait (cond, mutex,
+                                      (int (*) (void *)) mutex_lock,
+                                      (int (*) (void *)) mutex_unlock,
+                                      abstime);
+  return (err == 0 ? thrd_success :
+          err == ETIMEDOUT ? thrd_timedout :
+          thrd_error);
+}
+
+int
+cnd_signal (cnd_t *cond)
+{
+  int err = glwthread_cond_signal (cond);
+  return (err == 0 ? thrd_success :
+          err == ENOMEM ? thrd_nomem :
+          thrd_error);
+}
+
+int
+cnd_broadcast (cnd_t *cond)
+{
+  int err = glwthread_cond_broadcast (cond);
+  return (err == 0 ? thrd_success : thrd_error);
+}
+
+void
+cnd_destroy (cnd_t *cond)
+{
+  glwthread_cond_destroy (cond);
+}
+
+#else
+/* Use POSIX threads.  */
+
+int
+cnd_init (cnd_t *cond)
+{
+  int err = pthread_cond_init (cond, NULL);
+  return (err == 0 ? thrd_success :
+          err == ENOMEM ? thrd_nomem :
+          thrd_error);
+}
+
+int
+cnd_wait (cnd_t *cond, mtx_t *mutex)
+{
+  int err = pthread_cond_wait (cond, mutex);
+  return (err == 0 ? thrd_success : thrd_error);
+}
+
+int
+cnd_timedwait (cnd_t *cond, mtx_t *mutex, const struct timespec *abstime)
+{
+  int err = pthread_cond_timedwait (cond, mutex, abstime);
+  return (err == 0 ? thrd_success :
+          err == ETIMEDOUT ? thrd_timedout :
+          thrd_error);
+}
+
+int
+cnd_signal (cnd_t *cond)
+{
+  int err = pthread_cond_signal (cond);
+  return (err == 0 ? thrd_success :
+          err == ENOMEM ? thrd_nomem :
+          thrd_error);
+}
+
+int
+cnd_broadcast (cnd_t *cond)
+{
+  int err = pthread_cond_broadcast (cond);
+  return (err == 0 ? thrd_success : thrd_error);
+}
+
+void
+cnd_destroy (cnd_t *cond)
+{
+  pthread_cond_destroy (cond);
+}
+
+#endif
diff --git a/modules/cnd b/modules/cnd
new file mode 100644 (file)
index 0000000..635a422
--- /dev/null
@@ -0,0 +1,31 @@
+Description:
+ISO C 11 condition variable functions.
+
+Files:
+lib/cnd.c
+
+Depends-on:
+threads-h
+windows-cond
+gettimeofday
+
+configure.ac:
+AC_REQUIRE([gl_THREADS_H])
+if test $HAVE_THREADS_H = 0; then
+  AC_LIBOBJ([cnd])
+fi
+gl_THREADS_MODULE_INDICATOR([cnd])
+
+Makefile.am:
+
+Include:
+<threads.h>
+
+Link:
+$(LTLIBSTDTHREAD) when linking with libtool, $(LIBSTDTHREAD) otherwise
+
+License:
+LGPLv2+
+
+Maintainer:
+all