[Support/Parallel] Use lock_guard which has less overhead than unique_lock.
authorFangrui Song <maskray@google.com>
Thu, 22 Mar 2018 23:40:02 +0000 (23:40 +0000)
committerFangrui Song <maskray@google.com>
Thu, 22 Mar 2018 23:40:02 +0000 (23:40 +0000)
Summary: unique_lock has the overhead of tracking ownership status and the owner.

Reviewers: grimar, zturner

Subscribers: llvm-commits

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

llvm-svn: 328271

llvm/include/llvm/Support/Parallel.h

index 6bc0a6bbaf2b1b63876905c7748514e7e75b8a4c..01b2bcdb812f68cd5b604e2b6276865b59c6c91e 100644 (file)
@@ -56,12 +56,12 @@ public:
   ~Latch() { sync(); }
 
   void inc() {
-    std::unique_lock<std::mutex> lock(Mutex);
+    std::lock_guard<std::mutex> lock(Mutex);
     ++Count;
   }
 
   void dec() {
-    std::unique_lock<std::mutex> lock(Mutex);
+    std::lock_guard<std::mutex> lock(Mutex);
     if (--Count == 0)
       Cond.notify_all();
   }