]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
pthread-once: New module.
authorBruno Haible <bruno@clisp.org>
Mon, 15 Jul 2019 00:37:41 +0000 (02:37 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 15 Jul 2019 00:37:41 +0000 (02:37 +0200)
* lib/pthread-once.c: New file.
* m4/pthread-once.m4: New file.
* modules/pthread-once: New file.
* doc/posix-functions/pthread_once.texi: Mention the new module.

ChangeLog
doc/posix-functions/pthread_once.texi
lib/pthread-once.c [new file with mode: 0644]
m4/pthread-once.m4 [new file with mode: 0644]
modules/pthread-once [new file with mode: 0644]

index f21fa24175376abbe1b6fe1289144646e054c4bd..b23cffa191d437a4afe627fc5a40d977fb256f72 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-07-14  Bruno Haible  <bruno@clisp.org>
+
+       pthread-once: New module.
+       * lib/pthread-once.c: New file.
+       * m4/pthread-once.m4: New file.
+       * modules/pthread-once: New file.
+       * doc/posix-functions/pthread_once.texi: Mention the new module.
+
 2019-07-14  Bruno Haible  <bruno@clisp.org>
 
        pthread-thread: New module.
index a8f48afc93068e9cb688b91cff94101c33f95b56..89bfbad25557fcad0e5a59a61a04fe8c189f798e 100644 (file)
@@ -4,15 +4,17 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_once.html}
 
-Gnulib module: ---
+Gnulib module: pthread-once
 
 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
diff --git a/lib/pthread-once.c b/lib/pthread-once.c
new file mode 100644 (file)
index 0000000..bbb195c
--- /dev/null
@@ -0,0 +1,55 @@
+/* POSIX once-only control.
+   Copyright (C) 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 Bruno Haible <bruno@clisp.org>, 2019.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <pthread.h>
+
+#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS
+# include "windows-once.h"
+#endif
+
+#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS
+/* Use Windows threads.  */
+
+int
+pthread_once (pthread_once_t *once_control, void (*initfunction) (void))
+{
+  glwthread_once (once_control, initfunction);
+  return 0;
+}
+
+#elif HAVE_PTHREAD_H
+/* Provide workarounds for POSIX threads.  */
+
+#else
+/* Provide a dummy implementation for single-threaded applications.  */
+
+int
+pthread_once (pthread_once_t *once_control, void (*initfunction) (void))
+{
+  if (*once_control == 0)
+    {
+      *once_control = ~ 0;
+      initfunction ();
+    }
+  return 0;
+}
+
+#endif
diff --git a/m4/pthread-once.m4 b/m4/pthread-once.m4
new file mode 100644 (file)
index 0000000..03149d5
--- /dev/null
@@ -0,0 +1,22 @@
+# pthread-once.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_ONCE],
+[
+  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_ONCE=1
+  else
+    if test $HAVE_PTHREAD_H = 0; then
+      HAVE_PTHREAD_ONCE=0
+    fi
+  fi
+])
diff --git a/modules/pthread-once b/modules/pthread-once
new file mode 100644 (file)
index 0000000..3e25c76
--- /dev/null
@@ -0,0 +1,31 @@
+Description:
+POSIX once-only control.
+
+Files:
+lib/pthread-once.c
+m4/pthread-once.m4
+
+Depends-on:
+pthread-h
+windows-once    [test $gl_threads_api = windows]
+
+configure.ac:
+gl_PTHREAD_ONCE
+if test $HAVE_PTHREAD_ONCE = 0 || test $REPLACE_PTHREAD_ONCE = 1; then
+  AC_LIBOBJ([pthread-once])
+fi
+gl_PTHREAD_MODULE_INDICATOR([pthread-once])
+
+Makefile.am:
+
+Include:
+<pthread.h>
+
+Link:
+$(LIBMULTITHREAD)
+
+License:
+LGPLv2+
+
+Maintainer:
+all