Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
blaze
util
threadpool
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/PtrDelete.h
>
33
#include <
blaze/util/threadpool/Task.h
>
34
#include <
blaze/util/threadpool/TaskID.h
>
35
#include <
blaze/util/UniquePtr.h
>
36
37
38
namespace
blaze {
39
40
namespace
threadpool {
41
42
//=================================================================================================
43
//
44
// CLASS DEFINITION
45
//
46
//=================================================================================================
47
48
//*************************************************************************************************
55
class
TaskQueue
56
{
57
private
:
58
//**Type definitions****************************************************************************
59
typedef
std::deque<Task*>
Tasks
;
60
//**********************************************************************************************
61
62
public
:
63
//**Type definitions****************************************************************************
64
typedef
Tasks::size_type
SizeType
;
65
//**********************************************************************************************
66
67
//**Constructor*********************************************************************************
70
explicit
inline
TaskQueue
();
72
//**********************************************************************************************
73
74
//**Destructor**********************************************************************************
77
inline
~TaskQueue
();
79
//**********************************************************************************************
80
81
//**Get functions*******************************************************************************
84
inline
SizeType
maxSize
()
const
;
85
inline
SizeType
size
()
const
;
86
inline
bool
isEmpty
()
const
;
88
//**********************************************************************************************
89
90
//**Element functions***************************************************************************
93
inline
void
push
(
TaskID
task );
94
inline
TaskID
pop
();
95
inline
void
clear
();
97
//**********************************************************************************************
98
99
//**Utility functions***************************************************************************
102
inline
void
swap
(
TaskQueue
& tq )
/* throw() */
;
104
//**********************************************************************************************
105
106
private
:
107
//**Member variables****************************************************************************
110
Tasks
tasks_
;
111
112
//**********************************************************************************************
113
};
114
//*************************************************************************************************
115
116
117
118
119
//=================================================================================================
120
//
121
// CONSTRUCTOR
122
//
123
//=================================================================================================
124
125
//*************************************************************************************************
128
inline
TaskQueue::TaskQueue
()
129
: tasks_()
// FIFO container for the contained tasks
130
{}
131
//*************************************************************************************************
132
133
134
135
136
//=================================================================================================
137
//
138
// DESTRUCTOR
139
//
140
//=================================================================================================
141
142
//*************************************************************************************************
147
TaskQueue::~TaskQueue
()
148
{
149
clear
();
150
}
151
//*************************************************************************************************
152
153
154
155
156
//=================================================================================================
157
//
158
// GET FUNCTIONS
159
//
160
//=================================================================================================
161
162
//*************************************************************************************************
167
inline
TaskQueue::SizeType
TaskQueue::maxSize
()
const
168
{
169
return
tasks_
.max_size();
170
}
171
//*************************************************************************************************
172
173
174
//*************************************************************************************************
181
inline
TaskQueue::SizeType
TaskQueue::size
()
const
182
{
183
return
tasks_
.size();
184
}
185
//*************************************************************************************************
186
187
188
//*************************************************************************************************
193
inline
bool
TaskQueue::isEmpty
()
const
194
{
195
return
tasks_
.empty();
196
}
197
//*************************************************************************************************
198
199
200
201
202
//=================================================================================================
203
//
204
// ELEMENT FUNCTIONS
205
//
206
//=================================================================================================
207
208
//*************************************************************************************************
216
inline
void
TaskQueue::push
(
TaskID
task )
217
{
218
UniquePtr<Task>
ptr( task );
219
tasks_
.push_back( task );
220
ptr.
release
();
221
}
222
//*************************************************************************************************
223
224
225
//*************************************************************************************************
230
inline
TaskID
TaskQueue::pop
()
231
{
232
TaskID
task(
tasks_
.front() );
233
tasks_
.pop_front();
234
return
task;
235
}
236
//*************************************************************************************************
237
238
239
//*************************************************************************************************
244
inline
void
TaskQueue::clear
()
245
{
246
std::for_each(
tasks_
.begin(),
tasks_
.end(),
PtrDelete
() );
247
tasks_
.clear();
248
}
249
//*************************************************************************************************
250
251
252
253
254
//=================================================================================================
255
//
256
// UTILITY FUNCTIONS
257
//
258
//=================================================================================================
259
260
//*************************************************************************************************
267
inline
void
TaskQueue::swap
(
TaskQueue
& tq )
/* throw() */
268
{
269
tasks_
.swap( tq.
tasks_
);
270
}
271
//*************************************************************************************************
272
273
274
275
276
//=================================================================================================
277
//
278
// GLOBAL OPERATORS
279
//
280
//=================================================================================================
281
282
//*************************************************************************************************
285
inline
void
swap
(
TaskQueue
& a,
TaskQueue
& b )
/* throw() */
;
287
//*************************************************************************************************
288
289
290
//*************************************************************************************************
298
inline
void
swap
(
TaskQueue
& a,
TaskQueue
& b )
/* throw() */
299
{
300
a.
swap
( b );
301
}
302
//*************************************************************************************************
303
304
}
// namespace threadpool
305
306
}
// namespace blaze
307
308
309
#endif
Generated on Sun Jul 28 2013 17:06:08 by
1.8.3.1