public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Gthreads patch to disable static initializer macros
@ 2012-02-05 20:27 Jonathan Wakely
  2012-02-05 23:53 ` Jack Howarth
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Jonathan Wakely @ 2012-02-05 20:27 UTC (permalink / raw)
  To: gcc-patches; +Cc: Rainer Orth

[-- Attachment #1: Type: text/plain, Size: 1110 bytes --]

PRs libstdc++/51296 and libstdc++/51906 are both caused by problems
with the Pthreads static initializer macros such as
PTHREAD_MUTEX_INITIALIZER.

On Tru64 PTHREAD_MUTEX_INITIALIZER and PTHREAD_COND_INITIALIZER can
only be used for statically-initialized variables, as allowed by POSIX
currently, but http://austingroupbugs.net/view.php?id=70#c127 removes
that limitation for the next POSIX standard. C++11 needs to use those
macros for variables with automatic and dynamic scope, because the
init functions can't be used in constexpr constructors.

On Mac OS X 10.7 the PTHREAD_RECURSIVE_MUTEX_INITIALIZER is buggy.
This has shown up now because C++11 threads weren't enabled on darwin
before 4.7

My suggestion is to modify gthr-posix.h with the attached patch, so
that target maintainers can define e.g.
_GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC to force use of the init
function instead of the __GTHREAD_RECURSIVE_MUTEX_INIT initializer.
The patch includes a change to do that for darwin.

This has been testing on darwin, if Rainer tests it successfully on
Tru64 will the gthr-posix.h change be acceptable?

[-- Attachment #2: gthr-init.txt --]
[-- Type: text/plain, Size: 2633 bytes --]

diff --git a/libgcc/gthr-posix.h b/libgcc/gthr-posix.h
index 46054f6..45b15a8 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)
@@ -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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Gthreads patch to disable static initializer macros
  2012-02-05 20:27 Gthreads patch to disable static initializer macros Jonathan Wakely
@ 2012-02-05 23:53 ` Jack Howarth
  2012-02-06  0:10   ` Jonathan Wakely
  2012-02-06  6:40 ` Jakub Jelinek
  2012-02-06 19:24 ` Mike Stump
  2 siblings, 1 reply; 14+ messages in thread
From: Jack Howarth @ 2012-02-05 23:53 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-patches, Rainer Orth

On Sun, Feb 05, 2012 at 08:26:22PM +0000, Jonathan Wakely wrote:
> PRs libstdc++/51296 and libstdc++/51906 are both caused by problems
> with the Pthreads static initializer macros such as
> PTHREAD_MUTEX_INITIALIZER.
> 
> On Tru64 PTHREAD_MUTEX_INITIALIZER and PTHREAD_COND_INITIALIZER can
> only be used for statically-initialized variables, as allowed by POSIX
> currently, but http://austingroupbugs.net/view.php?id=70#c127 removes
> that limitation for the next POSIX standard. C++11 needs to use those
> macros for variables with automatic and dynamic scope, because the
> init functions can't be used in constexpr constructors.
> 
> On Mac OS X 10.7 the PTHREAD_RECURSIVE_MUTEX_INITIALIZER is buggy.
> This has shown up now because C++11 threads weren't enabled on darwin
> before 4.7
> 
> My suggestion is to modify gthr-posix.h with the attached patch, so
> that target maintainers can define e.g.
> _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC to force use of the init
> function instead of the __GTHREAD_RECURSIVE_MUTEX_INIT initializer.
> The patch includes a change to do that for darwin.
> 
> This has been testing on darwin, if Rainer tests it successfully on
> Tru64 will the gthr-posix.h change be acceptable?

There are no unexpected libstdc++ testsuite regressions on x86_64-apple-darwin11 with this
patch applied to current gcc trunk.


> diff --git a/libgcc/gthr-posix.h b/libgcc/gthr-posix.h
> index 46054f6..45b15a8 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)
> @@ -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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Gthreads patch to disable static initializer macros
  2012-02-05 23:53 ` Jack Howarth
@ 2012-02-06  0:10   ` Jonathan Wakely
  0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Wakely @ 2012-02-06  0:10 UTC (permalink / raw)
  To: Jack Howarth; +Cc: gcc-patches, Rainer Orth

On 5 February 2012 23:53, Jack Howarth wrote:
>
> There are no unexpected libstdc++ testsuite regressions on x86_64-apple-darwin11 with this
> patch applied to current gcc trunk.

Thanks, Jack.  If I can't get approval for the change I'll workaround
it in libstdc++, but IMHO it would be cleaner to change gthr-posix.h
to not define macros that can't be used safely.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Gthreads patch to disable static initializer macros
  2012-02-05 20:27 Gthreads patch to disable static initializer macros Jonathan Wakely
  2012-02-05 23:53 ` Jack Howarth
