Files
ternfs-XTXMarkets/cpp/core/Stopper.hpp
Francesco Mazzoli bf447408a6 Actually wait for things to finish terminating before reaping next one
Fixes #27. This is all kind of clunky right now, it would be much
better to just standardize the `run()` function pattern.
2023-07-26 22:31:42 +00:00

28 lines
402 B
C++

#pragma once
#include <atomic>
#include <mutex>
struct Stopper {
private:
std::atomic<bool> _stop;
std::mutex _stopped;
public:
Stopper() : _stop(false) {
_stopped.lock();
}
bool shouldStop() const {
return _stop.load();
}
void stopDone() {
_stopped.unlock();
}
void stop() {
_stop.store(true);
_stopped.lock();
}
};