*/
#include <acess.h>
#include <threads_int.h>
+#include <arch_int.h>
+#include <hal_proc.h> // GetCPUNum
#define TRACE_LOCKS 0
//#define TRACE_LOCK_COND (Lock != &glDebug_Lock && Lock != &glPhysAlloc.Protector)
#endif
-extern int GetCPUNum(void);
-
// === PROTOTYPES ==
Uint64 __divmod64(Uint64 Num, Uint64 Den, Uint64 *Rem);
Uint64 __udivdi3(Uint64 Num, Uint64 Den);
return Lock->Lock == GetCPUNum() + 1;
}
+void __AtomicTestSetLoop(Uint *Ptr, Uint Value)
+{
+ __ASM__(
+ "1:\n\t"
+ "xor %%eax, %%eax;\n\t"
+ "lock cmpxchgl %0, (%1);\n\t"
+ "jnz 1b;\n\t"
+ :: "r"(Value), "r"(Ptr)
+ : "eax" // EAX clobbered
+ );
+}
/**
* \brief Acquire a Short Spinlock
* \param Lock Lock pointer
__ASM__("cli");
// Wait for another CPU to release
- __ASM__(
- "1:\n\t"
- "xor %%eax, %%eax;\n\t"
- "lock cmpxchgl %0, (%1);\n\t"
- "jnz 1b;\n\t"
- :: "r"(cpu), "r"(&Lock->Lock)
- : "eax" // EAX clobbered
- );
-
+ __AtomicTestSetLoop( (Uint*)&Lock->Lock, cpu );
Lock->IF = IF;
#if TRACE_LOCKS