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
0badeaa2
Commit
0badeaa2
authored
15 years ago
by
rsc
Browse files
Options
Downloads
Patches
Plain Diff
bio.c: use struct like icache does
parent
c47bc4fd
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
bio.c
+31
-30
31 additions, 30 deletions
bio.c
with
31 additions
and
30 deletions
bio.c
+
31
−
30
View file @
0badeaa2
...
...
@@ -27,30 +27,32 @@
#include
"spinlock.h"
#include
"buf.h"
struct
buf
buf
[
NBUF
];
struct
spinlock
buf_table_lock
;
struct
{
struct
spinlock
lock
;
struct
buf
buf
[
NBUF
];
// Linked list of all buffers, through prev/next.
//
buf
head
->
next is most recently used.
// bufhead->tail is least recently used.
struct
buf
bufhead
;
// Linked list of all buffers, through prev/next.
// head
.
next is most recently used.
struct
buf
head
;
}
bcache
;
void
binit
(
void
)
{
struct
buf
*
b
;
initlock
(
&
b
uf_table_
lock
,
"buf_table"
);
initlock
(
&
b
cache
.
lock
,
"buf_table"
);
//PAGEBREAK!
// Create linked list of buffers
bufhead
.
prev
=
&
bufhead
;
bufhead
.
next
=
&
bufhead
;
for
(
b
=
buf
;
b
<
buf
+
NBUF
;
b
++
){
b
->
next
=
bufhead
.
next
;
b
->
prev
=
&
bufhead
;
bufhead
.
next
->
prev
=
b
;
bufhead
.
next
=
b
;
bcache
.
head
.
prev
=
&
bcache
.
head
;
bcache
.
head
.
next
=
&
bcache
.
head
;
for
(
b
=
bcache
.
buf
;
b
<
bcache
.
buf
+
NBUF
;
b
++
){
b
->
next
=
bcache
.
head
.
next
;
b
->
prev
=
&
bcache
.
head
;
b
->
dev
=
-
1
;
bcache
.
head
.
next
->
prev
=
b
;
bcache
.
head
.
next
=
b
;
}
}
...
...
@@ -62,30 +64,29 @@ bget(uint dev, uint sector)
{
struct
buf
*
b
;
acquire
(
&
b
uf_table_
lock
);
acquire
(
&
b
cache
.
lock
);
loop:
// Try for cached block.
for
(
b
=
bufhead
.
next
;
b
!=
&
bufhead
;
b
=
b
->
next
){
if
((
b
->
flags
&
(
B_BUSY
|
B_VALID
))
&&
b
->
dev
==
dev
&&
b
->
sector
==
sector
){
for
(
b
=
bcache
.
head
.
next
;
b
!=
&
bcache
.
head
;
b
=
b
->
next
){
if
(
b
->
dev
==
dev
&&
b
->
sector
==
sector
){
if
(
!
(
b
->
flags
&
B_BUSY
)){
b
->
flags
|=
B_BUSY
;
release
(
&
b
uf_table_
lock
);
release
(
&
b
cache
.
lock
);
return
b
;
}
sleep
(
b
,
&
b
uf_table_
lock
);
sleep
(
b
,
&
b
cache
.
lock
);
goto
loop
;
}
}
// Allocate fresh block.
for
(
b
=
b
uf
head
.
prev
;
b
!=
&
b
uf
head
;
b
=
b
->
prev
){
for
(
b
=
b
cache
.
head
.
prev
;
b
!=
&
b
cache
.
head
;
b
=
b
->
prev
){
if
((
b
->
flags
&
B_BUSY
)
==
0
){
b
->
dev
=
dev
;
b
->
sector
=
sector
;
b
->
flags
=
B_BUSY
;
release
(
&
b
uf_table_
lock
);
release
(
&
b
cache
.
lock
);
return
b
;
}
}
...
...
@@ -104,7 +105,7 @@ bread(uint dev, uint sector)
return
b
;
}
// Write b
uf
's contents to disk. Must be locked.
// Write b's contents to disk. Must be locked.
void
bwrite
(
struct
buf
*
b
)
{
...
...
@@ -114,25 +115,25 @@ bwrite(struct buf *b)
iderw
(
b
);
}
// Release the buffer b
uf
.
// Release the buffer b.
void
brelse
(
struct
buf
*
b
)
{
if
((
b
->
flags
&
B_BUSY
)
==
0
)
panic
(
"brelse"
);
acquire
(
&
b
uf_table_
lock
);
acquire
(
&
b
cache
.
lock
);
b
->
next
->
prev
=
b
->
prev
;
b
->
prev
->
next
=
b
->
next
;
b
->
next
=
b
uf
head
.
next
;
b
->
prev
=
&
b
uf
head
;
b
uf
head
.
next
->
prev
=
b
;
b
uf
head
.
next
=
b
;
b
->
next
=
b
cache
.
head
.
next
;
b
->
prev
=
&
b
cache
.
head
;
b
cache
.
head
.
next
->
prev
=
b
;
b
cache
.
head
.
next
=
b
;
b
->
flags
&=
~
B_BUSY
;
wakeup
(
b
);
release
(
&
b
uf_table_
lock
);
release
(
&
b
cache
.
lock
);
}
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