diff mbox

Gthreads patch to disable static initializer macros

Message ID CAH6eHdThWs-AiLfApqT=5TtX_6_4wAxOG18nOL1ZW2fZ2StM=w@mail.gmail.com
State New
Headers show

Commit Message

Jonathan Wakely Feb. 7, 2012, 9:11 a.m. UTC
On 6 February 2012 06:40, Jakub Jelinek wrote:
> On Sun, Feb 05, 2012 at 08:26:22PM +0000, Jonathan Wakely wrote:
>> This has been testing on darwin, if Rainer tests it successfully on
>> Tru64 will the gthr-posix.h change be acceptable?
>
> Ok with a suitable ChangeLog entry.

Jakub, further to the patch you approved this version unconditionally
defines a weak reference to pthread_cond_init (rather than only doing
it for libobjc) so that it can be used by
__gthread_cond_init_function() if _GTHREAD_USE_COND_INIT_FUNC is
defined.  Testing with _GTHREAD_USE_COND_INIT_FUNC revealed that was
necessary.

gthr-posix.h changes OK as attached, with this ChangeLog?

libgcc/
2012-02-07  Jonathan Wakely  <jwakely.gcc@gmail.com>

        PR libstdc++/51906
        PR libstdc++/51296
        * gthr-posix.h: Allow static initializer macros to be disabled.
        (__gthrw_pthread_cond_init): Define weak reference unconditionally.

libstdc++-v3/
2012-02-07  Jonathan Wakely  <jwakely.gcc@gmail.com>

        PR libstdc++/51296
        * include/std/mutex (__mutex_base::~__mutex_base): Declare noexcept.
        * src/c++11/condition_variable.cc (condition_variable): Use macro for
        initializer function.

        PR libstdc++/51906
        * config/os/bsd/darwin/os_defines.h: Disable static initializer for
        recursive mutexes.

Tested x86_64-linux with --enable-languages=c,c++,objc,obj-c++, both
with and without the new _GTHREAD_USE_XXX_INIT_FUNC macros defined.

Also tested on i686-linux, powerpc-linux, x86_64-netbsd with default
configuration and just --enable-languages=c,c++

Comments

Jakub Jelinek Feb. 7, 2012, 9:13 a.m. UTC | #1
On Tue, Feb 07, 2012 at 09:11:38AM +0000, Jonathan Wakely wrote:
> gthr-posix.h changes OK as attached, with this ChangeLog?

Okay.  Thanks.

> libgcc/
> 2012-02-07  Jonathan Wakely  <jwakely.gcc@gmail.com>
> 
>         PR libstdc++/51906
>         PR libstdc++/51296
>         * gthr-posix.h: Allow static initializer macros to be disabled.
>         (__gthrw_pthread_cond_init): Define weak reference unconditionally.
> 
> libstdc++-v3/
> 2012-02-07  Jonathan Wakely  <jwakely.gcc@gmail.com>
> 
>         PR libstdc++/51296
>         * include/std/mutex (__mutex_base::~__mutex_base): Declare noexcept.
>         * src/c++11/condition_variable.cc (condition_variable): Use macro for
>         initializer function.
> 
>         PR libstdc++/51906
>         * config/os/bsd/darwin/os_defines.h: Disable static initializer for
>         recursive mutexes.
> 
> Tested x86_64-linux with --enable-languages=c,c++,objc,obj-c++, both
> with and without the new _GTHREAD_USE_XXX_INIT_FUNC macros defined.
> 
> Also tested on i686-linux, powerpc-linux, x86_64-netbsd with default
> configuration and just --enable-languages=c,c++

	Jakub
diff mbox

Patch

diff --git a/libgcc/gthr-posix.h b/libgcc/gthr-posix.h
index 46054f6..a935e92 100644
--- a/libgcc/gthr-posix.h
+++ b/libgcc/gthr-posix.h
@@ -74,6 +74,20 @@  typedef struct timespec __gthread_time_t;
 #define __GTHREAD_COND_INIT PTHREAD_COND_INITIALIZER
 #define __GTHREAD_TIME_INIT {0,0}
 
+#ifdef _GTHREAD_USE_MUTEX_INIT_FUNC
+# undef __GTHREAD_MUTEX_INIT
+# define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
+#endif
+#ifdef _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC
+# undef __GTHREAD_RECURSIVE_MUTEX_INIT
+# undef __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION
+# define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
+#endif
+#ifdef _GTHREAD_USE_COND_INIT_FUNC
+# undef __GTHREAD_COND_INIT
+# define __GTHREAD_COND_INIT_FUNCTION __gthread_cond_init_function
+#endif
+
 #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
 # ifndef __gthrw_pragma
 #  define __gthrw_pragma(pragma)
