17#ifndef __ROGUE_QUEUE_H__
18#define __ROGUE_QUEUE_H__
23#include <condition_variable>
41 mutable std::mutex mtx_;
42 std::condition_variable pushCond_;
43 std::condition_variable popCond_;
62 std::unique_lock<std::mutex> lock(mtx_);
64 pushCond_.notify_all();
65 popCond_.notify_all();
93 std::unique_lock<std::mutex> lock(mtx_);
95 while (run_ && max_ > 0 && queue_.size() >= max_) pushCond_.wait(lock);
97 if (run_) queue_.push(data);
98 busy_ = (thold_ > 0 && queue_.size() >= thold_);
99 popCond_.notify_all();
107 return queue_.empty();
115 std::unique_lock<std::mutex> lock(mtx_);
116 return queue_.size();
131 std::unique_lock<std::mutex> lock(mtx_);
132 while (!queue_.empty()) queue_.pop();
134 pushCond_.notify_all();
143 std::unique_lock<std::mutex> lock(mtx_);
144 while (run_ && queue_.empty()) popCond_.wait(lock);
146 ret = queue_.front();
149 busy_ = (thold_ > 0 && queue_.size() >= thold_);
150 pushCond_.notify_all();
Thread-safe bounded queue with optional busy threshold.
bool empty()
Returns whether queue is currently empty.
Queue()
Constructs an empty running queue.
void reset()
Clears all queued entries and resets busy state.
void push(T const &data)
Pushes one entry, blocking when queue is full.
bool busy()
Returns busy state based on configured threshold.
void setMax(uint32_t max)
Sets maximum queue depth before push() blocks.
void setThold(uint32_t thold)
Sets busy-threshold depth used by busy().
void stop()
Stops queue operation and wakes blocked producers/consumers.
T pop()
Pops one entry, blocking until data is available or stopped.
uint32_t size()
Returns current queue depth.