libstdc++: Remove redundant copying of std::async arguments [PR 69724]
authorJonathan Wakely <jwakely@redhat.com>
Tue, 18 Aug 2020 13:23:19 +0000 (14:23 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 18 Aug 2020 13:28:38 +0000 (14:28 +0100)
commitbb1b7f087bdd028000fd8f84e74b20adccc9d5bb
tree65bdb476307e00f202d1de0f0b1d649342d4788e
parent634046d1a81b48a48b3564ff2f90974f6b7b087b
libstdc++: Remove redundant copying of std::async arguments [PR 69724]

As was previously done for std::thread, this removes an unnecessary copy
of an rvalue of type thread::_Invoker. Instead of creating the rvalue
and then moving that into the shared state, the member of the shared
state is initialized directly from the forwarded callable and bound
arguments.

This also slightly simplifies std::thread creation to remove the
_S_make_state helper function.

libstdc++-v3/ChangeLog:

PR libstdc++/69724
* include/std/future (__future_base::_S_make_deferred_state)
(__future_base::_S_make_async_state): Remove.
(__future_base::_Deferred_state): Change constructor to accept a
parameter pack of arguments and forward them to the call
wrapper.
(__future_base::_Async_state_impl): Likewise. Replace lambda
expression with a named member function.
(async): Construct state object directly from the arguments,
instead of using thread::__make_invoker, _S_make_deferred_state
and _S_make_async_state. Move shared state into the returned
future.
* include/std/thread (thread::_Call_wrapper): New alias
template for use by constructor and std::async.
(thread::thread(Callable&&, Args&&...)): Create state object
directly instead of using _S_make_state.
(thread::__make_invoker, thread::__decayed_tuple)
(thread::_S_make_state): Remove.
* testsuite/30_threads/async/69724.cc: New test.
libstdc++-v3/include/std/future
libstdc++-v3/include/std/thread
libstdc++-v3/testsuite/30_threads/async/69724.cc [new file with mode: 0644]