ScopeRunner::stop now returns if count is already negative
This commit is contained in:
parent
474fab90f3
commit
e3789b6d4d
2 changed files with 4 additions and 0 deletions
|
|
@ -39,6 +39,8 @@ int main() {
|
||||||
assert(scope_runner.count == -1);
|
assert(scope_runner.count == -1);
|
||||||
auto lock = scope_runner.continue_lock();
|
auto lock = scope_runner.continue_lock();
|
||||||
assert(!lock);
|
assert(!lock);
|
||||||
|
scope_runner.stop();
|
||||||
|
assert(scope_runner.count == -1);
|
||||||
|
|
||||||
scope_runner.count = 0;
|
scope_runner.count = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -289,6 +289,8 @@ namespace SimpleWeb {
|
||||||
void stop() {
|
void stop() {
|
||||||
long expected = 0;
|
long expected = 0;
|
||||||
while(!count.compare_exchange_weak(expected, -1)) {
|
while(!count.compare_exchange_weak(expected, -1)) {
|
||||||
|
if(expected < 0)
|
||||||
|
return;
|
||||||
expected = 0;
|
expected = 0;
|
||||||
spin_loop_pause();
|
spin_loop_pause();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue