23 #ifndef BM_BM_SIM_QUEUE_H_
24 #define BM_BM_SIM_QUEUE_H_
26 #include <condition_variable>
66 : capacity(capacity), wb(wb), rb(rb) {}
70 std::unique_lock<std::mutex> lock(q_mutex);
71 while (!is_not_full()) {
73 q_not_full.wait(lock);
75 queue.push_front(item);
77 q_not_empty.notify_one();
82 std::unique_lock<std::mutex> lock(q_mutex);
83 while (!is_not_full()) {
85 q_not_full.wait(lock);
87 queue.push_front(std::move(item));
89 q_not_empty.notify_one();
94 std::unique_lock<std::mutex> lock(q_mutex);
95 while (!is_not_empty())
96 q_not_empty.wait(lock);
97 *pItem = std::move(queue.back());
100 q_not_full.notify_one();
105 std::unique_lock<std::mutex> lock(q_mutex);
112 std::unique_lock<std::mutex> lock(q_mutex);
127 bool is_not_empty()
const {
return queue.size() > 0; }
128 bool is_not_full()
const {
return queue.size() < capacity; }
135 mutable std::mutex q_mutex;
136 mutable std::condition_variable q_not_empty;
137 mutable std::condition_variable q_not_full;
142 #endif // BM_BM_SIM_QUEUE_H_