mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-31 09:50:26 +00:00
Add ThreadedQueue::EnqueueAll to reduce lock contention.
This commit is contained in:
parent
28ddc9f346
commit
58fbd04142
@ -998,18 +998,18 @@ bool IndexMain_DoParse(
|
||||
entry.args = request->args;
|
||||
std::vector<Index_DoIdMap> responses = ParseFile(config, index, file_consumer_shared, timestamp_manager, entry);
|
||||
|
||||
// TODO/FIXME: bulk enqueue so we don't lock so many times
|
||||
for (Index_DoIdMap& response : responses)
|
||||
queue->do_id_map.Enqueue(std::move(response));
|
||||
if (responses.empty())
|
||||
return false;
|
||||
|
||||
return !responses.empty();
|
||||
// EnqueueAll will clear |responses|.
|
||||
queue->do_id_map.EnqueueAll(std::move(responses));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IndexMain_DoCreateIndexUpdate(
|
||||
Config* config,
|
||||
QueueManager* queue,
|
||||
TimestampManager* timestamp_manager) {
|
||||
// TODO: Index_OnIdMapped dtor is failing because it seems that its contents have already been destroyed.
|
||||
optional<Index_OnIdMapped> response = queue->on_id_mapped.TryDequeue();
|
||||
if (!response)
|
||||
return false;
|
||||
|
@ -71,6 +71,15 @@ public:
|
||||
waiter_->cv.notify_all();
|
||||
}
|
||||
|
||||
// Add a set of elements to the queue.
|
||||
void EnqueueAll(std::vector<T>&& elements) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
for (T& element : elements)
|
||||
queue_.push(std::move(element));
|
||||
elements.clear();
|
||||
waiter_->cv.notify_all();
|
||||
}
|
||||
|
||||
// Return all elements in the queue.
|
||||
std::vector<T> DequeueAll() {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
Loading…
Reference in New Issue
Block a user