All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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>
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>
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>
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 
The namespace threadpool contains a thread pool and related utility classes.
Definition: iter_pos.hpp:13
bool empty() const
Checks if the scheduler is empty.
Task adaptors.
SchedulingPolicy which implements prioritized ordering.
bool push(task_type const &task)
Adds a new task to the scheduler.
Task task_type
Indicates the scheduler's task type.
void pop()
Removes the task which should be executed next.
std::priority_queue< task_type > m_container
Internal task container.
void pop()
Removes the task which should be executed next.
std::deque< task_type > m_container
Internal task container.
void clear()
Removes all tasks from the scheduler.
task_type const & top() const
Gets the task which should be executed next.
size_t size() const
Gets the current number of tasks in the scheduler.
bool push(task_type const &task)
Adds a new task to the scheduler.
size_t size() const
Gets the current number of tasks in the scheduler.
std::deque< task_type > m_container
Internal task container.
void pop()
Removes the task which should be executed next.
Task task_type
Indicates the scheduler's task type.
task_type const & top() const
Gets the task which should be executed next.
void clear()
Removes all tasks from the scheduler.
bool empty() const
Checks if the scheduler is empty.
void clear()
Removes all tasks from the scheduler.
Task task_type
Indicates the scheduler's task type.
SchedulingPolicy which implements FIFO ordering.
size_t size() const
Gets the current number of tasks in the scheduler.
bool push(task_type const &task)
Adds a new task to the scheduler.
task_type const & top() const
Gets the task which should be executed next.
bool empty() const
Checks if the scheduler is empty.
SchedulingPolicy which implements LIFO ordering.