merged cleanup
This commit is contained in:
@ -10,7 +10,6 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "lib/SpinLock.h"
|
||||
#include "kernel/Globals.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: CAS *
|
||||
@ -24,7 +23,7 @@
|
||||
* *ptr := _new *
|
||||
* return prev *
|
||||
*****************************************************************************/
|
||||
static inline unsigned long CAS(unsigned long* ptr, unsigned long old, unsigned long _new) {
|
||||
static inline unsigned long CAS(const unsigned long* ptr) {
|
||||
unsigned long prev;
|
||||
|
||||
/*
|
||||
@ -38,7 +37,7 @@ static inline unsigned long CAS(unsigned long* ptr, unsigned long old, unsigned
|
||||
"cmpxchg %1, %2;" // %1 = _new; %2 = *ptr
|
||||
// constraints
|
||||
: "=a"(prev) // output: =a: RAX -> prev (%0))
|
||||
: "r"(_new), "m"(*ptr), "a"(old) // input = %1, %2, %3 (r=register, m=memory, a=accumlator = eax
|
||||
: "r"(1), "m"(*ptr), "a"(0) // input = %1, %2, %3 (r=register, m=memory, a=accumlator = eax
|
||||
: "memory"); // ensures assembly block will not be moved by gcc
|
||||
|
||||
return prev; // return pointer instead of prev to prevent unnecessary second call
|
||||
@ -52,7 +51,7 @@ static inline unsigned long CAS(unsigned long* ptr, unsigned long old, unsigned
|
||||
void SpinLock::acquire() {
|
||||
// If lock == 0 the SpinLock can be aquired without waiting
|
||||
// If lock == 1 the while loop blocks until aquired
|
||||
while (CAS(ptr, 0, 1) != 0) {}
|
||||
while (CAS(ptr) != 0) {}
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user