@ 2012-02-06  6:40 ` Jakub Jelinek
  2012-02-07  9:12   ` Jonathan Wakely
  2012-02-06 19:24 ` Mike Stump
  2 siblings, 1 reply; 14+ messages in thread
From: Jakub Jelinek @ 2012-02-06  6:40 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-patches, Rainer Orth

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.

> diff --git a/libgcc/gthr-posix.h b/libgcc/gthr-posix.h
> index 46054f6..45b15a8 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)
> @@ -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


	Jakub

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Gthreads patch to disable static initializer macros
  2012-02-05 20:27 Gthreads patch to disable static initializer macros Jonathan Wakely
  2012-02-05 23:53 ` Jack Howarth
  2012-02-06  6:40 ` Jakub Jelinek
@ 2012-02-06 19:24 ` Mike Stump
  2012-02-07 10:55   ` Jonathan Wakely
  2 siblings, 1 reply; 14+ messages in thread
From: Mike Stump @ 2012-02-06 19:24 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-patches, Rainer Orth

On Feb 5, 2012, at 12:26 PM, Jonathan Wakely wrote:
> PRs libstdc++/51296 and libstdc++/51906 are both caused by problems
> with the Pthreads static initializer macros such as
> PTHREAD_MUTEX_INITIALIZER.

> On Mac OS X 10.7 the PTHREAD_RECURSIVE_MUTEX_INITIALIZER is buggy.

Thanks for all you work on this.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Gthreads patch to disable static initializer macros
  2012-02-06  6:40 ` Jakub Jelinek
@ 2012-02-07  9:12   ` Jonathan Wakely
  2012-02-07  9:13     ` Jakub Jelinek
  0 siblings, 1 reply; 14+ messages in thread
From: Jonathan Wakely @ 2012-02-07  9:12 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, libstdc++

