Newer
Older
#include "types.h"
#include "defs.h"
#include "x86.h"
#include "param.h"
#include "proc.h"
#include "spinlock.h"
int getcallerpc(void *v) {
return ((int*)v)[-1];
}
void
{
if(DEBUG) cprintf("cpu%d: acquiring at %x\n", cpu(), getcallerpc(&lock));
if (lock->who == who && lock->locked){
// if we get the lock, eax will be zero
// if we don't get the lock, eax will be one
while ( cmpxchg(0, 1, &lock->locked) == 1 ) { ; }
if(DEBUG) cprintf("cpu%d: acquired at %x\n", cpu(), getcallerpc(&lock));
}
void
{
if(DEBUG) cprintf ("cpu%d: releasing at %x\n", cpu(), getcallerpc(&lock));
if(lock->who != who || lock->count < 1 || lock->locked != 1)