diff options
Diffstat (limited to 'clang-tools-extra/clangd/index/BackgroundQueue.cpp')
-rw-r--r-- | clang-tools-extra/clangd/index/BackgroundQueue.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/index/BackgroundQueue.cpp b/clang-tools-extra/clangd/index/BackgroundQueue.cpp index 487dcb8f146..914097225b9 100644 --- a/clang-tools-extra/clangd/index/BackgroundQueue.cpp +++ b/clang-tools-extra/clangd/index/BackgroundQueue.cpp @@ -67,6 +67,7 @@ void BackgroundQueue::stop() { void BackgroundQueue::push(Task T) { { std::lock_guard<std::mutex> Lock(Mu); + T.QueuePri = std::max(T.QueuePri, Boosts.lookup(T.Tag)); Queue.push_back(std::move(T)); std::push_heap(Queue.begin(), Queue.end()); } @@ -76,12 +77,33 @@ void BackgroundQueue::push(Task T) { void BackgroundQueue::append(std::vector<Task> Tasks) { { std::lock_guard<std::mutex> Lock(Mu); + for (Task &T : Tasks) + T.QueuePri = std::max(T.QueuePri, Boosts.lookup(T.Tag)); std::move(Tasks.begin(), Tasks.end(), std::back_inserter(Queue)); std::make_heap(Queue.begin(), Queue.end()); } CV.notify_all(); } +void BackgroundQueue::boost(llvm::StringRef Tag, unsigned NewPriority) { + std::lock_guard<std::mutex> Lock(Mu); + unsigned &Boost = Boosts[Tag]; + bool Increase = NewPriority > Boost; + Boost = NewPriority; + if (!Increase) + return; // existing tasks unaffected + + unsigned Changes = 0; + for (Task &T : Queue) + if (Tag == T.Tag && NewPriority > T.QueuePri) { + T.QueuePri = NewPriority; + ++Changes; + } + if (Changes) + std::make_heap(Queue.begin(), Queue.end()); + // No need to signal, only rearranged items in the queue. +} + bool BackgroundQueue::blockUntilIdleForTest( llvm::Optional<double> TimeoutSeconds) { std::unique_lock<std::mutex> Lock(Mu); |