Kernel - General fixing after ARM7 changes
[tpg/acess2.git] / Kernel / arch / arm7 / include / lock.h
1 /*
2  * Acess2
3  * ARM7 Architecture
4  *
5  * lock.h - Hardware level spinlocks
6  */
7 #ifndef _LOCK_H_
8 #define _LOCK_H_
9
10 // === CODE ===
11 struct sShortSpinlock {
12          int    Lock;
13 };
14
15 // --- Spinlocks ---
16 static inline int IS_LOCKED(struct sShortSpinlock *Lock)
17 {
18         return !!Lock->Lock;
19 }
20
21 static inline int CPU_HAS_LOCK(struct sShortSpinlock *Lock)
22 {
23         // TODO: Handle multiple CPUs
24         return !!Lock->Lock;
25 }
26
27 static inline int SHORTLOCK(struct sShortSpinlock *Lock)
28 {
29         #if 0
30         while( __sync_lock_test_and_set( &Lock->Lock, 1 ) == 1 );
31         #endif
32         #if 1
33         while( Lock->Lock )     ;
34         Lock->Lock = 1;
35         #endif
36         #if 0
37         // Shamelessly copied from linux (/arch/arm/include/asm/spinlock.h) until I can fix stuff
38         Uint    tmp;
39         __asm__ __volatile__ (
40         "1:     ldrex   %0, [%1]\n"
41         "       teq     %0, #0\n"
42         "       strexeq %0, %2, [%1]\n" // Magic? TODO: Look up
43         "       teqeq   %0, #0\n"
44         "       bne     1b"
45                 : "=&r" (tmp)   // Temp
46                 : "r" (&Lock->Lock), "r" (1)
47                 : "cc"  // Condition codes clobbered
48                 );
49         #endif
50         return 1;
51 }
52
53 static inline void SHORTREL(struct sShortSpinlock *Lock)
54 {
55         Lock->Lock = 0;
56 }
57
58 #endif
59

UCC git Repository :: git.ucc.asn.au