+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.
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.
@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
--- /dev/null
+/* 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
}
}
-void
-call_once (once_flag *flagp, void (*func) (void))
-{
- glwthread_once (flagp, func);
-}
-
#else
/* Use POSIX threads. */
pthread_mutex_destroy (mutex);
}
-void
-call_once (once_flag *flagp, void (*func) (void))
-{
- pthread_once (flagp, func);
-}
-
#endif
#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)));
-# 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,
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])
--- /dev/null
+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
--- /dev/null
+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@
Files:
tests/test-mtx.c
-tests/test-call_once.c
tests/atomic-int-isoc.h
tests/macros.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@
Depends-on:
threads-h
thrd
+call_once
mtx
cnd
tss
-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' \
(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