[clang-tools-extra] r324363 - [clangd] Fixed a bug in the new threading implementation.

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 6 09:22:58 PST 2018


Author: ibiryukov
Date: Tue Feb  6 09:22:58 2018
New Revision: 324363

URL: http://llvm.org/viewvc/llvm-project?rev=324363&view=rev
Log:
[clangd] Fixed a bug in the new threading implementation.

This should fix the buildbots.

Modified:
    clang-tools-extra/trunk/clangd/Threading.cpp

Modified: clang-tools-extra/trunk/clangd/Threading.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Threading.cpp?rev=324363&r1=324362&r2=324363&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Threading.cpp (original)
+++ clang-tools-extra/trunk/clangd/Threading.cpp Tue Feb  6 09:22:58 2018
@@ -40,12 +40,13 @@ void AsyncTaskRunner::runAsync(UniqueFun
   }
 
   auto CleanupTask = llvm::make_scope_exit([this]() {
-    std::unique_lock<std::mutex> Lock(Mutex);
+    std::lock_guard<std::mutex> Lock(Mutex);
     int NewTasksCnt = --InFlightTasks;
-    Lock.unlock();
-
-    if (NewTasksCnt == 0)
+    if (NewTasksCnt == 0) {
+      // Note: we can't unlock here because we don't want the object to be
+      // destroyed before we notify.
       TasksReachedZero.notify_one();
+    }
   });
 
   std::thread(




More information about the cfe-commits mailing list