[PATCH] D129162: [BOLT] Change mutex implementation

Elvina Yakubova via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 5 14:42:30 PDT 2022


Elvina updated this revision to Diff 442401.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129162/new/

https://reviews.llvm.org/D129162

Files:
  bolt/runtime/common.h


Index: bolt/runtime/common.h
===================================================================
--- bolt/runtime/common.h
+++ bolt/runtime/common.h
@@ -468,17 +468,12 @@
   reportError(Buf, Ptr - Buf);
 }
 
-/// 1B mutex accessed by lock xchg
 class Mutex {
   volatile bool InUse{false};
 
 public:
-  bool acquire() {
-    bool Result = true;
-    asm volatile("lock; xchg %0, %1" : "+m"(InUse), "=r"(Result) : : "cc");
-    return !Result;
-  }
-  void release() { InUse = false; }
+  bool acquire() { return !__atomic_test_and_set(&InUse, __ATOMIC_ACQUIRE); }
+  void release() { __atomic_clear(&InUse, __ATOMIC_RELEASE); }
 };
 
 /// RAII wrapper for Mutex


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129162.442401.patch
Type: text/x-patch
Size: 663 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220705/98d950a0/attachment.bin>


More information about the llvm-commits mailing list