1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ 2 3 #include "base/threadpool.hpp" 4 #include <boost/thread/locks.hpp> 5 6 using namespace icinga; 7 ThreadPool(size_t threads)8ThreadPool::ThreadPool(size_t threads) 9 : m_Threads(threads), m_Pending(0) 10 { 11 Start(); 12 } 13 ~ThreadPool()14ThreadPool::~ThreadPool() 15 { 16 Stop(); 17 } 18 Start()19void ThreadPool::Start() 20 { 21 boost::unique_lock<decltype(m_Mutex)> lock (m_Mutex); 22 23 if (!m_Pool) { 24 m_Pool = decltype(m_Pool)(new boost::asio::thread_pool(m_Threads)); 25 } 26 } 27 Stop()28void ThreadPool::Stop() 29 { 30 boost::unique_lock<decltype(m_Mutex)> lock (m_Mutex); 31 32 if (m_Pool) { 33 m_Pool->join(); 34 m_Pool = nullptr; 35 } 36 } 37