From: Gunnar Beutner Date: Mon, 18 Jun 2012 04:29:48 +0000 (+0200) Subject: Use a FIFO queue for the tasks in the thread pool. X-Git-Tag: v0.0.1~403 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1d8331ecd8c3e54f80ea5f912b5da5800bfe6ef8;p=icinga2 Use a FIFO queue for the tasks in the thread pool. --- diff --git a/base/i2-base.h b/base/i2-base.h index 283c57523..c55a2db28 100644 --- a/base/i2-base.h +++ b/base/i2-base.h @@ -91,7 +91,7 @@ #include #include #include -#include +#include using std::string; using std::vector; @@ -100,7 +100,7 @@ using std::list; using std::set; using std::multimap; using std::pair; -using std::stack; +using std::deque; using std::stringstream; diff --git a/base/threadpool.cpp b/base/threadpool.cpp index ce18f7c52..663014e83 100644 --- a/base/threadpool.cpp +++ b/base/threadpool.cpp @@ -25,7 +25,7 @@ ThreadPool::~ThreadPool(void) void ThreadPool::EnqueueTask(Task task) { unique_lock lock(m_Lock); - m_Tasks.push(task); + m_Tasks.push_back(task); m_CV.notify_one(); } @@ -44,8 +44,8 @@ void ThreadPool::WorkerThreadProc(void) return; } - task = m_Tasks.top(); - m_Tasks.pop(); + task = m_Tasks.front(); + m_Tasks.pop_front(); } task(); diff --git a/base/threadpool.h b/base/threadpool.h index 2eded6ef9..18c9a84a8 100644 --- a/base/threadpool.h +++ b/base/threadpool.h @@ -23,7 +23,7 @@ private: mutex m_Lock; condition_variable m_CV; - stack m_Tasks; + deque m_Tasks; thread_group m_Threads; bool m_Alive; diff --git a/dyn/i2-dyn.h b/dyn/i2-dyn.h index da44e7e14..3db7e0e93 100644 --- a/dyn/i2-dyn.h +++ b/dyn/i2-dyn.h @@ -29,8 +29,10 @@ #include +#include #include +using std::stack; using std::istream; using std::ostream; using std::cin;