chore: use condition variable to shutdown websocket pools (#5721)

This commit is contained in:
nerix
2024-11-20 22:29:47 +01:00
committed by GitHub
parent 19f449866e
commit 1c827f6288
9 changed files with 237 additions and 30 deletions
+33
View File
@@ -0,0 +1,33 @@
#include "util/OnceFlag.hpp"
namespace chatterino {
OnceFlag::OnceFlag() = default;
OnceFlag::~OnceFlag() = default;
void OnceFlag::set()
{
{
std::unique_lock guard(this->mutex);
this->flag = true;
}
this->condvar.notify_all();
}
bool OnceFlag::waitFor(std::chrono::milliseconds ms)
{
std::unique_lock lock(this->mutex);
return this->condvar.wait_for(lock, ms, [this] {
return this->flag;
});
}
void OnceFlag::wait()
{
std::unique_lock lock(this->mutex);
this->condvar.wait(lock, [this] {
return this->flag;
});
}
} // namespace chatterino