5 * lock.h - Hardware level spinlocks
11 struct sShortSpinlock {
16 static inline int IS_LOCKED(struct sShortSpinlock *Lock)
21 static inline int CPU_HAS_LOCK(struct sShortSpinlock *Lock)
23 // TODO: Handle multiple CPUs
27 static inline int SHORTLOCK(struct sShortSpinlock *Lock)
29 // Coped from linux, yes, but I know what it does now :)
31 __asm__ __volatile__ (
32 "1: ldrex %0, [%1]\n" // Exclusive LOAD
33 " teq %0, #0\n" // Check if zero
34 " strexeq %0, %2, [%1]\n" // Set to one if it is zero (releasing lock on the memory)
35 " teqeq %0, #0\n" // If the lock was avaliable, check if the write succeeded
36 " bne 1b" // If the lock was unavaliable, or the write failed, loop
38 : "r" (&Lock->Lock), "r" (1)
39 : "cc" // Condition codes clobbered
44 static inline void SHORTREL(struct sShortSpinlock *Lock)