From 6adb609cb3971aadf0483b4cf662428ea896aa9d Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 9 Dec 2020 18:51:40 +0100 Subject: [PATCH] threadlib: Fix test-fstrcmp failure on FreeBSD 11. * m4/threadlib.m4 (gl_THREADLIB_BODY): When weak symbols are not present on FreeBSD, define PTHREAD_IN_USE_DETECTION_HARD. * lib/glthread/threadlib.c: Include . (glthread_in_use): For FreeBSD, provide an alternative implementation that uses pthread_key_create. --- ChangeLog | 9 +++++++++ lib/glthread/threadlib.c | 35 +++++++++++++++++++++++++++++++++++ m4/threadlib.m4 | 13 ++++++++++++- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 817bd1f9ea..45aa98528b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2020-12-09 Bruno Haible + + threadlib: Fix test-fstrcmp failure on FreeBSD 11. + * m4/threadlib.m4 (gl_THREADLIB_BODY): When weak symbols are not present + on FreeBSD, define PTHREAD_IN_USE_DETECTION_HARD. + * lib/glthread/threadlib.c: Include . + (glthread_in_use): For FreeBSD, provide an alternative implementation + that uses pthread_key_create. + 2020-12-09 Bruno Haible math C++ tests: Fix compilation error in with clang >= 7 on FreeBSD. diff --git a/lib/glthread/threadlib.c b/lib/glthread/threadlib.c index 725017541a..fb8aab77b4 100644 --- a/lib/glthread/threadlib.c +++ b/lib/glthread/threadlib.c @@ -24,11 +24,44 @@ /* Use the POSIX threads library. */ +# include # include # include # if PTHREAD_IN_USE_DETECTION_HARD +# if defined __FreeBSD__ || defined __DragonFly__ /* FreeBSD */ + +/* Test using pthread_key_create. */ + +int +glthread_in_use (void) +{ + static int tested; + static int result; /* 1: linked with -lpthread, 0: only with libc */ + + if (!tested) + { + pthread_key_t key; + int err = pthread_key_create (&key, NULL); + + if (err == ENOSYS) + result = 0; + else + { + result = 1; + if (err == 0) + pthread_key_delete (key); + } + tested = 1; + } + return result; +} + +# else /* Solaris, HP-UX */ + +/* Test using pthread_create. */ + /* The function to be executed by a dummy thread. */ static void * dummy_thread_func (void *arg) @@ -62,6 +95,8 @@ glthread_in_use (void) return result; } +# endif + # endif #endif diff --git a/m4/threadlib.m4 b/m4/threadlib.m4 index 1da5fc089e..e03c34f53b 100644 --- a/m4/threadlib.m4 +++ b/m4/threadlib.m4 @@ -1,4 +1,4 @@ -# threadlib.m4 serial 28 +# threadlib.m4 serial 29 dnl Copyright (C) 2005-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -486,6 +486,17 @@ AC_DEFUN([gl_THREADLIB_BODY], AC_DEFINE([USE_POSIX_THREADS_WEAK], [1], [Define if references to the POSIX multithreading library should be made weak.]) LIBTHREAD= LTLIBTHREAD= + else + case "$host_os" in + freebsd* | dragonfly*) + if test "x$LIBTHREAD" != "x$LIBMULTITHREAD"; then + dnl If weak symbols can't tell whether pthread_create(), pthread_key_create() + dnl etc. will succeed, we need a runtime test. + AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1], + [Define if the pthread_in_use() detection is hard.]) + fi + ;; + esac fi fi fi -- 2.39.5