From e3789b6d4d99aa969e52708e2f77c4c8124a82d5 Mon Sep 17 00:00:00 2001 From: eidheim Date: Thu, 20 Jul 2017 18:32:35 +0200 Subject: [PATCH] ScopeRunner::stop now returns if count is already negative --- tests/io_test.cpp | 2 ++ utility.hpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/io_test.cpp b/tests/io_test.cpp index c15ddc2..514efba 100644 --- a/tests/io_test.cpp +++ b/tests/io_test.cpp @@ -39,6 +39,8 @@ int main() { assert(scope_runner.count == -1); auto lock = scope_runner.continue_lock(); assert(!lock); + scope_runner.stop(); + assert(scope_runner.count == -1); scope_runner.count = 0; diff --git a/utility.hpp b/utility.hpp index 94def45..6f733f9 100644 --- a/utility.hpp +++ b/utility.hpp @@ -289,6 +289,8 @@ namespace SimpleWeb { void stop() { long expected = 0; while(!count.compare_exchange_weak(expected, -1)) { + if(expected < 0) + return; expected = 0; spin_loop_pause(); }