On 06/13/2014 11:07 PM, Paul Eggert wrote:
> Pádraig Brady wrote:
> 
> 
>> +     case "$host_os" in
>> +       aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;;
>> +       solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;;
> 
> Why not use AC_DEFINE([_THREAD_SAFE], 1, ...) instead?  That makes for 
> shorter command lines in projects like Emacs.  I don't see any advantage to 
> putting it in CPPFLAGS.

Fair point. The reason that threadlib.m4 uses CPPFLAGS
is so that <pthread.h> is parseable on OSF/1.
But let's not try to cater for all old cases in the pthread module.
Also Bruno said that the existing pthread.h using code
in pthread.m4 works on (possibly newer) OSF/1:
http://lists.gnu.org/archive/html/bug-gnulib/2012-07/msg00106.html

So the attached patch is now completely independent of the threadlib module,
and uses AC_DEFINE.

I'll push later.

thanks,
Pádraig.
>From e671c501e95e9372db2f61a86aa27c986895c943 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com>
Date: Fri, 13 Jun 2014 19:56:20 +0100
Subject: [PATCH] pthread: define thread safe macros on some platforms

* m4/pthread.m4 (gl_PTHREAD_CHECK): Define macros needed
for thread safe access on some platforms.
---
 ChangeLog     |    6 ++++++
 m4/pthread.m4 |   14 ++++++++++++++
 2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cd19897..27fc247 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-06-14  Pádraig Brady  <p...@draigbrady.com>
+
+	pthread: define thread safe macros on some platforms
+	* m4/pthread.m4 (gl_PTHREAD_CHECK): Define macros needed
+	for thread safe access on some platforms.
+
 2014-06-13  Paul Eggert  <egg...@cs.ucla.edu>
 
 	regex: don't be multithreaded if USE_UNLOCKED_IO.
diff --git a/m4/pthread.m4 b/m4/pthread.m4
index 1ed0dd3..cba1606 100644
--- a/m4/pthread.m4
+++ b/m4/pthread.m4
@@ -88,6 +88,20 @@ AC_DEFUN([gl_PTHREAD_CHECK],
    fi
    AC_SUBST([LIB_PTHREAD])
 
+   dnl Some systems optimize for single-threaded programs by default, and
+   dnl need special flags to disable these optimizations. For example, the
+   dnl definition of 'errno' in <errno.h>.
+   case "$host_os" in
+     aix* | freebsd*)
+       AC_DEFINE([_THREAD_SAFE], 1,
+         [Define on some systems, to enable only thread safe operations.])
+     ;;
+     osf* | solaris*)
+       AC_DEFINE([_REENTRANT], 1,
+         [Define on some systems, to enable only thread safe operations.])
+     ;;
+   esac
+
    AC_REQUIRE([AC_C_RESTRICT])
 ])
 
-- 
1.7.7.6

Reply via email to