Renamed ScopesContinue to ScopeRunner, and some related cleanup

This commit is contained in:
eidheim 2017-07-20 17:21:19 +02:00
commit 474fab90f3
6 changed files with 58 additions and 56 deletions

View file

@ -253,13 +253,13 @@ namespace SimpleWeb {
namespace SimpleWeb {
/// Makes it possible to for instance cancel Asio handlers without stopping asio::io_service
class ScopesContinue {
class ScopeRunner {
/// Scope count that is set to -1 if scopes are to be canceled
std::atomic<long> count;
public:
class SharedLock {
friend class ScopesContinue;
friend class ScopeRunner;
std::atomic<long> &count;
SharedLock(std::atomic<long> &count) : count(count) {}
SharedLock &operator=(const SharedLock &) = delete;
@ -271,10 +271,10 @@ namespace SimpleWeb {
}
};
ScopesContinue() : count(0) {}
ScopeRunner() : count(0) {}
/// Returns nullptr if scope is to be cancelled, or a shared lock otherwise
std::unique_ptr<SharedLock> shared_lock() {
/// Returns nullptr if scope should be exited, or a shared lock otherwise
std::unique_ptr<SharedLock> continue_lock() {
long expected = count;
while(expected >= 0 && !count.compare_exchange_weak(expected, expected + 1))
spin_loop_pause();