[clang-tools-extra] r341797 - [clangd] Fix async index loading (from r341376).
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 10 03:00:47 PDT 2018
Author: sammccall
Date: Mon Sep 10 03:00:47 2018
New Revision: 341797
URL: http://llvm.org/viewvc/llvm-project?rev=341797&view=rev
Log:
[clangd] Fix async index loading (from r341376).
Summary:
This wasn't actually async (due to std::future destructor blocking).
If it were, we would have clean shutdown issues if main returned
and destroyed Placeholder before the thread is done with it.
We could attempt to avoid any blocking by using shared_ptr or weak_ptr tricks so
the thread can detect Placeholder's destruction, but there are other potential
issues (e.g. loadIndex does tracing, and we'll destroy the tracer...)
Instead, once LSPServer::run returns, we wait for the index to finish loading
before exiting. Performance is not critical in this situation.
Reviewers: ilya-biryukov
Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D51674
Modified:
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=341797&r1=341796&r2=341797&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Mon Sep 10 03:00:47 2018
@@ -270,14 +270,17 @@ int main(int argc, char *argv[]) {
Opts.ResourceDir = ResourceDir;
Opts.BuildDynamicSymbolIndex = EnableIndex;
std::unique_ptr<SymbolIndex> StaticIdx;
+ std::future<void> AsyncIndexLoad; // Block exit while loading the index.
if (EnableIndex && !YamlSymbolFile.empty()) {
// Load the index asynchronously. Meanwhile SwapIndex returns no results.
SwapIndex *Placeholder;
StaticIdx.reset(Placeholder = new SwapIndex(llvm::make_unique<MemIndex>()));
- runAsync<void>([Placeholder, &Opts] {
+ AsyncIndexLoad = runAsync<void>([Placeholder, &Opts] {
if (auto Idx = loadIndex(YamlSymbolFile, Opts.URISchemes, UseDex))
Placeholder->reset(std::move(Idx));
});
+ if (RunSynchronously)
+ AsyncIndexLoad.wait();
}
Opts.StaticIndex = StaticIdx.get();
Opts.AsyncThreadsCount = WorkerThreadsCount;
More information about the cfe-commits
mailing list