})) {
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() {
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;
};