Skip to content
Snippets Groups Projects
Commit 5af5f6aa authored by rsc's avatar rsc
Browse files

Reorder spinlock.c: acquire and release first

parent 4bcd0f6a
No related branches found
No related tags found
No related merge requests found
...@@ -18,31 +18,6 @@ initlock(struct spinlock *lock, char *name) ...@@ -18,31 +18,6 @@ initlock(struct spinlock *lock, char *name)
lock->cpu = 0xffffffff; lock->cpu = 0xffffffff;
} }
// Record the current call stack in pcs[] by following the %ebp chain.
void
getcallerpcs(void *v, uint pcs[])
{
uint *ebp;
int i;
ebp = (uint*)v - 2;
for(i = 0; i < 10; i++){
if(ebp == 0 || ebp == (uint*)0xffffffff)
break;
pcs[i] = ebp[1]; // saved %eip
ebp = (uint*)ebp[0]; // saved %ebp
}
for(; i < 10; i++)
pcs[i] = 0;
}
// Check whether this cpu is holding the lock.
int
holding(struct spinlock *lock)
{
return lock->locked && lock->cpu == cpu() + 10;
}
// Acquire the lock. // Acquire the lock.
// Loops (spins) until the lock is acquired. // Loops (spins) until the lock is acquired.
// (Because contention is handled by spinning, // (Because contention is handled by spinning,
...@@ -90,3 +65,29 @@ release(struct spinlock *lock) ...@@ -90,3 +65,29 @@ release(struct spinlock *lock)
if(--cpus[cpu()].nlock == 0) if(--cpus[cpu()].nlock == 0)
sti(); sti();
} }
// Record the current call stack in pcs[] by following the %ebp chain.
void
getcallerpcs(void *v, uint pcs[])
{
uint *ebp;
int i;
ebp = (uint*)v - 2;
for(i = 0; i < 10; i++){
if(ebp == 0 || ebp == (uint*)0xffffffff)
break;
pcs[i] = ebp[1]; // saved %eip
ebp = (uint*)ebp[0]; // saved %ebp
}
for(; i < 10; i++)
pcs[i] = 0;
}
// Check whether this cpu is holding the lock.
int
holding(struct spinlock *lock)
{
return lock->locked && lock->cpu == cpu() + 10;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment