refactor bget to be more like iget - make it clear that sleep loops
This commit is contained in:
parent
9ad44da676
commit
3f98d050e1
1 changed files with 27 additions and 26 deletions
13
bio.c
13
bio.c
|
@ -59,7 +59,7 @@ binit(void)
|
|||
}
|
||||
}
|
||||
|
||||
// Look through buffer cache for block n on device dev.
|
||||
// Look through buffer cache for sector on device dev.
|
||||
// If not found, allocate fresh block.
|
||||
// In either case, return locked buffer.
|
||||
static struct buf*
|
||||
|
@ -69,7 +69,8 @@ bget(uint dev, uint sector)
|
|||
|
||||
acquire(&buf_table_lock);
|
||||
|
||||
for(;;){
|
||||
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)
|
||||
|
@ -78,13 +79,15 @@ bget(uint dev, uint sector)
|
|||
if(b != &bufhead){
|
||||
if(b->flags & B_BUSY){
|
||||
sleep(buf, &buf_table_lock);
|
||||
} else {
|
||||
goto loop;
|
||||
}
|
||||
b->flags |= B_BUSY;
|
||||
// b->flags &= ~B_VALID; // Force reread from disk
|
||||
release(&buf_table_lock);
|
||||
return b;
|
||||
}
|
||||
} else {
|
||||
|
||||
// Allocate fresh block.
|
||||
for(b = bufhead.prev; b != &bufhead; b = b->prev){
|
||||
if((b->flags & B_BUSY) == 0){
|
||||
b->flags = B_BUSY;
|
||||
|
@ -96,8 +99,6 @@ bget(uint dev, uint sector)
|
|||
}
|
||||
panic("bget: no buffers");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read buf's contents from disk.
|
||||
struct buf*
|
||||
|
|
Loading…
Reference in a new issue