Update spinlock_gcc_arm.hpp
Added logic to use LSE as a primary instead of Swap.
This commit is contained in:
@@ -29,11 +29,30 @@ public:
|
|||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
#if defined(__ARM_FEATURE_LSE)
|
||||||
|
// Use LSE atomic instructions if supported
|
||||||
|
#pragma message("LSE feature detected") // This will print a message in your build logs
|
||||||
__asm__ __volatile__(
|
__asm__ __volatile__(
|
||||||
"swp %0, %1, [%2]":
|
"ldaxr %0, [%1];" // Load-Exclusive instruction
|
||||||
"=&r"( r ): // outputs
|
"cbnz %0, 1f;" // If the value is non-zero, the lock is already acquired
|
||||||
"r"( 1 ), "r"( &v_ ): // inputs
|
"stlxr %w0, %2, [%1];" // Store-Exclusive instruction
|
||||||
"memory", "cc" );
|
"cbnz %w0, 1f;" // If the store failed, retry
|
||||||
|
"mov %0, #0;" // Success, zero indicates lock acquired
|
||||||
|
"1:"
|
||||||
|
: "=&r"(r)
|
||||||
|
: "r"(&v_), "r"(1)
|
||||||
|
: "memory", "cc"
|
||||||
|
);
|
||||||
|
#else
|
||||||
|
// Fallback for systems that don't support LSE
|
||||||
|
#pragma message("LSE feature not detected") // This will print a message in your build logs if LSE is not detected
|
||||||
|
__asm__ __volatile__(
|
||||||
|
"swp %0, %1, [%2];" // Swap instruction (used as a fallback)
|
||||||
|
: "=&r"(r) // output constraint
|
||||||
|
: "r"(1), "r"(&v_) // input constraints
|
||||||
|
: "memory", "cc" // clobbered registers
|
||||||
|
);
|
||||||
|
#endif
|
||||||
|
|
||||||
return r == 0;
|
return r == 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user