#include #include namespace pEp { class Semaphore { std::mutex mtx; std::condition_variable cv; bool _stop; public: Semaphore() : _stop(false) { } void stop() { std::unique_lock lock(mtx); _stop = true; } void try_wait() { std::unique_lock lock(mtx); if (!_stop) return; while(_stop) cv.wait(lock); } void go() { std::unique_lock lock(mtx); _stop = false; cv.notify_all(); } }; }