All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TaskQueue.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_UTIL_THREADPOOL_TASKQUEUE_H_
23 #define _BLAZE_UTIL_THREADPOOL_TASKQUEUE_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <algorithm>
31 #include <deque>
32 #include <blaze/util/Policies.h>
35 
36 
37 namespace blaze {
38 
39 namespace threadpool {
40 
41 //=================================================================================================
42 //
43 // CLASS DEFINITION
44 //
45 //=================================================================================================
46 
47 //*************************************************************************************************
54 class TaskQueue
55 {
56  private:
57  //**Type definitions****************************************************************************
58  typedef std::deque<Task*> Tasks;
59  //**********************************************************************************************
60 
61  public:
62  //**Type definitions****************************************************************************
63  typedef Tasks::size_type SizeType;
64  //**********************************************************************************************
65 
66  //**Constructor*********************************************************************************
69  explicit inline TaskQueue();
71  //**********************************************************************************************
72 
73  //**Destructor**********************************************************************************
76  inline ~TaskQueue();
78  //**********************************************************************************************
79 
80  //**Get functions*******************************************************************************
83  inline SizeType maxSize() const;
84  inline SizeType size() const;
85  inline bool isEmpty() const;
87  //**********************************************************************************************
88 
89  //**Element functions***************************************************************************
92  inline void push ( TaskID task );
93  inline TaskID pop ();
94  inline void clear();
96  //**********************************************************************************************
97 
98  //**Utility functions***************************************************************************
101  inline void swap( TaskQueue& tq ) /* throw() */;
103  //**********************************************************************************************
104 
105  private:
106  //**Member variables****************************************************************************
110 
111  //**********************************************************************************************
112 };
113 //*************************************************************************************************
114 
115 
116 
117 
118 //=================================================================================================
119 //
120 // CONSTRUCTOR
121 //
122 //=================================================================================================
123 
124 //*************************************************************************************************
128  : tasks_() // FIFO container for the contained tasks
129 {}
130 //*************************************************************************************************
131 
132 
133 
134 
135 //=================================================================================================
136 //
137 // DESTRUCTOR
138 //
139 //=================================================================================================
140 
141 //*************************************************************************************************
147 {
148  clear();
149 }
150 //*************************************************************************************************
151 
152 
153 
154 
155 //=================================================================================================
156 //
157 // GET FUNCTIONS
158 //
159 //=================================================================================================
160 
161 //*************************************************************************************************
167 {
168  return tasks_.max_size();
169 }
170 //*************************************************************************************************
171 
172 
173 //*************************************************************************************************
181 {
182  return tasks_.size();
183 }
184 //*************************************************************************************************
185 
186 
187 //*************************************************************************************************
192 inline bool TaskQueue::isEmpty() const
193 {
194  return tasks_.empty();
195 }
196 //*************************************************************************************************
197 
198 
199 
200 
201 //=================================================================================================
202 //
203 // ELEMENT FUNCTIONS
204 //
205 //=================================================================================================
206 
207 //*************************************************************************************************
215 inline void TaskQueue::push( TaskID task )
216 {
217  tasks_.push_back( task );
218 }
219 //*************************************************************************************************
220 
221 
222 //*************************************************************************************************
228 {
229  TaskID task( tasks_.front() );
230  tasks_.pop_front();
231  return task;
232 }
233 //*************************************************************************************************
234 
235 
236 //*************************************************************************************************
241 inline void TaskQueue::clear()
242 {
243  std::for_each( tasks_.begin(), tasks_.end(), PtrDelete() );
244  tasks_.clear();
245 }
246 //*************************************************************************************************
247 
248 
249 
250 
251 //=================================================================================================
252 //
253 // UTILITY FUNCTIONS
254 //
255 //=================================================================================================
256 
257 //*************************************************************************************************
264 inline void TaskQueue::swap( TaskQueue& tq ) /* throw() */
265 {
266  tasks_.swap( tq.tasks_ );
267 }
268 //*************************************************************************************************
269 
270 
271 
272 
273 //=================================================================================================
274 //
275 // GLOBAL OPERATORS
276 //
277 //=================================================================================================
278 
279 //*************************************************************************************************
282 inline void swap( TaskQueue& a, TaskQueue& b ) /* throw() */;
284 //*************************************************************************************************
285 
286 
287 //*************************************************************************************************
295 inline void swap( TaskQueue& a, TaskQueue& b ) /* throw() */
296 {
297  a.swap( b );
298 }
299 //*************************************************************************************************
300 
301 } // namespace threadpool
302 
303 } // namespace blaze
304 
305 
306 #endif