diff options
author | Frans Kaashoek <[email protected]> | 2019-07-30 08:54:43 -0400 |
---|---|---|
committer | Frans Kaashoek <[email protected]> | 2019-07-30 08:54:43 -0400 |
commit | f37a3e396454268074f48517e3773f099846d0e3 (patch) | |
tree | c0885b4e2009f26fe13046137008bfdfd69648c4 | |
parent | f1bb53c690051994f5a2c43ee900f9e335bd019c (diff) | |
download | xv6-labs-f37a3e396454268074f48517e3773f099846d0e3.tar.gz xv6-labs-f37a3e396454268074f48517e3773f099846d0e3.tar.bz2 xv6-labs-f37a3e396454268074f48517e3773f099846d0e3.zip |
Make pin/unpin explicit
-rw-r--r-- | kernel/bio.c | 16 | ||||
-rw-r--r-- | kernel/defs.h | 2 | ||||
-rw-r--r-- | kernel/log.c | 4 |
3 files changed, 20 insertions, 2 deletions
diff --git a/kernel/bio.c b/kernel/bio.c index 7455c06..a1074f2 100644 --- a/kernel/bio.c +++ b/kernel/bio.c @@ -133,3 +133,19 @@ brelse(struct buf *b) release(&bcache.lock); } + +void +bpin(struct buf *b) { + acquire(&bcache.lock); + b->refcnt++; + release(&bcache.lock); +} + +void +bunpin(struct buf *b) { + acquire(&bcache.lock); + b->refcnt--; + release(&bcache.lock); +} + + diff --git a/kernel/defs.h b/kernel/defs.h index 8421082..2689bed 100644 --- a/kernel/defs.h +++ b/kernel/defs.h @@ -14,6 +14,8 @@ void binit(void); struct buf* bread(uint, uint); void brelse(struct buf*); void bwrite(struct buf*); +void bpin(struct buf*); +void bunpin(struct buf*); // console.c void consoleinit(void); diff --git a/kernel/log.c b/kernel/log.c index 5aea267..59984db 100644 --- a/kernel/log.c +++ b/kernel/log.c @@ -77,7 +77,7 @@ install_trans(void) struct buf *dbuf = bread(log.dev, log.lh.block[tail]); // read dst memmove(dbuf->data, lbuf->data, BSIZE); // copy block to dst bwrite(dbuf); // write dst to disk - dbuf->refcnt--; // unpin buffer from cache + bunpin(dbuf); brelse(lbuf); brelse(dbuf); } @@ -229,7 +229,7 @@ log_write(struct buf *b) } log.lh.block[i] = b->blockno; if (i == log.lh.n) { // Add new block to log? - b->refcnt++; // Pin block in cache + bpin(b); log.lh.n++; } release(&log.lock); |