[cfe-commits] [PATCH] mutex: unify __mutex_base constructors

Saleem Abdulrasool compnerd at compnerd.org
Sun Dec 9 23:50:20 PST 2012


Use the _LIBCPP_CONSTEXPR macro to allow the preprocessor to determine if
constexpr should be applied to the constructor.  This is required to unify the
constructor definition.

Unify the constructor declarations, moving the member variable initialisation
into the initialiser-list.  This requires an ugly C-style cast to ensure
portability across all implementations.  PTHREAD_{MUTEX,COND}_INITIALIZER may be
an aggregate initialiser, which requires an explicit type conversion for the
compound literal.

http://llvm-reviews.chandlerc.com/D194

Files:
  include/__mutex_base

Index: include/__mutex_base
===================================================================
--- include/__mutex_base
+++ include/__mutex_base
@@ -37,13 +37,9 @@
     pthread_mutex_t __m_;
 
 public:
-    _LIBCPP_INLINE_VISIBILITY
-#ifndef _LIBCPP_HAS_NO_CONSTEXPR
-     constexpr mutex() _NOEXCEPT : __m_(PTHREAD_MUTEX_INITIALIZER) {}
-#else
-     mutex() _NOEXCEPT {__m_ = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;}
-#endif
-     ~mutex();
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR mutex() _NOEXCEPT
+        : __m_((pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER) {}
+    ~mutex();
 
 private:
     mutex(const mutex&);// = delete;
@@ -303,12 +299,8 @@
 {
     pthread_cond_t __cv_;
 public:
-    _LIBCPP_INLINE_VISIBILITY
-#ifndef _LIBCPP_HAS_NO_CONSTEXPR
-    constexpr condition_variable() : __cv_(PTHREAD_COND_INITIALIZER) {}
-#else
-    condition_variable() {__cv_ = (pthread_cond_t)PTHREAD_COND_INITIALIZER;}
-#endif
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR condition_variable()
+        : __cv_((pthread_cond_t)PTHREAD_COND_INITIALIZER) {}
     ~condition_variable();
 
 private:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D194.1.patch
Type: text/x-patch
Size: 1105 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121209/d6504e3a/attachment.bin>


More information about the cfe-commits mailing list