[cfe-commits] [libcxx] r159901 - /libcxx/trunk/include/__mutex_base

Dimitry Andric dimitry at andric.com
Mon Sep 10 13:17:12 PDT 2012


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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libcxx-mutex-initializer-1.diff
Type: text/x-diff
Size: 990 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120910/3edc8112/attachment.diff>


More information about the cfe-commits mailing list