mirror of https://github.com/Icinga/icinga2.git
Fix lock contention in ThreadPool::Post.
This commit is contained in:
parent
f176d8f28b
commit
3946c388c5
|
@ -205,17 +205,19 @@ void ThreadPool::QueueThreadProc(int tid)
|
||||||
*/
|
*/
|
||||||
bool ThreadPool::Post(const ThreadPool::WorkFunction& callback)
|
bool ThreadPool::Post(const ThreadPool::WorkFunction& callback)
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_Mutex);
|
|
||||||
|
|
||||||
if (m_Stopped)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
WorkItem wi;
|
WorkItem wi;
|
||||||
wi.Callback = callback;
|
wi.Callback = callback;
|
||||||
wi.Timestamp = Utility::GetTime();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue