[PATCH] D97366: [clangd] Fix a race

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 24 03:15:34 PST 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGc94ecf3f81ca: [clangd] Fix a race (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97366/new/

https://reviews.llvm.org/D97366

Files:
  clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp


Index: clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
@@ -314,8 +314,14 @@
     ~AsyncCounter() {
       // Verify shutdown sequence was performed.
       // Real modules would not do this, to be robust to no ClangdServer.
-      EXPECT_TRUE(ShouldStop) << "ClangdServer should request shutdown";
-      EXPECT_EQ(Queue.size(), 0u) << "ClangdServer should block until idle";
+      {
+        // We still need the lock here, as Queue might be empty when
+        // ClangdServer calls blockUntilIdle, but run() might not have returned
+        // yet.
+        std::lock_guard<std::mutex> Lock(Mu);
+        EXPECT_TRUE(ShouldStop) << "ClangdServer should request shutdown";
+        EXPECT_EQ(Queue.size(), 0u) << "ClangdServer should block until idle";
+      }
       Thread.join();
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97366.326038.patch
Type: text/x-patch
Size: 1004 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210224/5543c38f/attachment.bin>


More information about the cfe-commits mailing list