[icinga-checkins] icinga.org: icinga2/master: Fix ThreadPool exception on shutdown.

git at icinga.org git at icinga.org
Mon May 13 09:58:40 CEST 2013


Module: icinga2
Branch: master
Commit: f4d04f8172830c6814bebc859160dc3deb8c97f4
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=f4d04f8172830c6814bebc859160dc3deb8c97f4

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Mon May 13 09:58:24 2013 +0200

Fix ThreadPool exception on shutdown.

Fixes #3891

---

 lib/base/threadpool.cpp |    7 +++++--
 lib/base/threadpool.h   |    2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/base/threadpool.cpp b/lib/base/threadpool.cpp
index 9bad240..2f11749 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 7bb16aa..b6eb76f 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





More information about the icinga-checkins mailing list