]> Devi Nivas Git - cs3210-lab1.git/commitdiff
Only commit log to disk if something was written in to it.
authorAustin Clements <amdragon@mit.edu>
Mon, 15 Aug 2011 18:11:22 +0000 (14:11 -0400)
committerAustin Clements <amdragon@mit.edu>
Mon, 15 Aug 2011 18:12:35 +0000 (14:12 -0400)
Without this, every write to the console results in log writes.

log.c

diff --git a/log.c b/log.c
index e9a16c5b939661e86a9b6a90cf983d6631749f43..6b5c3296254462b358fd1065482f4d75dd541a59 100644 (file)
--- a/log.c
+++ b/log.c
@@ -143,11 +143,13 @@ begin_trans(void)
 void
 commit_trans(void)
 {
-  write_head();        // This causes all blocks till log.head to be commited
-  install_trans();     // Install all the transactions till head
-  log.lh.n = 0; 
-  write_head();        // Reclaim log
-
+  if (log.lh.n > 0) {
+    write_head();        // This causes all blocks till log.head to be commited
+    install_trans();     // Install all the transactions till head
+    log.lh.n = 0; 
+    write_head();        // Reclaim log
+  }
+  
   acquire(&log.lock);
   log.intrans = 0;
   wakeup(&log);