]> granicus.if.org Git - icinga2/commitdiff
Use a FIFO queue for the tasks in the thread pool.
authorGunnar Beutner <gunnar@beutner.name>
Mon, 18 Jun 2012 04:29:48 +0000 (06:29 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 18 Jun 2012 04:31:40 +0000 (06:31 +0200)
base/i2-base.h
base/threadpool.cpp
base/threadpool.h
dyn/i2-dyn.h

index 283c57523ab57de356c71add3a3b446b29fdce7e..c55a2db2889e61a99aca79cd412c8456d2d9cbca 100644 (file)
@@ -91,7 +91,7 @@
 #include <map>
 #include <list>
 #include <algorithm>
-#include <stack>
+#include <deque>
 
 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;
 
index ce18f7c5232ebb6451b233220e16d560ed8769bf..663014e83e1470e6217bc446b4051e1029a3bb34 100644 (file)
@@ -25,7 +25,7 @@ ThreadPool::~ThreadPool(void)
 void ThreadPool::EnqueueTask(Task task)
 {
        unique_lock<mutex> 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();
index 2eded6ef9c6e20f077ccbf078d14cf902b48979f..18c9a84a8a9b0c7a2c1892c21e62c93412a69cfb 100644 (file)
@@ -23,7 +23,7 @@ private:
        mutex m_Lock;
        condition_variable m_CV;
 
-       stack<Task> m_Tasks;
+       deque<Task> m_Tasks;
 
        thread_group m_Threads;
        bool m_Alive;
index da44e7e148d56361dc7a8771a0988bbaebe8afea..3db7e0e93602476e794711ceb0ca2b58e404d0a1 100644 (file)
 
 #include <i2-base.h>
 
+#include <stack>
 #include <fstream>
 
+using std::stack;
 using std::istream;
 using std::ostream;
 using std::cin;