aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2016-10-12 12:20:25 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2016-10-12 12:20:25 +0100
commit164b41ebf3e25bdb0b30e230591c463ce56df9d4 (patch)
tree3216774db7ccc7f7708ef860c8e890d4286a89aa /libstdc++-v3/include
parenta15ebbcde01c0d6b941f24fcb70cc1412a033b6d (diff)
downloadgcc-164b41ebf3e25bdb0b30e230591c463ce56df9d4.zip
gcc-164b41ebf3e25bdb0b30e230591c463ce56df9d4.tar.gz
gcc-164b41ebf3e25bdb0b30e230591c463ce56df9d4.tar.bz2
Do not copy std:call_once arguments (LWG 2442)
* doc/xml/manual/intro.xml: Document LWG 2442 status. * include/std/mutex [_GLIBCXX_HAVE_TLS] (__once_call_impl): Remove. [_GLIBCXX_HAVE_TLS] (_Once_call): Declare primary template and define partial specialization to unpack args and forward to std::invoke. (call_once) [_GLIBCXX_HAVE_TLS]: Use forward_as_tuple and _Once_call instead of __bind_simple and __once_call_impl. (call_once) [!_GLIBCXX_HAVE_TLS]: Use __invoke instead of __bind_simple. * testsuite/30_threads/call_once/dr2442.cc: New test. From-SVN: r241031
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r--libstdc++-v3/include/std/mutex35
1 files changed, 23 insertions, 12 deletions
diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
index 7a7bd2e..4c6f036 100644
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -580,12 +580,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
extern __thread void* __once_callable;
extern __thread void (*__once_call)();
- template<typename _Callable>
- inline void
- __once_call_impl()
+ template<typename _Tuple, typename _IndexSeq
+ = typename _Build_index_tuple<tuple_size<_Tuple>::value>::__type>
+ struct _Once_call;
+
+ template<typename _Tuple, size_t... _Ind>
+ struct _Once_call<_Tuple, _Index_tuple<_Ind...>>
{
- (*(_Callable*)__once_callable)();
- }
+ static void
+ _S_call()
+ {
+ auto& __f_args = *static_cast<_Tuple*>(__once_callable);
+ std::__invoke(std::get<_Ind>(std::move(__f_args))...);
+ }
+ };
#else
extern function<void()> __once_functor;
@@ -603,16 +611,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void
call_once(once_flag& __once, _Callable&& __f, _Args&&... __args)
{
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 2442. call_once() shouldn't DECAY_COPY()
#ifdef _GLIBCXX_HAVE_TLS
- auto __bound_functor = std::__bind_simple(std::forward<_Callable>(__f),
- std::forward<_Args>(__args)...);
- __once_callable = std::__addressof(__bound_functor);
- __once_call = &__once_call_impl<decltype(__bound_functor)>;
+ auto __f_args = std::forward_as_tuple(
+ std::forward<_Callable>(__f), std::forward<_Args>(__args)...);
+ __once_callable = std::__addressof(__f_args);
+ __once_call = _Once_call<decltype(__f_args)>::_S_call;
#else
unique_lock<mutex> __functor_lock(__get_once_mutex());
- auto __callable = std::__bind_simple(std::forward<_Callable>(__f),
- std::forward<_Args>(__args)...);
- __once_functor = [&]() { __callable(); };
+ __once_functor = [&] {
+ std::__invoke(std::forward<_Callable>(__f),
+ std::forward<_Args>(__args)...);
+ };
__set_once_functor_lock_ptr(&__functor_lock);
#endif