@@ -116,6 +130,7 @@  __gthrw3(pthread_mutex_unlock)
 __gthrw3(pthread_mutex_init)
 __gthrw3(pthread_mutex_destroy)
 
+__gthrw3(pthread_cond_init)
 __gthrw3(pthread_cond_broadcast)
 __gthrw3(pthread_cond_signal)
 __gthrw3(pthread_cond_wait)
@@ -145,6 +160,7 @@  __gthrw(pthread_mutex_unlock)
 __gthrw(pthread_mutex_init)
 __gthrw(pthread_mutex_destroy)
 
+__gthrw(pthread_cond_init)
 __gthrw(pthread_cond_broadcast)
 __gthrw(pthread_cond_signal)
 __gthrw(pthread_cond_wait)
@@ -162,10 +178,8 @@  __gthrw(pthread_mutexattr_destroy)
 #if defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)
 /* Objective-C.  */
 #if defined(__osf__) && defined(_PTHREAD_USE_MANGLED_NAMES_)
-__gthrw3(pthread_cond_init)
 __gthrw3(pthread_exit)
 #else
-__gthrw(pthread_cond_init)
 __gthrw(pthread_exit)
 #endif /* __osf__ && _PTHREAD_USE_MANGLED_NAMES_ */
 #ifdef _POSIX_PRIORITY_SCHEDULING
@@ -730,6 +744,15 @@  __gthread_setspecific (__gthread_key_t __key, const void *__ptr)
   return __gthrw_(pthread_setspecific) (__key, __ptr);
 }
 
+#ifdef _GTHREAD_USE_MUTEX_INIT_FUNC
+static inline void
+__gthread_mutex_init_function (__gthread_mutex_t *__mutex)
+{
+  if (__gthread_active_p ())
+    __gthrw_(pthread_mutex_init) (__mutex, NULL);
+}
+#endif
+
 static inline int
 __gthread_mutex_destroy (__gthread_mutex_t *__mutex)
 {
@@ -778,7 +801,8 @@  __gthread_mutex_unlock (__gthread_mutex_t *__mutex)
     return 0;
 }
 
-#ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+#if !defined( PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) \
+  || defined(_GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC)
 static inline int
 __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
 {
@@ -828,6 +852,15 @@  __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
   return __gthread_mutex_unlock (__mutex);
 }
 
+#ifdef _GTHREAD_USE_COND_INIT_FUNC
+static inline void
+__gthread_cond_init_function (__gthread_cond_t *__cond)
+{
+  if (__gthread_active_p ())
+    __gthrw_(pthread_cond_init) (__cond, NULL);
+}
+#endif
+
 static inline int
 __gthread_cond_broadcast (__gthread_cond_t *__cond)
 {
diff --git a/libstdc++-v3/config/os/bsd/darwin/os_defines.h b/libstdc++-v3/config/os/bsd/darwin/os_defines.h
index ccefeaf..421478d 100644
--- a/libstdc++-v3/config/os/bsd/darwin/os_defines.h
+++ b/libstdc++-v3/config/os/bsd/darwin/os_defines.h
@@ -39,4 +39,7 @@ 
 // -flat_namespace to work around the way that it doesn't.
 #define _GLIBCXX_WEAK_DEFINITION __attribute__ ((weak))
 
+// Static initializer macro is buggy in darwin, see libstdc++/51906
+#define _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC
+
 #endif
diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
index 69e26e6..a7ebace 100644
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -71,7 +71,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       __GTHREAD_MUTEX_INIT_FUNCTION(&_M_mutex);
     }
 
-    ~__mutex_base() { __gthread_mutex_destroy(&_M_mutex); }
+    ~__mutex_base() noexcept { __gthread_mutex_destroy(&_M_mutex); }
 #endif
 
     __mutex_base(const __mutex_base&) = delete;
diff --git a/libstdc++-v3/src/c++11/condition_variable.cc b/libstdc++-v3/src/c++11/condition_variable.cc
index 400fcf3..9cd0763 100644
--- a/libstdc++-v3/src/c++11/condition_variable.cc
+++ b/libstdc++-v3/src/c++11/condition_variable.cc
@@ -36,10 +36,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #else
   condition_variable::condition_variable() noexcept
   {
-    int __e = __gthread_cond_init(&_M_cond, 0);
-
-    if (__e)
-      __throw_system_error(__e);
+    __GTHREAD_COND_INIT_FUNCTION(&_M_cond);
   }
 
   condition_variable::~condition_variable() noexcept