]> granicus.if.org Git - icinga2/commitdiff
Fix lock contention in ThreadPool::Post.
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 18 Sep 2013 09:22:52 +0000 (11:22 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 18 Sep 2013 09:22:52 +0000 (11:22 +0200)
lib/base/threadpool.cpp

index 237ed4e8a2f2e43656e5027630e996e4940538e9..1b88f7d0f28d4ee078ccf07869bfcf76fc41689c 100644 (file)
@@ -205,17 +205,19 @@ void ThreadPool::QueueThreadProc(int tid)
  */
 bool ThreadPool::Post(const ThreadPool::WorkFunction& callback)
 {
-       boost::mutex::scoped_lock lock(m_Mutex);
-
-       if (m_Stopped)
-               return false;
-
        WorkItem wi;
        wi.Callback = callback;
        wi.Timestamp = Utility::GetTime();
 
-       m_WorkItems.push_back(wi);
-       m_WorkCV.notify_one();
+       {
+               boost::mutex::scoped_lock lock(m_Mutex);
+
+               if (m_Stopped)
+                       return false;
+
+               m_WorkItems.push_back(wi);
+               m_WorkCV.notify_one();
+       }
 
        return true;
 }