fix(once-flag): make flag atomic (#6237)

This commit is contained in:
nerix
2025-05-25 16:24:44 +02:00
committed by GitHub
parent 85ae913413
commit e9b3146a0e
3 changed files with 5 additions and 6 deletions
+3 -4
View File
@@ -3,13 +3,12 @@
namespace chatterino {
OnceFlag::OnceFlag() = default;
OnceFlag::~OnceFlag() = default;
void OnceFlag::set()
{
{
std::unique_lock guard(this->mutex);
this->flag = true;
this->flag.store(true, std::memory_order::relaxed);
}
this->condvar.notify_all();
}
@@ -18,7 +17,7 @@ bool OnceFlag::waitFor(std::chrono::milliseconds ms)
{
std::unique_lock lock(this->mutex);
return this->condvar.wait_for(lock, ms, [this] {
return this->flag;
return this->flag.load(std::memory_order::relaxed);
});
}
@@ -26,7 +25,7 @@ void OnceFlag::wait()
{
std::unique_lock lock(this->mutex);
this->condvar.wait(lock, [this] {
return this->flag;
return this->flag.load(std::memory_order::relaxed);
});
}