From d2576e3a2739c5847e2b0880494779924e5e713e Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Fri, 18 Aug 2023 21:14:40 +0200
Subject: [PATCH] thrd: Refactor.

* m4/thrd.m4 (gl_FUNC_THRD_JOIN): Define BROKEN_THRD_JOIN_NULL, not
BROKEN_THRD_JOIN. Rename gl_cv_func_thrd_join_works to
gl_cv_func_thrd_join_null_works.
* lib/thrd.c: Test BROKEN_THRD_JOIN_NULL instead of BROKEN_THRD_JOIN.
---
 ChangeLog  |  8 ++++++++
 lib/thrd.c |  2 +-
 m4/thrd.m4 | 20 ++++++++++----------
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 661dd10869..41dfa77177 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-08-18  Bruno Haible  <bruno@clisp.org>
+
+	thrd: Refactor.
+	* m4/thrd.m4 (gl_FUNC_THRD_JOIN): Define BROKEN_THRD_JOIN_NULL, not
+	BROKEN_THRD_JOIN. Rename gl_cv_func_thrd_join_works to
+	gl_cv_func_thrd_join_null_works.
+	* lib/thrd.c: Test BROKEN_THRD_JOIN_NULL instead of BROKEN_THRD_JOIN.
+
 2023-08-18  Bruno Haible  <bruno@clisp.org>
 
 	thrd: On AIX 7.1 and 7.2, override also thrd_exit.
diff --git a/lib/thrd.c b/lib/thrd.c
index 36117bb6de..687a0920ec 100644
--- a/lib/thrd.c
+++ b/lib/thrd.c
@@ -218,7 +218,7 @@ rpl_thrd_exit (int exitcode)
 
 # endif
 
-# if BROKEN_THRD_JOIN
+# if BROKEN_THRD_JOIN_NULL
 
 /* On Solaris 11.4, thrd_join crashes when the second argument is NULL.  */
 int
diff --git a/m4/thrd.m4 b/m4/thrd.m4
index fed111695f..1c0a611ae2 100644
--- a/m4/thrd.m4
+++ b/m4/thrd.m4
@@ -1,4 +1,4 @@
-# thrd.m4 serial 2
+# thrd.m4 serial 3
 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,
@@ -25,8 +25,8 @@ AC_DEFUN([gl_FUNC_THRD_JOIN],
     fi
 
     dnl On Solaris 11.4, thrd_join crashes when the second argument is NULL.
-    AC_CACHE_CHECK([whether thrd_join works],
-      [gl_cv_func_thrd_join_works],
+    AC_CACHE_CHECK([whether thrd_join with NULL argument works],
+      [gl_cv_func_thrd_join_null_works],
       [save_LIBS="$LIBS"
        LIBS="$LIBS $LIBSTDTHREAD"
        AC_RUN_IFELSE(
@@ -45,22 +45,22 @@ AC_DEFUN([gl_FUNC_THRD_JOIN],
                 return 2;
               return 0;
             ]])],
-         [gl_cv_func_thrd_join_works=yes],
-         [gl_cv_func_thrd_join_works=no],
+         [gl_cv_func_thrd_join_null_works=yes],
+         [gl_cv_func_thrd_join_null_works=no],
          [case "$host_os" in
                       # Only Solaris is known to be broken.
-            solaris*) gl_cv_func_thrd_join_works="guessing no" ;;
-            *)        gl_cv_func_thrd_join_works="guessing yes" ;;
+            solaris*) gl_cv_func_thrd_join_null_works="guessing no" ;;
+            *)        gl_cv_func_thrd_join_null_works="guessing yes" ;;
           esac
          ])
        LIBS="$save_LIBS"
       ])
-    case "$gl_cv_func_thrd_join_works" in
+    case "$gl_cv_func_thrd_join_null_works" in
       *yes) ;;
       *)
         REPLACE_THRD_JOIN=1
-        AC_DEFINE([BROKEN_THRD_JOIN], [1],
-          [Define if the thrd_join function does not behave as in ISO C 11.])
+        AC_DEFINE([BROKEN_THRD_JOIN_NULL], [1],
+          [Define if the thrd_join function, when given a NULL argument, does not behave as in ISO C 11.])
         ;;
     esac
   fi
-- 
2.39.5