X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86%2Finclude%2Farch.h;h=67a629016f6839576c7bbf30fb921dffa5decacb;hb=7d881c2e5fef91a6570e46ef69a5d4a5cf0e8b4d;hp=773556840a9dca2ca272d5fc2884ef3fff67a422;hpb=73e8ed89c011abce9b0ae2c5a3eb232bdbe8660e;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86/include/arch.h b/Kernel/arch/x86/include/arch.h index 77355684..67a62901 100644 --- a/Kernel/arch/x86/include/arch.h +++ b/Kernel/arch/x86/include/arch.h @@ -29,44 +29,48 @@ #define __ASM__ __asm__ __volatile__ +#define LONGLOCK_NUM_THREADS 8 + // === MACROS === -typedef volatile int tSpinlock; -#define IS_LOCKED(lockptr) (!!(*(tSpinlock*)lockptr)) -/** - * \brief Inter-Process interrupt (does a Yield) - */ -#define LOCK(lockptr) do {\ - int v=1;\ - while(v) {\ - __ASM__("xchgl %%eax, (%%edi)":"=a"(v):"a"(1),"D"(lockptr));\ - if(v) Threads_Yield();\ - }\ -}while(0) +struct sShortSpinlock { + volatile int Lock; + int IF; +}; /** - * \brief Tight spinlock (does a HLT) + * \brief Determine if a short spinlock is locked */ -#define TIGHTLOCK(lockptr) do{\ - int v=1;\ - while(v) {\ - __ASM__("xchgl %%eax,(%%edi)":"=a"(v):"a"(1),"D"(lockptr));\ - if(v) __ASM__("hlt");\ - }\ -}while(0) +static inline int IS_LOCKED(struct sShortSpinlock *Lock) { + return !!Lock->Lock; +} /** - * \brief Very Tight spinlock (short inter-cpu lock) + * \brief Acquire a Short Spinlock + * \note Stops interrupts, so be careful */ -#define VTIGHTLOCK(lockptr) do{\ - int v=1;\ - while(v)__ASM__("xchgl %%eax,(%%edi)":"=a"(v):"a"(1),"D"(lockptr));\ -}while(0) +static inline void SHORTLOCK(struct sShortSpinlock *Lock) { + int v = 1; + __ASM__ ("pushf;\n\tpop %%eax" : "=a"(Lock->IF)); + Lock->IF &= 0x200; + __ASM__ ("cli"); // Stop task switches + // Wait for another CPU to release + while(v) + __ASM__("xchgl %%eax, (%%edi)":"=a"(v):"a"(1),"D"(&Lock->Lock)); +} /** - * \brief Release a held spinlock + * \brief Release a short lock */ -#define RELEASE(lockptr) __ASM__("lock andl $0, (%%edi)"::"D"(lockptr)); +static inline void SHORTREL(struct sShortSpinlock *Lock) { + Lock->Lock = 0; + #if 0 + __ASM__ ("pushf;\n\tor %0, (%%esp);\n\tpopf" : : "a"(Lock->IF)); + #else + if(Lock->IF) __ASM__ ("sti"); + #endif +} /** * \brief Halt the CPU */ #define HALT() __asm__ __volatile__ ("hlt") +#define MAGIC_BREAK() __asm__ __volatile__ ("xchg %bx, %bx") // === TYPES === typedef unsigned int Uint; // Unsigned machine native integer