diff options
author | Max Kellermann <max@musicpd.org> | 2017-12-22 11:04:24 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-01-08 10:06:23 +0100 |
commit | 1f50bdb23075b817774c9ff0d033e7395be13067 (patch) | |
tree | 62fe4a9d3863aa51ece5605e9825dd74154ee02e /src | |
parent | 2eef4e67165c38c147980ead785bcf7180b53009 (diff) |
event/Loop: use std::atomic_bool for the "quit" variable
Fixes thread sanitizer warnings.
Diffstat (limited to 'src')
-rw-r--r-- | src/event/Loop.cxx | 6 | ||||
-rw-r--r-- | src/event/Loop.hxx | 3 |
2 files changed, 6 insertions, 3 deletions
diff --git a/src/event/Loop.cxx b/src/event/Loop.cxx index ada820c2d..9e09534da 100644 --- a/src/event/Loop.cxx +++ b/src/event/Loop.cxx @@ -27,7 +27,7 @@ #include <algorithm> EventLoop::EventLoop() - :SocketMonitor(*this) + :SocketMonitor(*this), quit(false) { SocketMonitor::Open(wake_fd.Get()); SocketMonitor::Schedule(SocketMonitor::READ); @@ -46,7 +46,9 @@ EventLoop::~EventLoop() void EventLoop::Break() { - quit = true; + if (quit.exchange(true)) + return; + wake_fd.Write(); } diff --git a/src/event/Loop.hxx b/src/event/Loop.hxx index 1060a8769..cf2ec33b2 100644 --- a/src/event/Loop.hxx +++ b/src/event/Loop.hxx @@ -30,6 +30,7 @@ #include "SocketMonitor.hxx" #include <chrono> +#include <atomic> #include <list> #include <set> @@ -82,7 +83,7 @@ class EventLoop final : SocketMonitor 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 |