1 // Copyright (C) 2019-2020 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-std=gnu++2a" }
19 // { dg-add-options libatomic }
20 // { dg-do run { target c++2a } }
23 #include <testsuite_hooks.h>
28 std::stop_source ssrc
;
29 std::stop_token tok
= ssrc
.get_token();
30 VERIFY(tok
.stop_possible());
31 VERIFY(!tok
.stop_requested());
33 std::stop_token
copy(tok
);
35 VERIFY(copy
.stop_possible());
36 VERIFY(!copy
.stop_requested());
37 VERIFY(tok
.stop_possible());
38 VERIFY(!tok
.stop_requested());
40 std::stop_token
move(std::move(tok
));
43 VERIFY(move
.stop_possible());
44 VERIFY(!move
.stop_requested());
45 VERIFY(!tok
.stop_possible());
46 VERIFY(!tok
.stop_requested());
47 VERIFY(copy
.stop_possible());
48 VERIFY(!copy
.stop_requested());
51 VERIFY(move
.stop_possible());
52 VERIFY(move
.stop_requested());
53 VERIFY(!tok
.stop_possible());
54 VERIFY(!tok
.stop_requested());
55 VERIFY(copy
.stop_possible());
56 VERIFY(copy
.stop_requested());
60 VERIFY(!move
.stop_possible());
61 VERIFY(!move
.stop_requested());
62 VERIFY(tok
.stop_possible());
63 VERIFY(tok
.stop_requested());
64 VERIFY(copy
.stop_possible());
65 VERIFY(copy
.stop_requested());
69 VERIFY(move
.stop_possible());
70 VERIFY(move
.stop_requested());
71 VERIFY(tok
.stop_possible());
72 VERIFY(tok
.stop_requested());
73 VERIFY(!copy
.stop_possible());
74 VERIFY(!copy
.stop_requested());
80 std::stop_source src1
, src2
;
81 std::stop_token tok
= src1
.get_token();
82 VERIFY(tok
.stop_possible());
83 VERIFY(!tok
.stop_requested());
85 std::stop_token copy
= src2
.get_token();
89 copy
= src2
.get_token();
97 std::stop_source ssrc
;
98 VERIFY(ssrc
.stop_possible());
99 VERIFY(!ssrc
.stop_requested());
101 // create stop_token from stop_source
102 std::stop_token stok
{ssrc
.get_token()};
103 VERIFY(ssrc
.stop_possible());
104 VERIFY(!ssrc
.stop_requested());
105 VERIFY(stok
.stop_possible());
106 VERIFY(!stok
.stop_requested());
109 bool cb1called
{false};
114 std::stop_callback scb1
{stok
, cb1
};
115 VERIFY(ssrc
.stop_possible());
116 VERIFY(!ssrc
.stop_requested());
117 VERIFY(stok
.stop_possible());
118 VERIFY(!stok
.stop_requested());
120 } // unregister callback
122 // register another callback
123 bool cb2called
{false};
125 VERIFY(stok
.stop_requested());
128 std::stop_callback scb2a
{stok
, cb2
}; // copies cb2
129 // std::stop_callback scb2b{stok, std::move(cb2)};
130 VERIFY(ssrc
.stop_possible());
131 VERIFY(!ssrc
.stop_requested());
132 VERIFY(stok
.stop_possible());
133 VERIFY(!stok
.stop_requested());
138 auto b
= ssrc
.request_stop();
140 VERIFY(ssrc
.stop_possible());
141 VERIFY(ssrc
.stop_requested());
142 VERIFY(stok
.stop_possible());
143 VERIFY(stok
.stop_requested());
147 b
= ssrc
.request_stop();
150 // register another callback
151 bool cb3called
{false};
152 std::stop_callback scb3
{stok
, [&]
156 VERIFY(ssrc
.stop_possible());
157 VERIFY(ssrc
.stop_requested());
158 VERIFY(stok
.stop_possible());
159 VERIFY(stok
.stop_requested());