Index: clang-tools-extra/trunk/clangd/index/Background.h =================================================================== --- clang-tools-extra/trunk/clangd/index/Background.h +++ clang-tools-extra/trunk/clangd/index/Background.h @@ -146,7 +146,7 @@ std::condition_variable QueueCV; bool ShouldStop = false; std::deque> Queue; - std::vector ThreadPool; // FIXME: Abstract this away. + AsyncTaskRunner ThreadPool; GlobalCompilationDatabase::CommandChanged::Subscription CommandsChanged; }; Index: clang-tools-extra/trunk/clangd/index/Background.cpp =================================================================== --- clang-tools-extra/trunk/clangd/index/Background.cpp +++ clang-tools-extra/trunk/clangd/index/Background.cpp @@ -148,19 +148,20 @@ })) { 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() {