From: Gunnar Beutner Date: Mon, 13 May 2013 07:58:24 +0000 (+0200) Subject: Fix ThreadPool exception on shutdown. X-Git-Tag: v0.0.2~104 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f4d04f8172830c6814bebc859160dc3deb8c97f4;p=icinga2 Fix ThreadPool exception on shutdown. Fixes #3891 --- diff --git a/lib/base/threadpool.cpp b/lib/base/threadpool.cpp index 9bad24050..2f11749ea 100644 --- a/lib/base/threadpool.cpp +++ b/lib/base/threadpool.cpp @@ -197,13 +197,14 @@ void ThreadPool::QueueThreadProc(int tid) * Appends a work item to the work queue. Work items will be processed in FIFO order. * * @param callback The callback function for the work item. + * @returns true if the item was queued, false otherwise. */ -void ThreadPool::Post(const ThreadPool::WorkFunction& callback) +bool ThreadPool::Post(const ThreadPool::WorkFunction& callback) { boost::mutex::scoped_lock lock(m_Mutex); if (m_Stopped) - BOOST_THROW_EXCEPTION(std::runtime_error("ThreadPool has been stopped.")); + return false; WorkItem wi; wi.Callback = callback; @@ -211,6 +212,8 @@ void ThreadPool::Post(const ThreadPool::WorkFunction& callback) m_WorkItems.push_back(wi); m_WorkCV.notify_one(); + + return true; } void ThreadPool::ManagerThreadProc(void) diff --git a/lib/base/threadpool.h b/lib/base/threadpool.h index 7bb16aa2c..b6eb76f0f 100644 --- a/lib/base/threadpool.h +++ b/lib/base/threadpool.h @@ -46,7 +46,7 @@ public: void Stop(void); void Join(void); - void Post(const WorkFunction& callback); + bool Post(const WorkFunction& callback); private: enum ThreadState