From: Gunnar Beutner Date: Fri, 20 Feb 2015 14:23:06 +0000 (+0100) Subject: Fix another potential deadlock in SocketEvents::WakeUpThread X-Git-Tag: v2.3.0~169 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0fb55060d25080d0b570545fc5f6052a14b9ea2d;p=icinga2 Fix another potential deadlock in SocketEvents::WakeUpThread refs #8484 --- diff --git a/lib/base/socketevents.cpp b/lib/base/socketevents.cpp index aa1cc6ee6..fdf49ee65 100644 --- a/lib/base/socketevents.cpp +++ b/lib/base/socketevents.cpp @@ -149,17 +149,21 @@ void SocketEvents::ThreadProc(void) } } -void SocketEvents::WakeUpThread(void) +void SocketEvents::WakeUpThread(bool wait) { - if (boost::this_thread::get_id() != l_SocketIOThread.get_id()) { - boost::mutex::scoped_lock lock(l_SocketIOMutex); + if (wait) { + if (boost::this_thread::get_id() != l_SocketIOThread.get_id()) { + boost::mutex::scoped_lock lock(l_SocketIOMutex); - l_SocketIOFDChanged = true; + l_SocketIOFDChanged = true; - (void) send(l_SocketIOEventFDs[1], "T", 1, 0); + (void) send(l_SocketIOEventFDs[1], "T", 1, 0); - while (l_SocketIOFDChanged) - l_SocketIOCV.wait(lock); + while (l_SocketIOFDChanged) + l_SocketIOCV.wait(lock); + } + } else { + (void) send(l_SocketIOEventFDs[1], "T", 1, 0); } } @@ -209,7 +213,7 @@ void SocketEvents::Unregister(void) m_FD = INVALID_SOCKET; } - WakeUpThread(); + WakeUpThread(true); } void SocketEvents::ChangeEvents(int events) diff --git a/lib/base/socketevents.hpp b/lib/base/socketevents.hpp index 645de789b..2523d6543 100644 --- a/lib/base/socketevents.hpp +++ b/lib/base/socketevents.hpp @@ -51,7 +51,7 @@ private: static void InitializeThread(void); static void ThreadProc(void); - static void WakeUpThread(void); + static void WakeUpThread(bool wait = false); int GetPollEvents(void) const;