]> granicus.if.org Git - icinga2/commitdiff
Fix ThreadPool exception on shutdown.
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 13 May 2013 07:58:24 +0000 (09:58 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 13 May 2013 07:58:24 +0000 (09:58 +0200)
Fixes #3891

lib/base/threadpool.cpp
lib/base/threadpool.h

index 9bad2405036864df4030006d5fd81f7a923e54a4..2f11749ea59c1257c0dd7c8488c82c04d77dc43b 100644 (file)
@@ -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)
index 7bb16aa2c37bec237d6265ebbaefd77cfb8a6c6f..b6eb76f0fb9e81d9a3c7360afed62cf8d41ef841 100644 (file)
@@ -46,7 +46,7 @@ public:
        void Stop(void);
        void Join(void);
 
-       void Post(const WorkFunction& callback);
+       bool Post(const WorkFunction& callback);
 
 private:
        enum ThreadState