]> Savannah Git Hosting - gnulib.git/commitdiff
call_once: New module, separate from mtx.
authorBruno Haible <bruno@clisp.org>
Sat, 25 Mar 2023 19:54:29 +0000 (20:54 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 25 Mar 2023 19:58:44 +0000 (20:58 +0100)
* lib/threads.in.h (call_once): Declare as part of module 'call_once',
not module 'mtx'.
* lib/call_once.c: New file, extracted from lib/mtx.c.
* lib/mtx.c (call_once): Remove function.
* m4/threads_h.m4 (gl_THREADS_H_REQUIRE_DEFAULTS): Inititalize
GNULIB_CALL_ONCE.
* modules/threads-h (Makefile.am): Substitute GNULIB_CALL_ONCE.
* modules/call_once: New file, based on modules/mtx.
* modules/threads (Depends-on): Add call_once.
* tests/test-threads-c++.cc: Update accordingly.
* modules/call_once-tests: New file, based on modules/mtx-tests.
* modules/mtx-tests (Files): Remove tests/test-call_once.c.
(Makefile.am): Don't compile test-call_once.
* doc/posix-functions/call_once.texi: Document that the relevant module
is now 'call_once'.
* NEWS: Mention the change.

13 files changed:
ChangeLog
NEWS
doc/posix-functions/call_once.texi
lib/call_once.c [new file with mode: 0644]
lib/mtx.c
lib/threads.in.h
m4/threads_h.m4
modules/call_once [new file with mode: 0644]
modules/call_once-tests [new file with mode: 0644]
modules/mtx-tests
modules/threads
modules/threads-h
tests/test-threads-c++.cc

index 9dd1b50086f7f6d652f75ae8a7f40f4519d8c2a0..07b96d58602b49d539abb7e491197b4183dcdc2d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2023-03-25  Bruno Haible  <bruno@clisp.org>
+
+       call_once: New module, separate from mtx.
+       * lib/threads.in.h (call_once): Declare as part of module 'call_once',
+       not module 'mtx'.
+       * lib/call_once.c: New file, extracted from lib/mtx.c.
+       * lib/mtx.c (call_once): Remove function.
+       * m4/threads_h.m4 (gl_THREADS_H_REQUIRE_DEFAULTS): Inititalize
+       GNULIB_CALL_ONCE.
+       * modules/threads-h (Makefile.am): Substitute GNULIB_CALL_ONCE.
+       * modules/call_once: New file, based on modules/mtx.
+       * modules/threads (Depends-on): Add call_once.
+       * tests/test-threads-c++.cc: Update accordingly.
+       * modules/call_once-tests: New file, based on modules/mtx-tests.
+       * modules/mtx-tests (Files): Remove tests/test-call_once.c.
+       (Makefile.am): Don't compile test-call_once.
+       * doc/posix-functions/call_once.texi: Document that the relevant module
+       is now 'call_once'.
+       * NEWS: Mention the change.
+
 2023-03-25  Bruno Haible  <bruno@clisp.org>
 
        stdio: ISO C 23: Define _PRINTF_NAN_LEN_MAX.
diff --git a/NEWS b/NEWS
index 7863514118a6e82e73974ad506b557c946deaa73..fcfaf4906b125baa26e80d95d849de4d49f7501c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -74,6 +74,10 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
+2023-03-25  mtx             This module no longer provides the function
+                            call_once.  To get this function, use the new
+                            separate module 'call_once'.
+
 2023-03-08  time            This module is renamed to 'time-h'.
                             The new 'time' module now also works around an
                             inconsistency in glibc 2.31+ on Linux.
index ee798db9631a75f44963c65caf36af624fdf0c0d..e7c6f07542db3187e10c0ad9a2c6362ac729b17e 100644 (file)
@@ -10,7 +10,7 @@ Documentation:@*
 @url{https://www.gnu.org/software/libc/manual/html_node/Call-Once.html}.
 @end ifnotinfo
 
-Gnulib module: mtx
+Gnulib module: call_once
 
 Portability problems fixed by Gnulib:
 @itemize
diff --git a/lib/call_once.c b/lib/call_once.c
new file mode 100644 (file)
index 0000000..d11d950
--- /dev/null
@@ -0,0 +1,59 @@
+/* ISO C 11 once-only initialization.
+   Copyright (C) 2005-2023 Free Software Foundation, Inc.
+
+   This file is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   This file 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 Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2005, 2019.
+   Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-win32.h.  */
+
+#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 <stdlib.h>
+
+#else
+/* Use POSIX threads.  */
+
+# include <pthread.h>
+
+#endif
+
+#if defined _WIN32 && ! defined __CYGWIN__
+/* Use Windows threads.  */
+
+void
+call_once (once_flag *flagp, void (*func) (void))
+{
+  glwthread_once (flagp, func);
+}
+
+#else
+/* Use POSIX threads.  */
+
+void
+call_once (once_flag *flagp, void (*func) (void))
+{
+  pthread_once (flagp, func);
+}
+
+#endif
index fe15b694941fed2e8c1e3d2071308b4a5880f565..9292773cf478d9b67f2d60b20673804273f8ff3e 100644 (file)
--- a/lib/mtx.c
+++ b/lib/mtx.c
@@ -187,12 +187,6 @@ mtx_destroy (mtx_t *mutex)
     }
 }
 
-void
-call_once (once_flag *flagp, void (*func) (void))
-{
-  glwthread_once (flagp, func);
-}
-
 #else
 /* Use POSIX threads.  */
 
