summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrsc <rsc>2007-08-24 20:06:14 +0000
committerrsc <rsc>2007-08-24 20:06:14 +0000
commit5af5f6aa7f52db85f0f22555ae39395dbe68b731 (patch)
tree556fe8b50bcf1e65512204c302a0bb5f9a9280b1
parent4bcd0f6a77e20c78632b64fe6ee57129556a531d (diff)
downloadxv6-labs-5af5f6aa7f52db85f0f22555ae39395dbe68b731.tar.gz
xv6-labs-5af5f6aa7f52db85f0f22555ae39395dbe68b731.tar.bz2
xv6-labs-5af5f6aa7f52db85f0f22555ae39395dbe68b731.zip
Reorder spinlock.c: acquire and release first
-rw-r--r--spinlock.c51
1 files changed, 26 insertions, 25 deletions
diff --git a/spinlock.c b/spinlock.c
index b194211..af0c2e9 100644
--- a/spinlock.c
+++ b/spinlock.c
@@ -18,31 +18,6 @@ initlock(struct spinlock *lock, char *name)
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.
// Loops (spins) until the lock is acquired.
// (Because contention is handled by spinning,
@@ -90,3 +65,29 @@ release(struct spinlock *lock)
if(--cpus[cpu()].nlock == 0)
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;
+}
+