15 #include <vsg/io/Logger.h>
16 #include <vsg/threading/ActivityStatus.h>
17 #include <vsg/threading/Latch.h>
30 using container_type = std::list<value_type>;
41 void add(value_type operation)
43 std::scoped_lock lock(_mutex);
44 _queue.emplace_back(operation);
49 template<
typename Iterator>
50 void add(Iterator begin, Iterator end)
52 size_t numAdditions = 0;
53 std::scoped_lock lock(_mutex);
54 for (
auto itr = begin; itr != end; ++itr)
56 _queue.emplace_back(*itr);
60 if (numAdditions == 1)
62 else if (numAdditions > 1)
69 std::unique_lock lock(_mutex);
70 return _queue.empty();
76 std::unique_lock lock(_mutex);
78 container_type objects;
87 std::unique_lock lock(_mutex);
89 if (_queue.empty())
return {};
91 auto operation = _queue.front();
93 _queue.erase(_queue.begin());
101 std::chrono::duration waitDuration = std::chrono::milliseconds(100);
103 std::unique_lock lock(_mutex);
106 while (_queue.empty() && _status->active())
109 _cv.wait_for(lock, waitDuration);
113 if (_status->cancel())
119 auto operation = _queue.front();
120 _queue.erase(_queue.begin());
125 mutable std::mutex _mutex;
126 std::condition_variable _cv;
127 container_type _queue;
137 virtual void run() = 0;
143 VSG_type_name(vsg::OperationQueue)
ActivityStatus provides atomic management of whether threads watching this ActivityStatus object shou...
Definition: ActivityStatus.h:22
Template thread safe queue.
Definition: OperationQueue.h:27
value_type take()
take the head from the queue of objects, return null pointer if none are available
Definition: OperationQueue.h:85
container_type take_all()
take all available objects from the queue
Definition: OperationQueue.h:74
value_type take_when_available()
take the head of the queue, waiting till one is made available if initially empty
Definition: OperationQueue.h:99
void add(Iterator begin, Iterator end)
add multiple objects to the back of the queue
Definition: OperationQueue.h:50
bool empty() const
return true if the queue is empty.
Definition: OperationQueue.h:67
void add(value_type operation)
add a single object to the back of the queue
Definition: OperationQueue.h:41
Operation base class.
Definition: OperationQueue.h:136