29 #ifndef BUFFERQUEUE_HPP
30 #define BUFFERQUEUE_HPP
34 #include <condition_variable>
88 bool push(
const T& item,
unsigned int timeout = 1 )
90 std::unique_lock<std::mutex> lock(
mutex);
93 std::chrono::milliseconds(timeout),
96 if (stillFull)
return false;
113 bool pop(T& item,
unsigned int timeout = 1 )
115 std::unique_lock<std::mutex> lock(
mutex);
118 std::chrono::milliseconds(timeout),
119 [
this]() {
return !
queue.empty(); });
121 if (stillEmpty)
return false;
123 item =
queue.front();
135 std::lock_guard<std::mutex> lock(
mutex);
137 while(!
queue.empty())
155 #endif // BUFFERQUEUE_HPP
bool push(const T &item, unsigned int timeout=1)
Attemps to push a new value into the queue.
std::condition_variable condNonEmpty
std::condition_variable condNonFull
ThreadSafeQueue & operator=(const ThreadSafeQueue &)
void clear()
Removes all elements from the queue.
const unsigned int TIMEOUT_INFINITE
A maximum timeout.
ThreadSafeQueue(std::size_t maxSize)
Creation of a thread-safe queue with a specified capacity.
bool pop(T &item, unsigned int timeout=1)
Attemps to pop the oldest value from the queue.