mirror of
https://github.com/XTXMarkets/ternfs.git
synced 2026-01-25 04:19:07 -06:00
Fixes #27. This is all kind of clunky right now, it would be much better to just standardize the `run()` function pattern.
28 lines
402 B
C++
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();
|
|
}
|
|
}; |