From f8bb66b4e0e90438b15bbfdd73e54973cf2d6ad1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 22 Dec 2017 11:04:24 +0100 Subject: [PATCH] event/Loop: use std::atomic_bool for the "quit" variable Fixes thread sanitizer warnings. --- src/event/Loop.cxx | 5 ++--- src/event/Loop.hxx | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/event/Loop.cxx b/src/event/Loop.cxx index 9bfeb9e9e..af488b899 100644 --- a/src/event/Loop.cxx +++ b/src/event/Loop.cxx @@ -25,7 +25,7 @@ #include "util/ScopeExit.hxx" EventLoop::EventLoop(ThreadId _thread) - :SocketMonitor(*this), thread(_thread) + :SocketMonitor(*this), quit(false), thread(_thread) { SocketMonitor::Open(SocketDescriptor(wake_fd.Get())); } @@ -39,10 +39,9 @@ EventLoop::~EventLoop() void EventLoop::Break() { - if (quit) + if (quit.exchange(true)) return; - quit = true; wake_fd.Write(); } diff --git a/src/event/Loop.hxx b/src/event/Loop.hxx index 7b9ec69e4..1d516020d 100644 --- a/src/event/Loop.hxx +++ b/src/event/Loop.hxx @@ -36,6 +36,7 @@ #include #include +#include #include @@ -85,7 +86,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