summaryrefslogtreecommitdiff
path: root/log.c
diff options
context:
space:
mode:
authorFrans Kaashoek <[email protected]>2011-08-26 10:08:29 -0400
committerFrans Kaashoek <[email protected]>2011-08-26 10:08:29 -0400
commit3a5fa7ed9020eaf8ab843a16d26db7393b2ec072 (patch)
treebfa4ad4ae03d7d21796bacaa7eab8e3d3e4ab365 /log.c
parent8a9b6dbd4468f6312f1d07226a623879f970bd4b (diff)
downloadxv6-labs-3a5fa7ed9020eaf8ab843a16d26db7393b2ec072.tar.gz
xv6-labs-3a5fa7ed9020eaf8ab843a16d26db7393b2ec072.tar.bz2
xv6-labs-3a5fa7ed9020eaf8ab843a16d26db7393b2ec072.zip
Introduce and use sleeplocks instead of BUSY flags
Remove I_BUSY, B_BUSY, and intrans defs and usages One spinlock per buf to avoid ugly loop in bget fix race in filewrite (don't update f->off after releasing lock)
Diffstat (limited to 'log.c')
-rw-r--r--log.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/log.c b/log.c
index 6b5c329..d2dcba7 100644
--- a/log.c
+++ b/log.c
@@ -43,9 +43,9 @@ struct logheader {
struct {
struct spinlock lock;
+ struct sleeplock sleeplock;
int start;
int size;
- int intrans;
int dev;
struct logheader lh;
} log;
@@ -60,6 +60,7 @@ initlog(void)
struct superblock sb;
initlock(&log.lock, "log");
+ initsleeplock(&log.sleeplock);
readsb(ROOTDEV, &sb);
log.start = sb.size - sb.nlog;
log.size = sb.nlog;
@@ -133,10 +134,7 @@ void
begin_trans(void)
{
acquire(&log.lock);
- while (log.intrans) {
- sleep(&log, &log.lock);
- }
- log.intrans = 1;
+ acquire_sleeplock(&log.sleeplock, &log.lock);
release(&log.lock);
}
@@ -149,10 +147,8 @@ commit_trans(void)
log.lh.n = 0;
write_head(); // Reclaim log
}
-
acquire(&log.lock);
- log.intrans = 0;
- wakeup(&log);
+ release_sleeplock(&log.sleeplock);
release(&log.lock);
}
@@ -171,7 +167,7 @@ log_write(struct buf *b)
if (log.lh.n >= LOGSIZE || log.lh.n >= log.size - 1)
panic("too big a transaction");
- if (!log.intrans)
+ if (!acquired_sleeplock(&log.sleeplock))
panic("write outside of trans");
// cprintf("log_write: %d %d\n", b->sector, log.lh.n);