Author: ibiryukov Date: Thu May 9 05:04:07 2019 New Revision: 360332 URL: http://llvm.org/viewvc/llvm-project?rev=360332&view=rev Log: [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 Modified: clang-tools-extra/trunk/clangd/index/Background.cpp clang-tools-extra/trunk/clangd/index/Background.h Modified: clang-tools-extra/trunk/clangd/index/Background.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=360332&r1=360331&r2=360332&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/index/Background.cpp (original) +++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu May 9 05:04:07 2019 @@ -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() { Modified: clang-tools-extra/trunk/clangd/index/Background.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.h?rev=360332&r1=360331&r2=360332&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/index/Background.h (original) +++ clang-tools-extra/trunk/clangd/index/Background.h Thu May 9 05:04:07 2019 @@ -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; }; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits