MCPcopy Create free account
hub / github.com/MaskRay/ccls / dequeue

Method dequeue

src/threaded_queue.hh:121–136  ·  view source on GitHub ↗

Get the first element from the queue. Blocks until one is available.

Source from the content-addressed store, hash-verified

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.

Callers 3

preambleMainFunction · 0.80
completionMainFunction · 0.80
diagnosticMainFunction · 0.80

Calls 4

waitMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected