mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 07:34:15 +02:00
Restart thread pool after freezing Configuration
The user (-D) or we could have changed Configuration.Concurrency, so correct the thread pool's thread amount.
This commit is contained in:
parent
32eb1680f7
commit
3fae41ef22
@ -451,6 +451,8 @@ static int Main()
|
|||||||
Configuration::Concurrency = std::thread::hardware_concurrency();
|
Configuration::Concurrency = std::thread::hardware_concurrency();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Application::GetTP().Restart();
|
||||||
|
|
||||||
/* Ensure that all defined constants work in the way we expect them. */
|
/* Ensure that all defined constants work in the way we expect them. */
|
||||||
HandleLegacyDefines();
|
HandleLegacyDefines();
|
||||||
|
|
||||||
|
@ -20,10 +20,15 @@ void ThreadPool::Start()
|
|||||||
boost::unique_lock<decltype(m_Mutex)> lock (m_Mutex);
|
boost::unique_lock<decltype(m_Mutex)> lock (m_Mutex);
|
||||||
|
|
||||||
if (!m_Pool) {
|
if (!m_Pool) {
|
||||||
m_Pool = decltype(m_Pool)(new boost::asio::thread_pool(Configuration::Concurrency * 2u));
|
InitializePool();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ThreadPool::InitializePool()
|
||||||
|
{
|
||||||
|
m_Pool = decltype(m_Pool)(new boost::asio::thread_pool(Configuration::Concurrency * 2u));
|
||||||
|
}
|
||||||
|
|
||||||
void ThreadPool::Stop()
|
void ThreadPool::Stop()
|
||||||
{
|
{
|
||||||
boost::unique_lock<decltype(m_Mutex)> lock (m_Mutex);
|
boost::unique_lock<decltype(m_Mutex)> lock (m_Mutex);
|
||||||
@ -33,3 +38,14 @@ void ThreadPool::Stop()
|
|||||||
m_Pool = nullptr;
|
m_Pool = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ThreadPool::Restart()
|
||||||
|
{
|
||||||
|
boost::unique_lock<decltype(m_Mutex)> lock (m_Mutex);
|
||||||
|
|
||||||
|
if (m_Pool) {
|
||||||
|
m_Pool->join();
|
||||||
|
}
|
||||||
|
|
||||||
|
InitializePool();
|
||||||
|
}
|
||||||
|
@ -42,6 +42,7 @@ public:
|
|||||||
|
|
||||||
void Start();
|
void Start();
|
||||||
void Stop();
|
void Stop();
|
||||||
|
void Restart();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Appends a work item to the work queue. Work items will be processed in FIFO order.
|
* Appends a work item to the work queue. Work items will be processed in FIFO order.
|
||||||
@ -91,6 +92,8 @@ private:
|
|||||||
boost::shared_mutex m_Mutex;
|
boost::shared_mutex m_Mutex;
|
||||||
std::unique_ptr<boost::asio::thread_pool> m_Pool;
|
std::unique_ptr<boost::asio::thread_pool> m_Pool;
|
||||||
Atomic<uint_fast64_t> m_Pending;
|
Atomic<uint_fast64_t> m_Pending;
|
||||||
|
|
||||||
|
void InitializePool();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user