]> granicus.if.org Git - icinga2/commitdiff
Ensure that the main thread pool gets re-initialized properly after fork()
authorGunnar Beutner <gunnar@beutner.name>
Wed, 21 Oct 2015 05:02:49 +0000 (07:02 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Wed, 21 Oct 2015 07:18:52 +0000 (09:18 +0200)
refs #10410

lib/base/application.cpp
lib/base/threadpool.cpp

index 05d7fb6d2ec365eb7c58458b458f8b4f41a39b00..0c8aef26608100002d822ca53c392995f928a462 100644 (file)
@@ -144,7 +144,7 @@ void Application::InitializeBase(void)
        Loader::ExecuteDeferredInitializers();
 
        /* make sure the thread pool gets initialized */
-       GetTP();
+       GetTP().Start();
 
        Timer::Initialize();
 }
index 4a4d5fd0d67571f7a2b7e1f38f4b81609f0e5639..8f516879d7489086b55641aedc4023208fdc0af8 100644 (file)
@@ -31,7 +31,7 @@ using namespace icinga;
 int ThreadPool::m_NextID = 1;
 
 ThreadPool::ThreadPool(size_t max_threads)
-       : m_ID(m_NextID++), m_MaxThreads(max_threads), m_Stopped(false)
+       : m_ID(m_NextID++), m_MaxThreads(max_threads), m_Stopped(true)
 {
        if (m_MaxThreads != UINT_MAX && m_MaxThreads < sizeof(m_Queues) / sizeof(m_Queues[0]))
                m_MaxThreads = sizeof(m_Queues) / sizeof(m_Queues[0]);
@@ -46,6 +46,11 @@ ThreadPool::~ThreadPool(void)
 
 void ThreadPool::Start(void)
 {
+       if (!m_Stopped)
+               return;
+
+       m_Stopped = false;
+
        for (size_t i = 0; i < sizeof(m_Queues) / sizeof(m_Queues[0]); i++)
                m_Queues[i].SpawnWorker(m_ThreadGroup);
 
@@ -54,6 +59,9 @@ void ThreadPool::Start(void)
 
 void ThreadPool::Stop(void)
 {
+       if (m_Stopped)
+               return;
+
        {
                boost::mutex::scoped_lock lock(m_MgmtMutex);
                m_Stopped = true;
@@ -76,7 +84,7 @@ void ThreadPool::Stop(void)
        for (size_t i = 0; i < sizeof(m_Queues) / sizeof(m_Queues[0]); i++)
                m_Queues[i].Stopped = false;
 
-       m_Stopped = false;
+       m_Stopped = true;
 }
 
 /**