17#ifndef __ROGUE_QUEUE_H__
18#define __ROGUE_QUEUE_H__
24#include <condition_variable>
42 mutable std::mutex mtx_;
43 std::condition_variable pushCond_;
44 std::condition_variable popCond_;
47 std::atomic<bool> busy_{
false};
58 std::unique_lock<std::mutex> lock(mtx_);
60 pushCond_.notify_all();
61 popCond_.notify_all();
89 std::unique_lock<std::mutex> lock(mtx_);
91 while (run_ && max_ > 0 && queue_.size() >= max_) pushCond_.wait(lock);
93 if (run_) queue_.push(data);
94 busy_ = (thold_ > 0 && queue_.size() >= thold_);
95 popCond_.notify_all();
103 return queue_.empty();
111 std::unique_lock<std::mutex> lock(mtx_);
112 return queue_.size();
127 std::unique_lock<std::mutex> lock(mtx_);
128 while (!queue_.empty()) queue_.pop();
130 pushCond_.notify_all();
139 std::unique_lock<std::mutex> lock(mtx_);
140 while (run_ && queue_.empty()) popCond_.wait(lock);
142 ret = queue_.front();
145 busy_ = (thold_ > 0 && queue_.size() >= thold_);
146 pushCond_.notify_all();
Thread-safe bounded queue with optional busy threshold.
bool empty()
Returns whether queue is currently empty.
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.
Queue()=default
Constructs an empty running queue.
uint32_t size()
Returns current queue depth.