diff options
author | Ilya Biryukov <ibiryukov@google.com> | 2019-05-09 12:04:07 +0000 |
---|---|---|
committer | Ilya Biryukov <ibiryukov@google.com> | 2019-05-09 12:04:07 +0000 |
commit | db68b104d8d4de92e123af2e52084aace564673e (patch) | |
tree | e5ceac8abe4c96a2950623f93451a8729cb4a256 | |
parent | d7b650cc721f7dbb52cbfa0a50797e61990d7990 (diff) | |
download | bcm5719-llvm-db68b104d8d4de92e123af2e52084aace564673e.tar.gz bcm5719-llvm-db68b104d8d4de92e123af2e52084aace564673e.zip |
[clangd] Use AsyncTaskRunner in BackgroundIndex instead of std::thread
Summary:
To unify the way we create threads in clangd.
This should simplify landing D50993.
Reviewers: kadircet
Reviewed By: kadircet
Subscribers: MaskRay, jkorous, arphaman, jfb, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61724
llvm-svn: 360332
-rw-r--r-- | clang-tools-extra/clangd/index/Background.cpp | 11 | ||||
-rw-r--r-- | clang-tools-extra/clangd/index/Background.h | 2 |
2 files changed, 7 insertions, 6 deletions
diff --git a/clang-tools-extra/clangd/index/Background.cpp b/clang-tools-extra/clangd/index/Background.cpp index 0746a358371..67053948a03 100644 --- a/clang-tools-extra/clangd/index/Background.cpp +++ b/clang-tools-extra/clangd/index/Background.cpp @@ -148,19 +148,20 @@ BackgroundIndex::BackgroundIndex( })) { assert(ThreadPoolSize > 0 && "Thread pool size can't be zero."); assert(this->IndexStorageFactory && "Storage factory can not be null!"); - while (ThreadPoolSize--) - ThreadPool.emplace_back([this] { run(); }); + for (unsigned I = 0; I < ThreadPoolSize; ++I) { + ThreadPool.runAsync("background-worker-" + llvm::Twine(I + 1), + [this] { run(); }); + } if (BuildIndexPeriodMs > 0) { log("BackgroundIndex: build symbol index periodically every {0} ms.", BuildIndexPeriodMs); - ThreadPool.emplace_back([this] { buildIndex(); }); + ThreadPool.runAsync("background-index-builder", [this] { buildIndex(); }); } } BackgroundIndex::~BackgroundIndex() { stop(); - for (auto &Thread : ThreadPool) - Thread.join(); + ThreadPool.wait(); } void BackgroundIndex::stop() { diff --git a/clang-tools-extra/clangd/index/Background.h b/clang-tools-extra/clangd/index/Background.h index 2132e579db4..cc530d5ac58 100644 --- a/clang-tools-extra/clangd/index/Background.h +++ b/clang-tools-extra/clangd/index/Background.h @@ -146,7 +146,7 @@ private: std::condition_variable QueueCV; bool ShouldStop = false; std::deque<std::pair<Task, llvm::ThreadPriority>> Queue; - std::vector<std::thread> ThreadPool; // FIXME: Abstract this away. + AsyncTaskRunner ThreadPool; GlobalCompilationDatabase::CommandChanged::Subscription CommandsChanged; }; |