[-- Attachment #1: Type: text/plain, Size: 1598 bytes --]

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++

[-- Attachment #2: gthr.txt --]
[-- Type: text/plain, Size: 4530 bytes --]

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Gthreads patch to disable static initializer macros
  2012-02-07  9:12   ` Jonathan Wakely
@ 2012-02-07  9:13     ` Jakub Jelinek
  0 siblings, 0 replies; 14+ messages in thread
From: Jakub Jelinek @ 2012-02-07  9:13 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-patches, libstdc++

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Gthreads patch to disable static initializer macros
  2012-02-06 19:24 ` Mike Stump
@ 2012-02-07 10:55   ` Jonathan Wakely
  2012-02-10 15:11     ` Rainer Orth
  0 siblings, 1 reply; 14+ messages in thread
From: Jonathan Wakely @ 2012-02-07 10:55 UTC (permalink / raw)
  To: Mike Stump; +Cc: gcc-patches, Rainer Orth

On 6 February 2012 19:24, Mike Stump wrote:
> On Feb 5, 2012, at 12:26 PM, Jonathan Wakely wrote:
>> PRs libstdc++/51296 and libstdc++/51906 are both caused by problems
>> with the Pthreads static initializer macros such as
>> PTHREAD_MUTEX_INITIALIZER.
>
>> On Mac OS X 10.7 the PTHREAD_RECURSIVE_MUTEX_INITIALIZER is buggy.
>
> Thanks for all you work on this.

Well I broke it so I had to fix it ;)

I'm pleased to say we should now have an almost complete C++11 thread
implementation for most POSIX platforms, with hundreds of existing
libstdc++ tests moving from UNSUPPORTED to PASS on some secondary
platforms (aix and darwin, maybe hpux too.)

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Gthreads patch to disable static initializer macros
  2012-02-07 10:55   ` Jonathan Wakely
@ 2012-02-10 15:11     ` Rainer Orth
  2012-02-10 18:04       ` Jonathan Wakely
  2012-02-10 18:20       ` Jonathan Wakely
  0 siblings, 2 replies; 14+ messages in thread
From: Rainer Orth @ 2012-02-10 15:11 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Mike Stump, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1851 bytes --]

Jonathan Wakely <jwakely.gcc@gmail.com> writes:

> On 6 February 2012 19:24, Mike Stump wrote:
>> On Feb 5, 2012, at 12:26 PM, Jonathan Wakely wrote:
>>> PRs libstdc++/51296 and libstdc++/51906 are both caused by problems
>>> with the Pthreads static initializer macros such as
>>> PTHREAD_MUTEX_INITIALIZER.
>>
>>> On Mac OS X 10.7 the PTHREAD_RECURSIVE_MUTEX_INITIALIZER is buggy.
>>
>> Thanks for all you work on this.
>
> Well I broke it so I had to fix it ;)
>
> I'm pleased to say we should now have an almost complete C++11 thread
> implementation for most POSIX platforms, with hundreds of existing
> libstdc++ tests moving from UNSUPPORTED to PASS on some secondary
> platforms (aix and darwin, maybe hpux too.)

Indeed, thanks for your hard work on this.  The following patch on top
of your previous one allows the 30_threads tests to PASS on Tru64 UNIX.

Bootstrapped without regressions on alpha-dec-osf5.1b, ok for mainline?

I've also noticed one feature of your patch that I don't like:
__GTHREAD_{MUTEX,COND}_INIT_FUNCTION ignore the return values of
pthread_{mutex,cond}_init_function instead of passing them on as all
other gthr-posix.h functions do.  This might lead to bad error handling,
and my previous patch (based on an older version of yours you had
attached to the PR) changed them to return int instead.  I suppose
changing this now is out of question, and this is left as 4.8 material.

	Rainer


2012-02-03  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	libstdc++-v3:
	PR libstdc++/51296
	* config/os/osf/ctype_base.h,
	config/os/osf/ctype_configure_char.cc,
	config/os/osf/ctype_inline.h, config/os/osf/error_constants.h:
	Copy from config/os/generic.
	* config/os/osf/os_defines.h: Likewise.
	(_GTHREAD_USE_MUTEX_INIT_FUNC, _GTHREAD_USE_COND_INIT_FUNC):
	Define.
	* configure.host <osf*>: Use os/osf for os_include_dir.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: v3-mutex_init_function.patch --]
[-- Type: text/x-patch, Size: 2562 bytes --]

# HG changeset patch
# Parent badf67959a1e06e2f8c98df3797878e3123aad8e
Use __GTHREAD_MUTEX_INIT_FUNCTION on Tru64 UNIX (PR libstdc++/51296)

diff --git a/libstdc++-v3/config/os/generic/ctype_base.h b/libstdc++-v3/config/os/osf/ctype_base.h
copy from libstdc++-v3/config/os/generic/ctype_base.h
copy to libstdc++-v3/config/os/osf/ctype_base.h
diff --git a/libstdc++-v3/config/os/generic/ctype_configure_char.cc b/libstdc++-v3/config/os/osf/ctype_configure_char.cc
copy from libstdc++-v3/config/os/generic/ctype_configure_char.cc
copy to libstdc++-v3/config/os/osf/ctype_configure_char.cc
diff --git a/libstdc++-v3/config/os/generic/ctype_inline.h b/libstdc++-v3/config/os/osf/ctype_inline.h
copy from libstdc++-v3/config/os/generic/ctype_inline.h
copy to libstdc++-v3/config/os/osf/ctype_inline.h
diff --git a/libstdc++-v3/config/os/generic/error_constants.h b/libstdc++-v3/config/os/osf/error_constants.h
copy from libstdc++-v3/config/os/generic/error_constants.h
copy to libstdc++-v3/config/os/osf/error_constants.h
diff --git a/libstdc++-v3/config/os/generic/os_defines.h b/libstdc++-v3/config/os/osf/os_defines.h
copy from libstdc++-v3/config/os/generic/os_defines.h
copy to libstdc++-v3/config/os/osf/os_defines.h
--- a/libstdc++-v3/config/os/generic/os_defines.h
+++ b/libstdc++-v3/config/os/osf/os_defines.h
@@ -1,6 +1,6 @@
-// Specific definitions for generic platforms  -*- C++ -*-
+// Specific definitions for Tru64 UNIX  -*- C++ -*-
 
-// Copyright (C) 2000, 2009, 2010 Free Software Foundation, Inc.
+// Copyright (C) 2000, 2009, 2010, 2012 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -33,4 +33,9 @@
 // System-specific #define, typedefs, corrections, etc, go here.  This
 // file will come before all others.
 
+// Tru64 UNIX requires using pthread_mutex_init()/pthread_cond_init() to
+// initialized non-statically allocated mutexes/condvars.
+#define _GTHREAD_USE_MUTEX_INIT_FUNC
+#define _GTHREAD_USE_COND_INIT_FUNC
+
 #endif
diff --git a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host
--- a/libstdc++-v3/configure.host
+++ b/libstdc++-v3/configure.host
@@ -280,7 +280,7 @@ case "${host_os}" in
     os_include_dir="os/bsd/netbsd"
     ;;
   osf*)
-    os_include_dir="os/generic"
+    os_include_dir="os/osf"
     # libstdc++.so relies on emutls on Tru64 UNIX, which only works with the
     # real functions implemented in libpthread.so, not with the dummies in
     # libgcc, so always pass -lpthread.

[-- Attachment #3: Type: text/plain, Size: 144 bytes --]



-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Gthreads patch to disable static initializer macros
  2012-02-10 15:11     ` Rainer Orth
@ 2012-02-10 18:04       ` Jonathan Wakely
  2012-02-10 18:24         ` Rainer Orth
  2012-02-10 18:20       ` Jonathan Wakely
  1 sibling, 1 reply; 14+ messages in thread
From: Jonathan Wakely @ 2012-02-10 18:04 UTC (permalink / raw)
  To: Rainer Orth; +Cc: Mike Stump, gcc-patches

On 10 February 2012 14:48, Rainer Orth wrote:
> I've also noticed one feature of your patch that I don't like:
> __GTHREAD_{MUTEX,COND}_INIT_FUNCTION ignore the return values of
> pthread_{mutex,cond}_init_function instead of passing them on as all
> other gthr-posix.h functions do.  This might lead to bad error handling,
> and my previous patch (based on an older version of yours you had
> attached to the PR) changed them to return int instead.  I suppose
> changing this now is out of question, and this is left as 4.8 material.

I didn't like that feature of the patch much either, but the signature
of the mutex_init function is specified in gthr.h:

     __GTHREAD_MUTEX_INIT_FUNCTION
            some systems can't initialize a mutex without a
        function call.  On such systems, define this to a
        function which looks like this:
          void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *)

The recursive one says it should have the same signature, and I (maybe
wrongly) assumed the cond_init one should too.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Gthreads patch to disable static initializer macros
  2012-02-10 15:11     ` Rainer Orth
  2012-02-10 18:04       ` Jonathan Wakely
@ 2012-02-10 18:20       ` Jonathan Wakely
  1 sibling, 0 replies; 14+ messages in thread
From: Jonathan Wakely @ 2012-02-10 18:20 UTC (permalink / raw)
  To: Rainer Orth; +Cc: Mike Stump, gcc-patches

On 10 February 2012 14:48, Rainer Orth wrote:
>
> Bootstrapped without regressions on alpha-dec-osf5.1b, ok for mainline?

Yes, this is OK, thanks for your help testing and getting all of this working.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Gthreads patch to disable static initializer macros
  2012-02-10 18:04       ` Jonathan Wakely
@ 2012-02-10 18:24         ` Rainer Orth
  2012-02-10 18:29           ` Jonathan Wakely
  0 siblings, 1 reply; 14+ messages in thread
From: Rainer Orth @ 2012-02-10 18:24 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Mike Stump, gcc-patches

Jon,

> On 10 February 2012 14:48, Rainer Orth wrote:
>> I've also noticed one feature of your patch that I don't like:
>> __GTHREAD_{MUTEX,COND}_INIT_FUNCTION ignore the return values of
>> pthread_{mutex,cond}_init_function instead of passing them on as all
>> other gthr-posix.h functions do.  This might lead to bad error handling,
>> and my previous patch (based on an older version of yours you had
>> attached to the PR) changed them to return int instead.  I suppose
>> changing this now is out of question, and this is left as 4.8 material.
>
> I didn't like that feature of the patch much either, but the signature
> of the mutex_init function is specified in gthr.h:
>
>      __GTHREAD_MUTEX_INIT_FUNCTION
>             some systems can't initialize a mutex without a
>         function call.  On such systems, define this to a
>         function which looks like this:
>           void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *)
>
> The recursive one says it should have the same signature, and I (maybe

I don't see this, neither in gthr.h nor in gthr-posix.h.

> wrongly) assumed the cond_init one should too.

I don't think this is cast in stone: the gthr*.h headers aren't
installed in a public place and aren't considered an external interface
to the best of my knowledge, so it should be possible to change.

Currently, __GTHREAD_MUTEX_INIT_FUNCTION is only used in libgcc,
libgfortran, and libstdc++ (and __GTHREAD_COND_INIT_FUNCTION only in
libstdc++), so changing the 13 calls is doable.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Gthreads patch to disable static initializer macros
  2012-02-10 18:24         ` Rainer Orth
@ 2012-02-10 18:29           ` Jonathan Wakely
  2012-02-10 18:50             ` Rainer Orth
  0 siblings, 1 reply; 14+ messages in thread
From: Jonathan Wakely @ 2012-02-10 18:29 UTC (permalink / raw)
  To: Rainer Orth; +Cc: Mike Stump, gcc-patches

On 10 February 2012 18:20, Rainer Orth wrote:
> Jon,
>
>> On 10 February 2012 14:48, Rainer Orth wrote:
>>> I've also noticed one feature of your patch that I don't like:
>>> __GTHREAD_{MUTEX,COND}_INIT_FUNCTION ignore the return values of
>>> pthread_{mutex,cond}_init_function instead of passing them on as all
>>> other gthr-posix.h functions do.  This might lead to bad error handling,
>>> and my previous patch (based on an older version of yours you had
>>> attached to the PR) changed them to return int instead.  I suppose
>>> changing this now is out of question, and this is left as 4.8 material.
>>
>> I didn't like that feature of the patch much either, but the signature
>> of the mutex_init function is specified in gthr.h:
>>
>>      __GTHREAD_MUTEX_INIT_FUNCTION
>>             some systems can't initialize a mutex without a
>>         function call.  On such systems, define this to a
>>         function which looks like this:
>>           void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *)
>>
>> The recursive one says it should have the same signature, and I (maybe
>
> I don't see this, neither in gthr.h nor in gthr-posix.h.

lines 54-62 in http://gcc.gnu.org/viewcvs/trunk/libgcc/gthr.h?view=markup

>> wrongly) assumed the cond_init one should too.
>
> I don't think this is cast in stone: the gthr*.h headers aren't
> installed in a public place and aren't considered an external interface
> to the best of my knowledge, so it should be possible to change.
>
> Currently, __GTHREAD_MUTEX_INIT_FUNCTION is only used in libgcc,
> libgfortran, and libstdc++ (and __GTHREAD_COND_INIT_FUNCTION only in
> libstdc++), so changing the 13 calls is doable.


Private ports which provide their own gthr header (I think they're
rare, but do exist) would need to modify their functions to return an
integer - but at least it would be a compile-time failure so they'd
know to change it.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Gthreads patch to disable static initializer macros
  2012-02-10 18:29           ` Jonathan Wakely
@ 2012-02-10 18:50             ` Rainer Orth
  0 siblings, 0 replies; 14+ messages in thread
From: Rainer Orth @ 2012-02-10 18:50 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Mike Stump, gcc-patches

Jonathan Wakely <jwakely.gcc@gmail.com> writes:

>>> I didn't like that feature of the patch much either, but the signature
>>> of the mutex_init function is specified in gthr.h:
>>>
>>>      __GTHREAD_MUTEX_INIT_FUNCTION
>>>             some systems can't initialize a mutex without a
>>>         function call.  On such systems, define this to a
>>>         function which looks like this:
>>>           void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *)
>>>
>>> The recursive one says it should have the same signature, and I (maybe
>>
>> I don't see this, neither in gthr.h nor in gthr-posix.h.
>
> lines 54-62 in http://gcc.gnu.org/viewcvs/trunk/libgcc/gthr.h?view=markup

I think that's overinterpreting the comment.
__gthread_recursive_mutex_init_function happily returns errors with no
indication it should be otherwise.

>>> wrongly) assumed the cond_init one should too.
>>
>> I don't think this is cast in stone: the gthr*.h headers aren't
>> installed in a public place and aren't considered an external interface
>> to the best of my knowledge, so it should be possible to change.
>>
>> Currently, __GTHREAD_MUTEX_INIT_FUNCTION is only used in libgcc,
>> libgfortran, and libstdc++ (and __GTHREAD_COND_INIT_FUNCTION only in
>> libstdc++), so changing the 13 calls is doable.
>
> Private ports which provide their own gthr header (I think they're
> rare, but do exist) would need to modify their functions to return an
> integer - but at least it would be a compile-time failure so they'd
> know to change it.

Right, and that's the cost of keeping a port out of the FSF tree.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2012-02-10 18:29 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-05 20:27 Gthreads patch to disable static initializer macros Jonathan Wakely
2012-02-05 23:53 ` Jack Howarth
2012-02-06  0:10   ` Jonathan Wakely
2012-02-06  6:40 ` Jakub Jelinek
2012-02-07  9:12   ` Jonathan Wakely
2012-02-07  9:13     ` Jakub Jelinek
2012-02-06 19:24 ` Mike Stump
2012-02-07 10:55   ` Jonathan Wakely
2012-02-10 15:11     ` Rainer Orth
2012-02-10 18:04       ` Jonathan Wakely
2012-02-10 18:24         ` Rainer Orth
2012-02-10 18:29           ` Jonathan Wakely
2012-02-10 18:50             ` Rainer Orth
2012-02-10 18:20       ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).