X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Farm7%2Finclude%2Flock.h;h=5a6708623bf4af36aeca3c1ae2e076376e4a7647;hb=ada42e7583b4fa07b30d5c1a3e813c9754ec5e0f;hp=dbcac936fce86d35cdc3a0b67767024f4b52b070;hpb=d7c3119cb69fab67f57d92f7055d0309f07218de;p=tpg%2Facess2.git diff --git a/Kernel/arch/arm7/include/lock.h b/Kernel/arch/arm7/include/lock.h index dbcac936..5a670862 100644 --- a/Kernel/arch/arm7/include/lock.h +++ b/Kernel/arch/arm7/include/lock.h @@ -26,31 +26,18 @@ static inline int CPU_HAS_LOCK(struct sShortSpinlock *Lock) static inline int SHORTLOCK(struct sShortSpinlock *Lock) { - #if 0 - while( __sync_lock_test_and_set( &Lock->Lock, 1 ) == 1 ); - #elif 0 - while( Lock->Lock ) ; - Lock->Lock = 1; - #elif 1 - int v = 1; - while( v ) - { - __asm__ __volatile__ ("swp [%0], %1" : "=r" (v) : "r" (&lock)); - } - #elif 0 - // Shamelessly copied from linux (/arch/arm/include/asm/spinlock.h) until I can fix stuff + // Coped from linux, yes, but I know what it does now :) Uint tmp; __asm__ __volatile__ ( - "1: ldrex %0, [%1]\n" - " teq %0, #0\n" - " strexeq %0, %2, [%1]\n" // Magic? TODO: Look up - " teqeq %0, #0\n" - " bne 1b" + "1: ldrex %0, [%1]\n" // Exclusive LOAD + " teq %0, #0\n" // Check if zero + " strexeq %0, %2, [%1]\n" // Set to one if it is zero (releasing lock on the memory) + " teqeq %0, #0\n" // If the lock was avaliable, check if the write succeeded + " bne 1b" // If the lock was unavaliable, or the write failed, loop : "=&r" (tmp) // Temp : "r" (&Lock->Lock), "r" (1) : "cc" // Condition codes clobbered ); - #endif return 1; }