fix(OnceFlag): add isSet and check before waiting (#6316)

This commit is contained in:
nerix
2025-07-03 23:22:15 +02:00
committed by GitHub
parent 2568d8a6ea
commit 70bdeb79c3
4 changed files with 39 additions and 1 deletions
+14
View File
@@ -16,6 +16,10 @@ void OnceFlag::set()
bool OnceFlag::waitFor(std::chrono::milliseconds ms)
{
std::unique_lock lock(this->mutex);
if (this->flag.load(std::memory_order::relaxed))
{
return true;
}
return this->condvar.wait_for(lock, ms, [this] {
return this->flag.load(std::memory_order::relaxed);
});
@@ -24,9 +28,19 @@ bool OnceFlag::waitFor(std::chrono::milliseconds ms)
void OnceFlag::wait()
{
std::unique_lock lock(this->mutex);
if (this->flag.load(std::memory_order::relaxed))
{
return;
}
this->condvar.wait(lock, [this] {
return this->flag.load(std::memory_order::relaxed);
});
}
bool OnceFlag::isSet()
{
std::unique_lock lock(this->mutex);
return this->flag.load(std::memory_order::relaxed);
}
} // namespace chatterino