[clangd] Fix a tsan failure in PreambleThrottle tests
authorKadir Cetinkaya <kadircet@google.com>
Thu, 18 Aug 2022 16:34:21 +0000 (18:34 +0200)
committerKadir Cetinkaya <kadircet@google.com>
Thu, 18 Aug 2022 16:36:01 +0000 (18:36 +0200)
clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

index 33c92b3..fd56b0d 100644 (file)
@@ -1401,9 +1401,12 @@ TEST_F(TUSchedulerTests, PreambleThrottle) {
       }
       if (Invoke)
         Invoke();
-      if (Notify && ID == Notify->first) {
-        Notify->second->notify();
-        Notify.reset();
+      {
+        std::lock_guard<std::mutex> Lock(Mu);
+        if (Notify && ID == Notify->first) {
+          Notify->second->notify();
+          Notify.reset();
+        }
       }
       return ID;
     }