@@ -279,10 +273,4 @@ mtx_destroy (mtx_t *mutex)
   pthread_mutex_destroy (mutex);
 }
 
-void
-call_once (once_flag *flagp, void (*func) (void))
-{
-  pthread_once (flagp, func);
-}
-
 #endif
index e34c39de3f2106390dc9dcaf20e9a1d79c062e3c..2bc0f23b326ba802ec900f70145a86c2e468d586 100644 (file)
@@ -459,7 +459,7 @@ typedef pthread_once_t once_flag;
 
 #endif
 
-#if @GNULIB_MTX@
+#if @GNULIB_CALL_ONCE@
 # if !@HAVE_THREADS_H@
 _GL_FUNCDECL_SYS (call_once, void, (once_flag *, void (*) (void))
                                    _GL_ARG_NONNULL ((1, 2)));
index 77fe20d279eeae4108cc75cb4a2baec036480245..851490c123006d8967c3062c095912f5b56c297a 100644 (file)
@@ -1,4 +1,4 @@
-# threads_h.m4 serial 10
+# threads_h.m4 serial 11
 dnl Copyright (C) 2019-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -156,6 +156,7 @@ AC_DEFUN([gl_THREADS_MODULE_INDICATOR],
 AC_DEFUN([gl_THREADS_H_REQUIRE_DEFAULTS],
 [
   m4_defun(GL_MODULE_INDICATOR_PREFIX[_THREADS_H_MODULE_INDICATOR_DEFAULTS], [
+    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CALL_ONCE])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CND])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MTX])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_THRD])
diff --git a/modules/call_once b/modules/call_once
new file mode 100644 (file)
index 0000000..3efc3f3
--- /dev/null
@@ -0,0 +1,31 @@
+Description:
+call_once() function: ISO C 11 once-only initialization.
+
+Files:
+lib/call_once.c
+
+Depends-on:
+threads-h
+windows-once
+
+configure.ac:
+AC_REQUIRE([gl_THREADS_H])
+gl_CONDITIONAL([GL_COND_OBJ_CALL_ONCE], [test $HAVE_THREADS_H = 0])
+gl_THREADS_MODULE_INDICATOR([call_once])
+
+Makefile.am:
+if GL_COND_OBJ_CALL_ONCE
+lib_SOURCES += call_once.c
+endif
+
+Include:
+<threads.h>
+
+Link:
+$(LIBSTDTHREAD)
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/call_once-tests b/modules/call_once-tests
new file mode 100644 (file)
index 0000000..70bae25
--- /dev/null
@@ -0,0 +1,12 @@
+Files:
+tests/test-call_once.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-call_once
+check_PROGRAMS += test-call_once
+test_call_once_LDADD = $(LDADD) @LIBSTDTHREAD@
index 52310625a558da82f95f5c67ed0341522586fe54..4a021d22fa79bed0dc84a08b95c21250072ca7a7 100644 (file)
@@ -1,6 +1,5 @@
 Files:
 tests/test-mtx.c
-tests/test-call_once.c
 tests/atomic-int-isoc.h
 tests/macros.h
 
@@ -14,7 +13,6 @@ AC_CHECK_HEADERS_ONCE([semaphore.h])
 AC_CHECK_DECLS_ONCE([alarm])
 
 Makefile.am:
-TESTS += test-mtx test-call_once
-check_PROGRAMS += test-mtx test-call_once
+TESTS += test-mtx
+check_PROGRAMS += test-mtx
 test_mtx_LDADD = $(LDADD) @LIBSTDTHREAD@ @LIBTHREAD@
-test_call_once_LDADD = $(LDADD) @LIBSTDTHREAD@
index 18391c1c2dddd1552e965559e2b312bddf61a21c..c5bed1c32868ceda1b3c4d012bddbc9091b7d6e2 100644 (file)
@@ -6,6 +6,7 @@ Files:
 Depends-on:
 threads-h
 thrd
+call_once
 mtx
 cnd
 tss
index 50a60dfdabaa47a24ac5a2d6e1a2620416bc1894..1a2b83a35432beba9644d00639b347b31fa8923f 100644 (file)
@@ -50,6 +50,7 @@ threads.h: threads.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(_NORETURN_H
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_AS_FIRST_DIRECTIVE_THREADS_H''@|$(NEXT_AS_FIRST_DIRECTIVE_THREADS_H)|g' \
              -e 's|@''NEXT_THREADS_H''@|$(NEXT_THREADS_H)|g' \
+             -e 's/@''GNULIB_CALL_ONCE''@/$(GNULIB_CALL_ONCE)/g' \
              -e 's/@''GNULIB_CND''@/$(GNULIB_CND)/g' \
              -e 's/@''GNULIB_MTX''@/$(GNULIB_MTX)/g' \
              -e 's/@''GNULIB_THRD''@/$(GNULIB_THRD)/g' \
index 7c3bcb80b1e8d499fbea930ddbbd5a30be3edcb8..d82b526458d279a7b3e77232cc0ea341c6e3e853 100644 (file)
@@ -45,6 +45,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::mtx_timedlock, int,
                  (mtx_t *, const struct timespec *));
 SIGNATURE_CHECK (GNULIB_NAMESPACE::mtx_unlock, int, (mtx_t *));
 SIGNATURE_CHECK (GNULIB_NAMESPACE::mtx_destroy, void, (mtx_t *));
+#endif
+
+#if GNULIB_TEST_CALL_ONCE
 SIGNATURE_CHECK (GNULIB_NAMESPACE::call_once, void,
                  (once_flag *, void (*) (void)));
 #endif