fix(once-flag): make flag atomic (#6237)
This commit is contained in:
@@ -53,6 +53,7 @@
|
|||||||
- Dev: Fixed incorrect lua generation of static methods for typescript plugins. (#6190, #6223)
|
- Dev: Fixed incorrect lua generation of static methods for typescript plugins. (#6190, #6223)
|
||||||
- Dev: Merged top/bottom and left/right notebook layouts. (#6215)
|
- Dev: Merged top/bottom and left/right notebook layouts. (#6215)
|
||||||
- Dev: Refactored `Button` and friends. (#6102)
|
- Dev: Refactored `Button` and friends. (#6102)
|
||||||
|
- Dev: `OnceFlag`'s internal flag is now atomic. (#6237)
|
||||||
- Dev: Bumped clang-format requirement to 19. (#6236)
|
- Dev: Bumped clang-format requirement to 19. (#6236)
|
||||||
|
|
||||||
## 2.5.3
|
## 2.5.3
|
||||||
|
|||||||
@@ -3,13 +3,12 @@
|
|||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
OnceFlag::OnceFlag() = default;
|
OnceFlag::OnceFlag() = default;
|
||||||
OnceFlag::~OnceFlag() = default;
|
|
||||||
|
|
||||||
void OnceFlag::set()
|
void OnceFlag::set()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::unique_lock guard(this->mutex);
|
std::unique_lock guard(this->mutex);
|
||||||
this->flag = true;
|
this->flag.store(true, std::memory_order::relaxed);
|
||||||
}
|
}
|
||||||
this->condvar.notify_all();
|
this->condvar.notify_all();
|
||||||
}
|
}
|
||||||
@@ -18,7 +17,7 @@ bool OnceFlag::waitFor(std::chrono::milliseconds ms)
|
|||||||
{
|
{
|
||||||
std::unique_lock lock(this->mutex);
|
std::unique_lock lock(this->mutex);
|
||||||
return this->condvar.wait_for(lock, ms, [this] {
|
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);
|
std::unique_lock lock(this->mutex);
|
||||||
this->condvar.wait(lock, [this] {
|
this->condvar.wait(lock, [this] {
|
||||||
return this->flag;
|
return this->flag.load(std::memory_order::relaxed);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ class OnceFlag
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OnceFlag();
|
OnceFlag();
|
||||||
~OnceFlag();
|
|
||||||
|
|
||||||
/// Set this flag and notify waiters
|
/// Set this flag and notify waiters
|
||||||
void set();
|
void set();
|
||||||
@@ -35,7 +34,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::mutex mutex;
|
std::mutex mutex;
|
||||||
std::condition_variable condvar;
|
std::condition_variable condvar;
|
||||||
bool flag = false;
|
std::atomic<bool> flag = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|||||||
Reference in New Issue
Block a user