mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +02:00
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user