| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

scheduling_policies.hpp
Go to the documentation of this file.
1
22 #ifndef THREADPOOL_SCHEDULING_POLICIES_HPP_INCLUDED
23 #define THREADPOOL_SCHEDULING_POLICIES_HPP_INCLUDED
24
25
26 #include <queue>
27 #include <deque>
28
29 #include "task_adaptors.hpp"
30
31 namespace boost { namespace threadpool
32 {
33
44 template <typename Task = task_func>
45 class fifo_scheduler
46 {
47 public:
48 typedef Task task_type;
49
50 protected:
51 std::deque<task_type> m_container;
52
53
54 public:
59 bool push(task_type const & task)
60 {
61 m_container.push_back(task);
62 return true;
63 }
64
67 void pop()
68 {
69 m_container.pop_front();
70 }
71
75 task_type const & top() const
76 {
77 return m_container.front();
78 }
79
84 size_t size() const
85 {
86 return m_container.size();
87 }
88
93 bool empty() const
94 {
95 return m_container.empty();
96 }
97
100 void clear()
101 {
102 m_container.clear();
103 }
104 };
105
106
107
117 template <typename Task = task_func>
118 class lifo_scheduler
119 {
120 public:
121 typedef Task task_type;
122
123 protected:
124 std::deque<task_type> m_container;
125
126 public:
131 bool push(task_type const & task)
132 {
133 m_container.push_front(task);
134 return true;
135 }
136
139 void pop()
140 {
141 m_container.pop_front();
142 }
143
147 task_type const & top() const
148 {
149 return m_container.front();
150 }
151
156 size_t size() const
157 {
158 return m_container.size();
159 }
160
165 bool empty() const
166 {
167 return m_container.empty();
168 }
169
172 void clear()
173 {
174 m_container.clear();
175 }
176
177 };
178
179
180
192 template <typename Task = prio_task_func>
193 class prio_scheduler
194 {
195 public:
196 typedef Task task_type;
197
198 protected:
199 std::priority_queue<task_type> m_container;
200
201
202 public:
207 bool push(task_type const & task)
208 {
209 m_container.push(task);
210 return true;
211 }
212
215 void pop()
216 {
217 m_container.pop();
218 }
219
223 task_type const & top() const
224 {
225 return m_container.top();
226 }
227
232 size_t size() const
233 {
234 return m_container.size();
235 }
236
241 bool empty() const
242 {
243 return m_container.empty();
244 }
245
248 void clear()
249 {
250 while(!m_container.empty())
251 {
252 m_container.pop();
253 }
254 }
255 };
256
257
258 } } // namespace boost::threadpool
259
260
261 #endif // THREADPOOL_SCHEDULING_POLICIES_HPP_INCLUDED
262
std::deque::empty
T empty(T...args)
boost
The namespace threadpool contains a thread pool and related utility classes.
Definition: iter_pos.hpp:13
boost::threadpool::lifo_scheduler::empty
bool empty() const
Checks if the scheduler is empty.
Definition: scheduling_policies.hpp:165
std::deque::front
T front(T...args)
task_adaptors.hpp
Task adaptors.
boost::threadpool::prio_scheduler
SchedulingPolicy which implements prioritized ordering.
Definition: scheduling_policies.hpp:193
boost::threadpool::lifo_scheduler::push
bool push(task_type const &task)
Adds a new task to the scheduler.
Definition: scheduling_policies.hpp:131
boost::threadpool::prio_scheduler::task_type
Task task_type
Indicates the scheduler&#39;s task type.
Definition: scheduling_policies.hpp:196
std::priority_queue::pop
T pop(T...args)
std::priority_queue::top
T top(T...args)
boost::threadpool::lifo_scheduler::pop
void pop()
Removes the task which should be executed next.
Definition: scheduling_policies.hpp:139
boost::threadpool::prio_scheduler::m_container
std::priority_queue< task_type > m_container
Internal task container.
Definition: scheduling_policies.hpp:199
boost::threadpool::fifo_scheduler::pop
void pop()
Removes the task which should be executed next.
Definition: scheduling_policies.hpp:67
std::priority_queue::push
T push(T...args)
boost::threadpool::lifo_scheduler::m_container
std::deque< task_type > m_container
Internal task container.
Definition: scheduling_policies.hpp:124
std::deque::push_back
T push_back(T...args)
boost::threadpool::prio_scheduler::clear
void clear()
Removes all tasks from the scheduler.
Definition: scheduling_policies.hpp:248
boost::threadpool::fifo_scheduler::top
task_type const & top() const
Gets the task which should be executed next.
Definition: scheduling_policies.hpp:75
std::priority_queue< task_type >
std::deque< task_type >
boost::threadpool::lifo_scheduler::size
size_t size() const
Gets the current number of tasks in the scheduler.
Definition: scheduling_policies.hpp:156
boost::threadpool::fifo_scheduler::push
bool push(task_type const &task)
Adds a new task to the scheduler.
Definition: scheduling_policies.hpp:59
std::deque::clear
T clear(T...args)
boost::threadpool::prio_scheduler::size
size_t size() const
Gets the current number of tasks in the scheduler.
Definition: scheduling_policies.hpp:232
boost::threadpool::fifo_scheduler::m_container
std::deque< task_type > m_container
Internal task container.
Definition: scheduling_policies.hpp:51
boost::threadpool::prio_scheduler::pop
void pop()
Removes the task which should be executed next.
Definition: scheduling_policies.hpp:215
std::deque::size
T size(T...args)
boost::threadpool::fifo_scheduler::task_type
Task task_type
Indicates the scheduler&#39;s task type.
Definition: scheduling_policies.hpp:48
boost::threadpool::lifo_scheduler::top
task_type const & top() const
Gets the task which should be executed next.
Definition: scheduling_policies.hpp:147
std::deque::push_front
T push_front(T...args)
boost::threadpool::lifo_scheduler::clear
void clear()
Removes all tasks from the scheduler.
Definition: scheduling_policies.hpp:172
boost::threadpool::fifo_scheduler::empty
bool empty() const
Checks if the scheduler is empty.
Definition: scheduling_policies.hpp:93
boost::threadpool::fifo_scheduler::clear
void clear()
Removes all tasks from the scheduler.
Definition: scheduling_policies.hpp:100
std::deque::pop_front
T pop_front(T...args)
boost::threadpool::lifo_scheduler::task_type
Task task_type
Indicates the scheduler&#39;s task type.
Definition: scheduling_policies.hpp:121
boost::threadpool::fifo_scheduler
SchedulingPolicy which implements FIFO ordering.
Definition: scheduling_policies.hpp:45
boost::threadpool::fifo_scheduler::size
size_t size() const
Gets the current number of tasks in the scheduler.
Definition: scheduling_policies.hpp:84
boost::threadpool::prio_scheduler::push
bool push(task_type const &task)
Adds a new task to the scheduler.
Definition: scheduling_policies.hpp:207
boost::threadpool::prio_scheduler::top
task_type const & top() const
Gets the task which should be executed next.
Definition: scheduling_policies.hpp:223
boost::threadpool::prio_scheduler::empty
bool empty() const
Checks if the scheduler is empty.
Definition: scheduling_policies.hpp:241
boost::threadpool::lifo_scheduler
SchedulingPolicy which implements LIFO ordering.
Definition: scheduling_policies.hpp:118