[llvm] r328271 - [Support/Parallel] Use lock_guard which has less overhead than unique_lock.

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 22 16:40:02 PDT 2018


Author: maskray
Date: Thu Mar 22 16:40:02 2018
New Revision: 328271

URL: http://llvm.org/viewvc/llvm-project?rev=328271&view=rev
Log:
[Support/Parallel] Use lock_guard which has less overhead than unique_lock.

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

Modified:
    llvm/trunk/include/llvm/Support/Parallel.h

Modified: llvm/trunk/include/llvm/Support/Parallel.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Parallel.h?rev=328271&r1=328270&r2=328271&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Parallel.h (original)
+++ llvm/trunk/include/llvm/Support/Parallel.h Thu Mar 22 16:40:02 2018
@@ -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();
   }




More information about the llvm-commits mailing list