From 3946c388c5d56913610a29f8bf9556e9cc3d53ef Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 18 Sep 2013 11:22:52 +0200 Subject: [PATCH] Fix lock contention in ThreadPool::Post. --- lib/base/threadpool.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/base/threadpool.cpp b/lib/base/threadpool.cpp index 237ed4e8a..1b88f7d0f 100644 --- a/lib/base/threadpool.cpp +++ b/lib/base/threadpool.cpp @@ -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; }