From f30726f69962bd5b4b911eea4e1b825ec08cf30a Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 20 Jan 2020 18:29:24 +0100 Subject: [PATCH] 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. --- ChangeLog | 7 +++++++ lib/glthread/lock.c | 20 ++++++++++++++++++++ lib/glthread/lock.h | 17 +++++++++++++---- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 148d15ef3f..8b6168164a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2020-01-20 Bruno Haible + + 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 threadlib: Disable use of weak symbols on FreeBSD 11. diff --git a/lib/glthread/lock.c b/lib/glthread/lock.c index 63365910b0..1f6f713e3e 100644 --- a/lib/glthread/lock.c +++ b/lib/glthread/lock.c @@ -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 /* ========================================================================= */ diff --git a/lib/glthread/lock.h b/lib/glthread/lock.h index 9c70f4e5f0..1de86fe4f7 100644 --- a/lib/glthread/lock.h +++ b/lib/glthread/lock.h @@ -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 -- 2.39.5