diff mbox

[v3] add missing dg-require to tests

Message ID CAH6eHdSqJLgtmMak-UV7DfN=M5+k6=9nQDdUa7vJsdMpnNGvxw@mail.gmail.com
State New
Headers show

Commit Message

Jonathan Wakely Nov. 7, 2011, 10:26 p.m. UTC
On 7 November 2011 21:51, Jonathan Wakely wrote:
>
> Aha, this is a problem with all platforms where _GLIBCXX_HAVE_TLS is
> not defined, std::call_once uses std:function which assumes a copyable
> target object.
>
> I'm working on it ..
>

Fixed like so ...

        * include/std/mutex (call_once): Store closure in __once_functor
        as bound function wrapper might not be copyable.

The fix would be simpler but the lambda can't capture the parameter
pack directly because of PR c++/41933. Unfortunately the non-TLS
std::call_once implementation is quite wasteful, creating a function
wrapper, which is captured by a closure, which is stored in a
std::function.  IIRC the std::function has to be kept for backwards
compatibility, otherwise we could just store the closure and a pointer
to a function, like the TLS code but using a mutex to serialize calls.

Tested x86_64-linux and x86_64-netbsd5.1, committed to trunk.

Comments

Eric Botcazou Nov. 7, 2011, 11:55 p.m. UTC | #1
> Fixed like so ...
>
>         * include/std/mutex (call_once): Store closure in __once_functor
>         as bound function wrapper might not be copyable.
>
> The fix would be simpler but the lambda can't capture the parameter
> pack directly because of PR c++/41933. Unfortunately the non-TLS
> std::call_once implementation is quite wasteful, creating a function
> wrapper, which is captured by a closure, which is stored in a
> std::function.  IIRC the std::function has to be kept for backwards
> compatibility, otherwise we could just store the closure and a pointer
> to a function, like the TLS code but using a mutex to serialize calls.

Thanks a lot for the quick fix!
diff mbox

Patch

Index: include/std/mutex
===================================================================
--- include/std/mutex	(revision 181123)
+++ include/std/mutex	(working copy)
@@ -810,8 +810,9 @@ 
       __once_call = &__once_call_impl<decltype(__bound_functor)>;
 #else
       unique_lock<mutex> __functor_lock(__get_once_mutex());
-      __once_functor = std::__bind_simple(std::forward<_Callable>(__f),
+      auto __callable = std::__bind_simple(std::forward<_Callable>(__f),
           std::forward<_Args>(__args)...);
+      __once_functor = [&]() { __callable(); };
       __set_once_functor_lock_ptr(&__functor_lock);
 #endif