Commit 1f50bdb2 authored by Max Kellermann's avatar Max Kellermann

event/Loop: use std::atomic_bool for the "quit" variable

Fixes thread sanitizer warnings.
parent 2eef4e67
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <algorithm> #include <algorithm>
EventLoop::EventLoop() EventLoop::EventLoop()
:SocketMonitor(*this) :SocketMonitor(*this), quit(false)
{ {
SocketMonitor::Open(wake_fd.Get()); SocketMonitor::Open(wake_fd.Get());
SocketMonitor::Schedule(SocketMonitor::READ); SocketMonitor::Schedule(SocketMonitor::READ);
...@@ -46,7 +46,9 @@ EventLoop::~EventLoop() ...@@ -46,7 +46,9 @@ EventLoop::~EventLoop()
void void
EventLoop::Break() EventLoop::Break()
{ {
quit = true; if (quit.exchange(true))
return;
wake_fd.Write(); wake_fd.Write();
} }
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "SocketMonitor.hxx" #include "SocketMonitor.hxx"
#include <chrono> #include <chrono>
#include <atomic>
#include <list> #include <list>
#include <set> #include <set>
...@@ -82,7 +83,7 @@ class EventLoop final : SocketMonitor ...@@ -82,7 +83,7 @@ class EventLoop final : SocketMonitor
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
bool quit = false; std::atomic_bool quit;
/** /**
* True when the object has been modified and another check is * True when the object has been modified and another check is
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment