From 0fb55060d25080d0b570545fc5f6052a14b9ea2d Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 20 Feb 2015 15:23:06 +0100 Subject: [PATCH] Fix another potential deadlock in SocketEvents::WakeUpThread refs #8484 --- lib/base/socketevents.cpp | 20 ++++++++++++-------- lib/base/socketevents.hpp | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) 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); + + while (l_SocketIOFDChanged) + l_SocketIOCV.wait(lock); + } + } else { (void) send(l_SocketIOEventFDs[1], "T", 1, 0); - - while (l_SocketIOFDChanged) - l_SocketIOCV.wait(lock); } } @@ -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;