[PATCH] D129162: [BOLT] Change mutex implementation

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


Elvina created this revision.
Elvina added reviewers: yota9, maksfb, rafaelauler.
Elvina added a project: LLVM.
Herald added a reviewer: rafauler.
Herald added a subscriber: ayermolo.
Herald added a reviewer: Amir.
Herald added a project: All.
Elvina requested review of this revision.
Herald added a subscriber: llvm-commits.

Changed acquire implementation to __atomic_test_and_set() and release to __atomic_clear() so it eliminates inline asm usage and is arch independent.

      

Elvina Yakubova,
Advanced Software Technology Lab, Huawei


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129162

Files:
  bolt/runtime/common.h


Index: bolt/runtime/common.h
===================================================================
--- bolt/runtime/common.h
+++ bolt/runtime/common.h
@@ -470,15 +470,11 @@
 
 /// 1B mutex accessed by lock xchg
 class Mutex {
-  volatile bool InUse{false};
+  volatile bool Result{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(&Result, __ATOMIC_ACQUIRE); }
+  void release() { __atomic_clear(&Result, __ATOMIC_RELEASE); }
 };
 
 /// RAII wrapper for Mutex


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


More information about the llvm-commits mailing list