]> granicus.if.org Git - icinga2/commitdiff
Fix another potential deadlock in SocketEvents::WakeUpThread
authorGunnar Beutner <gunnar@beutner.name>
Fri, 20 Feb 2015 14:23:06 +0000 (15:23 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Fri, 20 Feb 2015 14:25:56 +0000 (15:25 +0100)
refs #8484

lib/base/socketevents.cpp
lib/base/socketevents.hpp

index aa1cc6ee6f2c37ef262f8e9fe615834932a8265a..fdf49ee65665181dd04c3d54714cb907445f161c 100644 (file)
@@ -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)
index 645de789b4579e7bc16700c114e2aecef563f541..2523d654347cef4357beda3a5d1f197270b30a77 100644 (file)
@@ -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;