Fix libstdc++/56002

Jonathan Wakely jwakely.gcc@gmail.com
Sat Mar 16 19:46:00 GMT 2013


This allows the generic locks to be used when threading is not enabled
or supported, so std::lock_guard etc. can be used with user-defined
mutex types.

        PR libstdc++/56002
        * include/std/mutex (lock_guard, unique_lock, lock): Define without
        depending on _GLIBCXX_HAS_GTHREADS.
        * testsuite/30_threads/lock_guard/cons/1.cc: Run on all targets.

Tested x86_64-linux, with posix and single thread models.
Committed to trunk. This should be safe for 4.7.3 and 4.8.1 so I'll
commit to the branches too at some point.
-------------- next part --------------
commit 90e586fcb5a2ab326e4b59a61fd5fd818fb31efe
Author: Jonathan Wakely <jwakely.gcc@gmail.com>
Date:   Sat Mar 16 18:26:59 2013 +0000

    	PR libstdc++/56002
    	* include/std/mutex (lock_guard, unique_lock, lock): Define without
    	depending on _GLIBCXX_HAS_GTHREADS.
    	* testsuite/30_threads/lock_guard/cons/1.cc: Run on all targets.

diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
index e327f28..67f3418 100644
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -45,12 +45,13 @@
 #include <bits/gthr.h>
 #include <bits/move.h> // for std::swap
 
-#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
+#ifdef _GLIBCXX_HAS_GTHREADS
   // Common base class for std::mutex and std::timed_mutex
   class __mutex_base
   {
@@ -384,6 +385,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       }
   };
 #endif
+#endif // _GLIBCXX_HAS_GTHREADS
 
   /// Do not acquire ownership of the mutex.
   struct defer_lock_t { };
@@ -719,6 +721,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
         }
     }
 
+#ifdef _GLIBCXX_HAS_GTHREADS
   /// once_flag
   struct once_flag
   {
@@ -790,12 +793,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       if (__e)
 	__throw_system_error(__e);
     }
+#endif // _GLIBCXX_HAS_GTHREADS
 
   // @} group mutexes
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
-
-#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1
+#endif // _GLIBCXX_USE_C99_STDINT_TR1
 
 #endif // C++11
 
diff --git a/libstdc++-v3/testsuite/30_threads/lock_guard/cons/1.cc b/libstdc++-v3/testsuite/30_threads/lock_guard/cons/1.cc
index d92e6ba..cd6d914 100644
--- a/libstdc++-v3/testsuite/30_threads/lock_guard/cons/1.cc
+++ b/libstdc++-v3/testsuite/30_threads/lock_guard/cons/1.cc
@@ -1,9 +1,6 @@
-// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* powerpc-ibm-aix* } }
-// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* powerpc-ibm-aix* } }
-// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
-// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-do run }
+// { dg-options " -std=gnu++11 " }
 // { dg-require-cstdint "" }
-// { dg-require-gthreads "" }
 
 // Copyright (C) 2010-2013 Free Software Foundation, Inc.
 //


More information about the Libstdc++ mailing list