Get the first element from the queue. Blocks until one is available.
| 119 | |
| 120 | // Get the first element from the queue. Blocks until one is available. |
| 121 | T dequeue(int keep_only_latest = 0) { |
| 122 | std::unique_lock<std::mutex> lock(mutex_); |
| 123 | waiter_->cv.wait(lock, [&]() { return !priority_.empty() || !queue_.empty(); }); |
| 124 | |
| 125 | auto execute = [&](std::deque<T> *q) { |
| 126 | if (keep_only_latest > 0 && q->size() > keep_only_latest) |
| 127 | q->erase(q->begin(), q->end() - keep_only_latest); |
| 128 | auto val = std::move(q->front()); |
| 129 | q->pop_front(); |
| 130 | --total_count_; |
| 131 | return val; |
| 132 | }; |
| 133 | if (!priority_.empty()) |
| 134 | return execute(&priority_); |
| 135 | return execute(&queue_); |
| 136 | } |
| 137 | |
| 138 | // Get the first element from the queue without blocking. Returns a null |
| 139 | // value if the queue is empty. |
no test coverage detected