[PATCH] D44698: [Support/Parallel] Use lock_guard which has less overhead than unique_lock.

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 20 12:48:56 PDT 2018


MaskRay created this revision.
MaskRay added reviewers: grimar, zturner.
Herald added a subscriber: llvm-commits.

unique_lock has the overhead of tracking ownership status and the owner.


Repository:
  rL LLVM

https://reviews.llvm.org/D44698

Files:
  include/llvm/Support/Parallel.h


Index: include/llvm/Support/Parallel.h
===================================================================
--- include/llvm/Support/Parallel.h
+++ include/llvm/Support/Parallel.h
@@ -56,12 +56,12 @@
   ~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();
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44698.139180.patch
Type: text/x-patch
Size: 518 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180320/85aab51e/attachment.bin>


More information about the llvm-commits mailing list