libstdc++: Fix <stop_token> and improve tests
authorJonathan Wakely <jwakely@redhat.com>
Fri, 15 Nov 2019 23:44:47 +0000 (23:44 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 15 Nov 2019 23:44:47 +0000 (23:44 +0000)
commite73ca078b8d9de25593006ae573b48ae6b12576c
tree40a58633577e8773f091cf2c351fbaacc9b42cf9
parentd5fbe5e014bc9fc803604eec805392c21ff4da16
libstdc++: Fix <stop_token> and improve tests

* include/std/stop_token: Reduce header dependencies by including
internal headers.
(stop_token::swap(stop_token&), swap(stop_token&, stop_token&)):
Define.
(operator!=(const stop_token&, const stop_token&)): Fix return value.
(stop_token::_Stop_cb::_Stop_cb(Cb&&)): Use std::forward instead of
(stop_token::_Stop_state_t) [_GLIBCXX_HAS_GTHREADS]: Use lock_guard
instead of unique_lock.
[!_GLIBCXX_HAS_GTHREADS]: Do not use mutex.
(stop_token::stop_token(_Stop_state)): Change parameter to lvalue
reference.
(stop_source): Remove unnecessary using-declarations for names only
used once.
(swap(stop_source&, stop_source&)): Define.
(stop_callback(const stop_token&, _Cb&&))
(stop_callback(stop_token&&, _Cb&&)): Replace lambdas with a named
function. Use std::forward instead of std::move. Run callbacks if a
stop request has already been made.
(stop_source::_M_execute()): Remove.
(stop_source::_S_execute(_Stop_cb*)): Define.
* include/std/version (__cpp_lib_jthread): Define conditionally.
* testsuite/30_threads/stop_token/stop_callback.cc: New test.
* testsuite/30_threads/stop_token/stop_source.cc: New test.
* testsuite/30_threads/stop_token/stop_token.cc: Enable test for
immediate execution of callback.

From-SVN: r278325
libstdc++-v3/ChangeLog
libstdc++-v3/include/std/stop_token
libstdc++-v3/include/std/version
libstdc++-v3/testsuite/30_threads/stop_token/stop_callback.cc [new file with mode: 0644]
libstdc++-v3/testsuite/30_threads/stop_token/stop_source.cc
libstdc++-v3/testsuite/30_threads/stop_token/stop_token.cc