Skip to content

Commit

Permalink
[BOLT] Change mutex implementation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ElvinaYakubova committed Jul 6, 2022
1 parent 484b4f3 commit 35155a0
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions bolt/runtime/common.h
Expand Up @@ -468,17 +468,12 @@ void assert(bool Assertion, const char *Msg) {
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
Expand Down

0 comments on commit 35155a0

Please sign in to comment.