25 template <
class T,
typename StorageType = std::deque<T> >
51 void add(
const T& item)
55 _queue.push_back(item);
61 template<
class Iterator>
62 void readd(Iterator begin, Iterator end)
64 std::lock_guard<std::mutex>
lock(_lock);
65 _queue.insert(_queue.begin(), begin, end);
71 std::lock_guard<std::mutex>
lock(_lock);
76 result = _queue.front();
82 template<
class Checker>
85 std::lock_guard<std::mutex>
lock(_lock);
90 result = _queue.front();
91 if (!check.Process(result))
99 T&
peek(
bool autoUnlock =
false)
103 T& result = _queue.front();
114 std::lock_guard<std::mutex>
lock(_lock);
122 std::lock_guard<std::mutex>
lock(_lock);
135 this->_lock.unlock();
141 std::lock_guard<std::mutex>
lock(_lock);
148 std::lock_guard<std::mutex>
lock(_lock);
149 return _queue.empty();
void unlock()
Unlocks the queue.
Definition: LockedQueue.h:133
void pop_front()
! Calls pop_front of the queue
Definition: LockedQueue.h:139
bool cancelled()
Checks if the queue is cancelled.
Definition: LockedQueue.h:120
#define false
Definition: CascPort.h:18
T & peek(bool autoUnlock=false)
Peeks at the top of the queue. Check if the queue is empty before calling! Remember to unlock after u...
Definition: LockedQueue.h:99
virtual ~LockedQueue()
Destroy a LockedQueue.
Definition: LockedQueue.h:46
StorageType _queue
Storage backing the queue.
Definition: LockedQueue.h:32
bool empty()
! Checks if we're empty or not with locks held
Definition: LockedQueue.h:146
bool next(T &result)
Gets the next result in the queue, if any.
Definition: LockedQueue.h:69
void cancel()
Cancels the queue.
Definition: LockedQueue.h:112
bool next(T &result, Checker &check)
Definition: LockedQueue.h:83
void add(const T &item)
Adds an item to the queue.
Definition: LockedQueue.h:51
void readd(Iterator begin, Iterator end)
Adds items back to front of the queue.
Definition: LockedQueue.h:62
void lock()
Locks the queue for access.
Definition: LockedQueue.h:127
T check(T value)
Definition: format.h:305
volatile bool _canceled
Cancellation flag.
Definition: LockedQueue.h:35
Definition: LockedQueue.h:26
LockedQueue()
Create a LockedQueue.
Definition: LockedQueue.h:40
std::mutex _lock
Lock access to the queue.
Definition: LockedQueue.h:29