mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-16 21:58:08 +00:00
Add DequeuePlusAction
This commit is contained in:
parent
c37396a36d
commit
7b052d887d
@ -94,7 +94,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the first element from the queue. Blocks until one is available.
|
// 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_);
|
std::unique_lock<std::mutex> lock(mutex_);
|
||||||
waiter_->cv.wait(lock, [&]() {
|
waiter_->cv.wait(lock, [&]() {
|
||||||
return !priority_.empty() || !queue_.empty();
|
return !priority_.empty() || !queue_.empty();
|
||||||
@ -108,9 +110,17 @@ public:
|
|||||||
|
|
||||||
auto val = std::move(queue_.front());
|
auto val = std::move(queue_.front());
|
||||||
queue_.pop();
|
queue_.pop();
|
||||||
|
|
||||||
|
action();
|
||||||
|
|
||||||
return std::move(val);
|
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
|
// Get the first element from the queue without blocking. Returns a null
|
||||||
// value if the queue is empty.
|
// value if the queue is empty.
|
||||||
optional<T> TryDequeue() {
|
optional<T> TryDequeue() {
|
||||||
|
Loading…
Reference in New Issue
Block a user