Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSEP551
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Krishna Vinnakota
CSEP551
Commits
b121486c
Commit
b121486c
authored
15 years ago
by
Russ Cox
Browse files
Options
Downloads
Patches
Plain Diff
spinlock: rename parameter lock -> lk
parent
b8912d99
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
spinlock.c
+15
-15
15 additions, 15 deletions
spinlock.c
with
15 additions
and
15 deletions
spinlock.c
+
15
−
15
View file @
b121486c
...
...
@@ -9,11 +9,11 @@
#include
"spinlock.h"
void
initlock
(
struct
spinlock
*
l
oc
k
,
char
*
name
)
initlock
(
struct
spinlock
*
lk
,
char
*
name
)
{
l
oc
k
->
name
=
name
;
l
oc
k
->
locked
=
0
;
l
oc
k
->
cpu
=
0xffffffff
;
lk
->
name
=
name
;
lk
->
locked
=
0
;
lk
->
cpu
=
0xffffffff
;
}
// Acquire the lock.
...
...
@@ -21,35 +21,35 @@ initlock(struct spinlock *lock, char *name)
// Holding a lock for a long time may cause
// other CPUs to waste time spinning to acquire it.
void
acquire
(
struct
spinlock
*
l
oc
k
)
acquire
(
struct
spinlock
*
lk
)
{
pushcli
();
if
(
holding
(
l
oc
k
))
if
(
holding
(
lk
))
panic
(
"acquire"
);
// The xchg is atomic.
// It also serializes, so that reads after acquire are not
// reordered before it.
while
(
xchg
(
&
l
oc
k
->
locked
,
1
)
=
=
1
)
// reordered before it.
while
(
xchg
(
&
lk
->
locked
,
1
)
!
=
0
)
;
// Record info about lock acquisition for debugging.
// The +10 is only so that we can tell the difference
// between forgetting to initialize lock->cpu
// and holding a lock on cpu 0.
l
oc
k
->
cpu
=
cpu
()
+
10
;
getcallerpcs
(
&
l
oc
k
,
l
oc
k
->
pcs
);
lk
->
cpu
=
cpu
()
+
10
;
getcallerpcs
(
&
lk
,
lk
->
pcs
);
}
// Release the lock.
void
release
(
struct
spinlock
*
l
oc
k
)
release
(
struct
spinlock
*
lk
)
{
if
(
!
holding
(
l
oc
k
))
if
(
!
holding
(
lk
))
panic
(
"release"
);
l
oc
k
->
pcs
[
0
]
=
0
;
l
oc
k
->
cpu
=
0xffffffff
;
lk
->
pcs
[
0
]
=
0
;
lk
->
cpu
=
0xffffffff
;
// The xchg serializes, so that reads before release are
// not reordered after it. The 1996 PentiumPro manual (Volume 3,
...
...
@@ -60,7 +60,7 @@ release(struct spinlock *lock)
// after a store. So lock->locked = 0 would work here.
// The xchg being asm volatile ensures gcc emits it after
// the above assignments (and after the critical section).
xchg
(
&
l
oc
k
->
locked
,
0
);
xchg
(
&
lk
->
locked
,
0
);
popcli
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment