[PATCH] D51674: [clangd] Fix async index loading (from r341376).

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 5 01:10:04 PDT 2018


sammccall created this revision.
sammccall added a reviewer: ilya-biryukov.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, ioeric.

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.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51674

Files:
  clangd/tool/ClangdMain.cpp


Index: clangd/tool/ClangdMain.cpp
===================================================================
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -280,11 +280,12 @@
     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] {
+    AsyncIndexLoad = runAsync<void>([Placeholder] {
       if (auto Idx = loadIndex(YamlSymbolFile))
         Placeholder->reset(std::move(Idx));
     });


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51674.163978.patch
Type: text/x-patch
Size: 820 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180905/766b6d6a/attachment.bin>


More information about the cfe-commits mailing list