mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 15:45:08 +00:00
Add DequeuePlusAction
This commit is contained in:
parent
c37396a36d
commit
7b052d887d
@ -94,12 +94,14 @@ public:
|
||||
}
|
||||
|
||||
// Get the first element from the queue. Blocks until one is available.
|
||||
T Dequeue() {
|
||||
// Executes |action| with an acquired |mutex_|.
|
||||
template<typename TAction>
|
||||
T DequeuePlusAction(TAction& action) {
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
waiter_->cv.wait(lock, [&]() {
|
||||
return !priority_.empty() || !queue_.empty();
|
||||
});
|
||||
|
||||
|
||||
if (!priority_.empty()) {
|
||||
auto val = std::move(priority_.front());
|
||||
priority_.pop();
|
||||
@ -108,9 +110,17 @@ public:
|
||||
|
||||
auto val = std::move(queue_.front());
|
||||
queue_.pop();
|
||||
|
||||
action();
|
||||
|
||||
return std::move(val);
|
||||
}
|
||||
|
||||
// Get the first element from the queue. Blocks until one is available.
|
||||
T Dequeue() {
|
||||
return DequeuePlusAction([]() {});
|
||||
}
|
||||
|
||||
// Get the first element from the queue without blocking. Returns a null
|
||||
// value if the queue is empty.
|
||||
optional<T> TryDequeue() {
|
||||
|
Loading…
Reference in New Issue
Block a user