Fix lock contention in ThreadPool::Post.

This commit is contained in:
Gunnar Beutner 2013-09-18 11:22:52 +02:00
parent f176d8f28b
commit 3946c388c5
1 changed files with 9 additions and 7 deletions

View 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;
}