Skip to content

Commit 30fc821

Browse files
committed
Added ability to add operations to front or back of OperationQueue.
1 parent 08d949e commit 30fc821

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

include/vsg/threading/OperationQueue.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
2020

2121
namespace vsg
2222
{
23+
enum InsertionPosition
24+
{
25+
INSERT_FRONT,
26+
INSERT_BACK
27+
};
2328

2429
/// Template thread safe queue
2530
template<class T>
@@ -38,22 +43,24 @@ namespace vsg
3843
const ActivityStatus* getStatus() const { return _status; }
3944

4045
/// add a single object to the back of the queue
41-
void add(value_type operation)
46+
void add(value_type operation, InsertionPosition insertionPosition = INSERT_BACK)
4247
{
4348
std::scoped_lock lock(_mutex);
44-
_queue.emplace_back(operation);
49+
if (insertionPosition==INSERT_BACK) _queue.emplace_back(operation);
50+
else _queue.emplace_front(operation);
4551
_cv.notify_one();
4652
}
4753

4854
/// add multiple objects to the back of the queue
4955
template<typename Iterator>
50-
void add(Iterator begin, Iterator end)
56+
void add(Iterator begin, Iterator end, InsertionPosition insertionPosition = INSERT_BACK)
5157
{
5258
size_t numAdditions = 0;
5359
std::scoped_lock lock(_mutex);
5460
for (auto itr = begin; itr != end; ++itr)
5561
{
56-
_queue.emplace_back(*itr);
62+
if (insertionPosition==INSERT_BACK) _queue.emplace_back(*itr);
63+
else _queue.emplace_front(*itr);
5764
++numAdditions;
5865
}
5966

include/vsg/threading/OperationThreads.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ namespace vsg
2929
OperationThreads(const OperationThreads&) = delete;
3030
OperationThreads& operator=(const OperationThreads& rhs) = delete;
3131

32-
void add(ref_ptr<Operation> operation)
32+
void add(ref_ptr<Operation> operation, InsertionPosition insertionPosition = INSERT_BACK)
3333
{
34-
queue->add(operation);
34+
queue->add(operation, insertionPosition);
3535
}
3636

3737
template<typename Iterator>
38-
void add(Iterator begin, Iterator end)
38+
void add(Iterator begin, Iterator end, InsertionPosition insertionPosition = INSERT_BACK)
3939
{
40-
queue->add(begin, end);
40+
queue->add(begin, end, insertionPosition);
4141
}
4242

4343
/// use this thread to run operations till the queue is empty as well

0 commit comments

Comments
 (0)