]> Savannah Git Hosting - gnulib.git/commitdiff
threadlib: Fix test-fstrcmp failure on FreeBSD 11.
authorBruno Haible <bruno@clisp.org>
Wed, 9 Dec 2020 17:51:40 +0000 (18:51 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 9 Dec 2020 17:51:40 +0000 (18:51 +0100)
* 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 <errno.h>.
(glthread_in_use): For FreeBSD, provide an alternative implementation
that uses pthread_key_create.

ChangeLog
lib/glthread/threadlib.c
m4/threadlib.m4

index 817bd1f9ea791c919e8fbf1d5f85e29bbc96d140..45aa98528b457b9d137b9a556ee1cac584d12801 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2020-12-09  Bruno Haible  <bruno@clisp.org>
+
+       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 <errno.h>.
+       (glthread_in_use): For FreeBSD, provide an alternative implementation
+       that uses pthread_key_create.
+
 2020-12-09  Bruno Haible  <bruno@clisp.org>
 
        math C++ tests: Fix compilation error in with clang >= 7 on FreeBSD.
index 725017541af35448001a8decb95e19e8bbb26191..fb8aab77b4b11969de735e063117cb05f9239c54 100644 (file)
 
 /* Use the POSIX threads library.  */
 
+# include <errno.h>
 # include <pthread.h>
 # include <stdlib.h>
 
 # 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
index 1da5fc089e2e499f7baf125be650421235b12cd3..e03c34f53b8f597e183660d8b3415ac2073534b3 100644 (file)
@@ -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