From 0ca9ca0c55922f72dbf324c4ac1aecf8069d1dbe Mon Sep 17 00:00:00 2001 From: rsc Date: Sun, 31 May 2009 00:23:00 +0000 Subject: [PATCH] slight rearrangement; sleep on b not buf. --- bio.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bio.c b/bio.c index b761c3b..aea7835 100644 --- a/bio.c +++ b/bio.c @@ -69,22 +69,22 @@ bget(uint dev, uint sector) for(b = bufhead.next; b != &bufhead; b = b->next){ if((b->flags & (B_BUSY|B_VALID)) && b->dev == dev && b->sector == sector){ - if(b->flags & B_BUSY){ - sleep(buf, &buf_table_lock); - goto loop; + if(!(b->flags & B_BUSY)){ + b->flags |= B_BUSY; + release(&buf_table_lock); + return b; } - b->flags |= B_BUSY; - release(&buf_table_lock); - return b; + sleep(b, &buf_table_lock); + goto loop; } } // Allocate fresh block. for(b = bufhead.prev; b != &bufhead; b = b->prev){ if((b->flags & B_BUSY) == 0){ - b->flags = B_BUSY; b->dev = dev; b->sector = sector; + b->flags = B_BUSY; release(&buf_table_lock); return b; } @@ -131,7 +131,7 @@ brelse(struct buf *b) bufhead.next = b; b->flags &= ~B_BUSY; - wakeup(buf); + wakeup(b); release(&buf_table_lock); }