Skip to content
Snippets Groups Projects
Commit dda6fe10 authored by John Hodge's avatar John Hodge
Browse files

Kernel/x86 - Fixed bug in SHORTLOCK that caused locks to always succeed

parent 77e039d9
No related merge requests found
...@@ -17,8 +17,11 @@ ...@@ -17,8 +17,11 @@
// === IMPRORTS === // === IMPRORTS ===
#if TRACE_LOCKS #if TRACE_LOCKS
extern struct sShortSpinlock glDebug_Lock; extern struct sShortSpinlock glDebug_Lock;
extern struct sShortSpinlock glThreadListLock; extern tMutex glPhysAlloc;
#define TRACE_LOCK_COND (Lock != &glDebug_Lock && Lock != &glThreadListLock && Lock != &glPhysAlloc.Protector)
//#define TRACE_LOCK_COND (Lock != &glDebug_Lock && Lock != &glPhysAlloc.Protector)
#endif #endif
extern int GetCPUNum(void); extern int GetCPUNum(void);
// === PROTOTYPES == // === PROTOTYPES ==
...@@ -64,7 +67,6 @@ int CPU_HAS_LOCK(struct sShortSpinlock *Lock) ...@@ -64,7 +67,6 @@ int CPU_HAS_LOCK(struct sShortSpinlock *Lock)
*/ */
void SHORTLOCK(struct sShortSpinlock *Lock) void SHORTLOCK(struct sShortSpinlock *Lock)
{ {
int v = 1;
int IF; int IF;
int cpu = GetCPUNum() + 1; int cpu = GetCPUNum() + 1;
...@@ -73,10 +75,10 @@ void SHORTLOCK(struct sShortSpinlock *Lock) ...@@ -73,10 +75,10 @@ void SHORTLOCK(struct sShortSpinlock *Lock)
IF &= 0x200; // AND out all but the interrupt flag IF &= 0x200; // AND out all but the interrupt flag
#if TRACE_LOCKS #if TRACE_LOCKS
if( Lock != &glDebug_Lock && Lock != &glThreadListLock ) if( TRACE_LOCK_COND )
{ {
//Log_Log("LOCK", "%p locked by %p", Lock, __builtin_return_address(0)); //Log_Log("LOCK", "%p locked by %p", Lock, __builtin_return_address(0));
Debug("%p obtaining %p (Called by %p)", __builtin_return_address(0), Lock, __builtin_return_address(1)); Debug("%i %p obtaining %p (Called by %p)", cpu-1, __builtin_return_address(0), Lock, __builtin_return_address(1));
} }
#endif #endif
...@@ -84,20 +86,22 @@ void SHORTLOCK(struct sShortSpinlock *Lock) ...@@ -84,20 +86,22 @@ void SHORTLOCK(struct sShortSpinlock *Lock)
// Wait for another CPU to release // Wait for another CPU to release
__ASM__( __ASM__(
"1: lock cmpxchgl %2, (%3)\n\t" "1:\n\t"
"jnz 1b" "xor %%eax, %%eax;\n\t"
: "=a"(v) "lock cmpxchgl %0, (%1);\n\t"
: "a"(0), "r"(cpu), "r"(&Lock->Lock) "jnz 1b;\n\t"
:: "r"(cpu), "r"(&Lock->Lock)
: "eax" // EAX clobbered
); );
Lock->IF = IF; Lock->IF = IF;
#if TRACE_LOCKS #if TRACE_LOCKS
if( Lock != &glDebug_Lock && Lock != &glThreadListLock ) if( TRACE_LOCK_COND )
{ {
//Log_Log("LOCK", "%p locked by %p", Lock, __builtin_return_address(0)); //Log_Log("LOCK", "%p locked by %p", Lock, __builtin_return_address(0));
//Debug("Lock %p locked by %p\t%p", Lock, __builtin_return_address(0), __builtin_return_address(1)); Debug("%i %p locked by %p\t%p", cpu-1, Lock, __builtin_return_address(0), __builtin_return_address(1));
Debug("got it"); // Debug("got it");
} }
#endif #endif
} }
...@@ -108,7 +112,7 @@ void SHORTLOCK(struct sShortSpinlock *Lock) ...@@ -108,7 +112,7 @@ void SHORTLOCK(struct sShortSpinlock *Lock)
void SHORTREL(struct sShortSpinlock *Lock) void SHORTREL(struct sShortSpinlock *Lock)
{ {
#if TRACE_LOCKS #if TRACE_LOCKS
if( Lock != &glDebug_Lock && Lock != &glThreadListLock ) if( TRACE_LOCK_COND )
{ {
//Log_Log("LOCK", "%p released by %p", Lock, __builtin_return_address(0)); //Log_Log("LOCK", "%p released by %p", Lock, __builtin_return_address(0));
Debug("Lock %p released by %p\t%p", Lock, __builtin_return_address(0), __builtin_return_address(1)); Debug("Lock %p released by %p\t%p", Lock, __builtin_return_address(0), __builtin_return_address(1));
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment