On 2012-07-07 22:01, Howard Hinnant wrote:
Author: hhinnant
Date: Sat Jul  7 15:01:52 2012
New Revision: 159901

URL: http://llvm.org/viewvc/llvm-project?rev=159901&view=rev
Log:
Apply constexpr to the mutex constructor.  As a conforming extension, apply 
constexpr to the condition_variable constructor.  These are important because 
it enables the compiler to construct these types at compile time, even though 
the object will be non-const.  Since they are constructed at compile time, 
there is no chance of a data race before they are constructed.
...
+#ifndef _LIBCPP_HAS_NO_CONSTEXPR
+     constexpr mutex() : __m_ PTHREAD_MUTEX_INITIALIZER {}
+#else
       mutex() {__m_ = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;}
+#endif
...
+#ifndef _LIBCPP_HAS_NO_CONSTEXPR
+    constexpr condition_variable() : __cv_ PTHREAD_COND_INITIALIZER {}
+#else
      condition_variable() {__cv_ = (pthread_cond_t)PTHREAD_COND_INITIALIZER;}
+#endif

On FreeBSD, PTHREAD_MUTEX_INITIALIZER and PTHREAD_COND_INITIALIZER are
both defined as NULL, which ends up as nullptr if you are using
-std=c++0x or higher.  This leads to compilation errors:

  /usr/include/c++/v1/__mutex_base:45:14: error: expected '{' or ','
       ~mutex();
               ^
  /usr/include/c++/v1/__mutex_base:311:26: error: expected '{' or ','
      ~condition_variable();
                           ^

Benjamin Kramer suggested to use parentheses around the initializers, as
per the attached patch.  He checked that this works on OSX, and I can
verify it works on FreeBSD.
Index: include/__mutex_base
===================================================================
--- include/__mutex_base	(revision 163535)
+++ include/__mutex_base	(working copy)
@@ -39,11 +39,11 @@ class _LIBCPP_VISIBLE mutex
 public:
     _LIBCPP_INLINE_VISIBILITY
 #ifndef _LIBCPP_HAS_NO_CONSTEXPR
-     constexpr mutex() _NOEXCEPT : __m_ PTHREAD_MUTEX_INITIALIZER {}
+     constexpr mutex() _NOEXCEPT : __m_(PTHREAD_MUTEX_INITIALIZER) {}
 #else
      mutex() _NOEXCEPT {__m_ = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;}
 #endif
-     ~mutex();
+     ~mutex(){}
 
 private:
     mutex(const mutex&);// = delete;
@@ -305,7 +305,7 @@ class _LIBCPP_VISIBLE condition_variable
 public:
     _LIBCPP_INLINE_VISIBILITY
 #ifndef _LIBCPP_HAS_NO_CONSTEXPR
-    constexpr condition_variable() : __cv_ PTHREAD_COND_INITIALIZER {}
+    constexpr condition_variable() : __cv_(PTHREAD_COND_INITIALIZER) {}
 #else
     condition_variable() {__cv_ = (pthread_cond_t)PTHREAD_COND_INITIALIZER;}
 #endif
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to