mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 08:06:06 +00:00
[BOLT] Change mutex implementation
Changed acquire implemetaion 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 Reviewers: yota9, maksfb, rafauler Differential Revision: https://reviews.llvm.org/D129162
This commit is contained in:
parent
484b4f3579
commit
35155a0716
@ -468,17 +468,12 @@ void assert(bool Assertion, const char *Msg) {
|
|||||||
reportError(Buf, Ptr - Buf);
|
reportError(Buf, Ptr - Buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 1B mutex accessed by lock xchg
|
|
||||||
class Mutex {
|
class Mutex {
|
||||||
volatile bool InUse{false};
|
volatile bool InUse{false};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool acquire() {
|
bool acquire() { return !__atomic_test_and_set(&InUse, __ATOMIC_ACQUIRE); }
|
||||||
bool Result = true;
|
void release() { __atomic_clear(&InUse, __ATOMIC_RELEASE); }
|
||||||
asm volatile("lock; xchg %0, %1" : "+m"(InUse), "=r"(Result) : : "cc");
|
|
||||||
return !Result;
|
|
||||||
}
|
|
||||||
void release() { InUse = false; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// RAII wrapper for Mutex
|
/// RAII wrapper for Mutex
|
||||||
|
Loading…
x
Reference in New Issue
Block a user