r367968 - [NFC][DirectoryWatchedTests] Unlocks mutexes before signaling condition variable

Puyan Lotfi via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 5 18:26:46 PDT 2019


Author: zer0
Date: Mon Aug  5 18:26:46 2019
New Revision: 367968

URL: http://llvm.org/viewvc/llvm-project?rev=367968&view=rev
Log:
[NFC][DirectoryWatchedTests] Unlocks mutexes before signaling condition variable

This should not affect actual behavior, but should pessimize the threading less
by avoiding the situation where:

  * mutex is still locked
  * T1 notifies on condition variable
  * T2 wakes to check mutex
  * T2 sees mutex is still locked
  * T2 waits
  * T1 unlocks mutex
  * T2 tries again, acquires mutex.

Differential Revision: https://reviews.llvm.org/D65708


Modified:
    cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp

Modified: cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp?rev=367968&r1=367967&r2=367968&view=diff
==============================================================================
--- cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp (original)
+++ cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp Mon Aug  5 18:26:46 2019
@@ -132,8 +132,10 @@ struct VerifyingConsumer {
     } else {
       ExpectedInitial.erase(It);
     }
-    if (result())
+    if (result()) {
+      L.unlock();
       ResultIsReady.notify_one();
+    }
   }
 
   void consumeNonInitial(DirectoryWatcher::Event E) {
@@ -151,8 +153,10 @@ struct VerifyingConsumer {
     } else {
       ExpectedNonInitial.erase(It);
     }
-    if (result())
+    if (result()) {
+      L.unlock();
       ResultIsReady.notify_one();
+    }
   }
 
   // This method is used by DirectoryWatcher.




More information about the cfe-commits mailing list