Get the first element from the queue without blocking. Returns a null value if the queue is empty.
| 138 | // Get the first element from the queue without blocking. Returns a null |
| 139 | // value if the queue is empty. |
| 140 | std::optional<T> tryPopFront() { |
| 141 | std::lock_guard<std::mutex> lock(mutex_); |
| 142 | auto execute = [&](std::deque<T> *q) { |
| 143 | auto val = std::move(q->front()); |
| 144 | q->pop_front(); |
| 145 | --total_count_; |
| 146 | return val; |
| 147 | }; |
| 148 | if (priority_.size()) |
| 149 | return execute(&priority_); |
| 150 | if (queue_.size()) |
| 151 | return execute(&queue_); |
| 152 | return std::nullopt; |
| 153 | } |
| 154 | |
| 155 | template <typename Fn> void apply(Fn fn) { |
| 156 | std::lock_guard<std::mutex> lock(mutex_); |
no test coverage detected