2006-06-22 01:28:57 +00:00
|
|
|
#include "types.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "x86.h"
|
|
|
|
|
|
|
|
#define LOCK_FREE -1
|
|
|
|
|
|
|
|
uint32_t kernel_lock = LOCK_FREE;
|
|
|
|
|
|
|
|
// lock = LOCK_FREE if free, else = cpu_id of owner CPU
|
|
|
|
void
|
|
|
|
acquire_spinlock(uint32_t* lock)
|
|
|
|
{
|
2006-06-22 20:47:23 +00:00
|
|
|
int cpu_id = cpu();
|
2006-06-22 01:28:57 +00:00
|
|
|
|
|
|
|
if (*lock == cpu_id)
|
|
|
|
return;
|
|
|
|
while ( cmpxchg(LOCK_FREE, cpu_id, lock) != cpu_id ) { ; }
|
2006-06-26 15:11:19 +00:00
|
|
|
// cprintf ("acquired: %d\n", cpu_id);
|
2006-06-22 01:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
release_spinlock(uint32_t* lock)
|
|
|
|
{
|
2006-06-22 20:47:23 +00:00
|
|
|
int cpu_id = cpu();
|
2006-06-26 15:11:19 +00:00
|
|
|
// cprintf ("release: %d\n", cpu_id);
|
2006-06-22 01:28:57 +00:00
|
|
|
if (*lock != cpu_id)
|
|
|
|
panic("release_spinlock: releasing a lock that i don't own\n");
|
|
|
|
*lock = LOCK_FREE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
release_grant_spinlock(uint32_t* lock, int c)
|
|
|
|
{
|
2006-06-22 20:47:23 +00:00
|
|
|
int cpu_id = cpu();
|
2006-06-26 15:11:19 +00:00
|
|
|
// cprintf ("release_grant: %d -> %d\n", cpu_id, c);
|
2006-06-22 01:28:57 +00:00
|
|
|
if (*lock != cpu_id)
|
|
|
|
panic("release_spinlock: releasing a lock that i don't own\n");
|
|
|
|
*lock = c;
|
|
|
|
}
|