diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2022-08-31 01:51:02 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2022-08-31 01:51:02 -0400 |
commit | 0fa33915da6255cf7460758197eaea7e43353543 (patch) | |
tree | 15a92a3aae2cd2647c24ce4c44f1aaca01fcf422 /src/discord/waiter.hpp | |
parent | 634f51fb4117c0870399e73560ac313d68d281e8 (diff) | |
download | abaddon-portaudio-0fa33915da6255cf7460758197eaea7e43353543.tar.gz abaddon-portaudio-0fa33915da6255cf7460758197eaea7e43353543.zip |
rudimentary voice implementation
Diffstat (limited to 'src/discord/waiter.hpp')
-rw-r--r-- | src/discord/waiter.hpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/discord/waiter.hpp b/src/discord/waiter.hpp new file mode 100644 index 0000000..0d5ae92 --- /dev/null +++ b/src/discord/waiter.hpp @@ -0,0 +1,29 @@ +#pragma once +#include <chrono> +#include <condition_variable> +#include <mutex> + +class Waiter { +public: + template<class R, class P> + bool wait_for(std::chrono::duration<R, P> const &time) const { + std::unique_lock<std::mutex> lock(m); + return !cv.wait_for(lock, time, [&] { return terminate; }); + } + + void kill() { + std::unique_lock<std::mutex> lock(m); + terminate = true; + cv.notify_all(); + } + + void revive() { + std::unique_lock<std::mutex> lock(m); + terminate = false; + } + +private: + mutable std::condition_variable cv; + mutable std::mutex m; + bool terminate = false; +}; |