]> Savannah Git Hosting - gnulib.git/commitdiff
lock: Fix test-once1 failure on FreeBSD 11 (regression from 2020-01-19).
authorBruno Haible <bruno@clisp.org>
Mon, 20 Jan 2020 17:29:24 +0000 (18:29 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 20 Jan 2020 17:29:24 +0000 (18:29 +0100)
* lib/glthread/lock.c (glthread_once_multithreaded): New function.
* lib/glthread/lock.h (glthread_once_multithreaded): New declaration.
(glthread_once): Use it.

ChangeLog
lib/glthread/lock.c
lib/glthread/lock.h

index 148d15ef3fe8436cba71380644e405b83c1ef825..8b6168164ab05c8d2dc41ec854a5a8bd0aafee16 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-01-20  Bruno Haible  <bruno@clisp.org>
+
+       lock: Fix test-once1 failure on FreeBSD 11 (regression from 2020-01-19).
+       * lib/glthread/lock.c (glthread_once_multithreaded): New function.
+       * lib/glthread/lock.h (glthread_once_multithreaded): New declaration.
+       (glthread_once): Use it.
+
 2020-01-19  Bruno Haible  <bruno@clisp.org>
 
        threadlib: Disable use of weak symbols on FreeBSD 11.
index 63365910b052cb9eb333d2ea6bc27d5f99b29969..1f6f713e3e1262006c6af133fec1ce7b77407735 100644 (file)
@@ -718,6 +718,26 @@ glthread_once_singlethreaded (pthread_once_t *once_control)
     return 0;
 }
 
+# if !(PTHREAD_IN_USE_DETECTION_HARD || USE_POSIX_THREADS_WEAK)
+
+int
+glthread_once_multithreaded (pthread_once_t *once_control,
+                             void (*init_function) (void))
+{
+  int err = pthread_once (once_control, init_function);
+  if (err == ENOSYS)
+    {
+      /* This happens on FreeBSD 11: The pthread_once function in libc returns
+         ENOSYS.  */
+      if (glthread_once_singlethreaded (once_control))
+        init_function ();
+      return 0;
+    }
+  return err;
+}
+
+# endif
+
 #endif
 
 /* ========================================================================= */
index 9c70f4e5f0a1258886962ae6246a93c70a58167b..1de86fe4f70302f00e5ec1b77b0fc01d11ff24e5 100644 (file)
@@ -505,10 +505,19 @@ extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *l
 typedef pthread_once_t gl_once_t;
 # define gl_once_define(STORAGECLASS, NAME) \
     STORAGECLASS pthread_once_t NAME = PTHREAD_ONCE_INIT;
-# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
-    (pthread_in_use ()                                                         \
-     ? pthread_once (ONCE_CONTROL, INITFUNCTION)                               \
-     : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0))
+# if PTHREAD_IN_USE_DETECTION_HARD || USE_POSIX_THREADS_WEAK
+#  define glthread_once(ONCE_CONTROL, INITFUNCTION) \
+     (pthread_in_use ()                                                        \
+      ? pthread_once (ONCE_CONTROL, INITFUNCTION)                              \
+      : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0))
+# else
+#  define glthread_once(ONCE_CONTROL, INITFUNCTION) \
+     (pthread_in_use ()                                                        \
+      ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION)               \
+      : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0))
+extern int glthread_once_multithreaded (pthread_once_t *once_control,
+                                        void (*init_function) (void));
+# endif
 extern int glthread_once_singlethreaded (pthread_once_t *once_control);
 
 # ifdef __cplusplus