]> Devi Nivas Git - cs3210-lab0.git/commitdiff
Remove console input.lock
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Sat, 7 Nov 2015 05:37:23 +0000 (00:37 -0500)
committerFrans Kaashoek <kaashoek@mit.edu>
Sun, 15 Nov 2015 18:28:43 +0000 (13:28 -0500)
Use cons.lock for everything.  This eliminates the possibility that two CPUS
independently, simultaneously manipulate the CRTC in cgaputc.

console.c

index 46c867ba5880d2cf1eb4fb7664e99c50e2f2b087..a699dd061dc881fea882896683029c34a5789f2d 100644 (file)
--- a/console.c
+++ b/console.c
@@ -178,7 +178,6 @@ consputc(int c)
 
 #define INPUT_BUF 128
 struct {
-  struct spinlock lock;
   char buf[INPUT_BUF];
   uint r;  // Read index
   uint w;  // Write index
@@ -190,13 +189,13 @@ struct {
 void
 consoleintr(int (*getc)(void))
 {
-  int c;
+  int c, dopd = 0;
 
-  acquire(&input.lock);
+  acquire(&cons.lock);
   while((c = getc()) >= 0){
     switch(c){
     case C('P'):  // Process listing.
-      procdump();
+      dopd = 1;
       break;
     case C('U'):  // Kill line.
       while(input.e != input.w &&
@@ -224,7 +223,12 @@ consoleintr(int (*getc)(void))
       break;
     }
   }
-  release(&input.lock);
+  release(&cons.lock);
+  // Have to do this without the console lock held.
+  if(dopd) {
+    dopd = 0;
+    procdump();
+  }
 }
 
 int
@@ -235,15 +239,15 @@ consoleread(struct inode *ip, char *dst, int n)
 
   iunlock(ip);
   target = n;
-  acquire(&input.lock);
+  acquire(&cons.lock);
   while(n > 0){
     while(input.r == input.w){
       if(proc->killed){
-        release(&input.lock);
+        release(&cons.lock);
         ilock(ip);
         return -1;
       }
-      sleep(&input.r, &input.lock);
+      sleep(&input.r, &cons.lock);
     }
     c = input.buf[input.r++ % INPUT_BUF];
     if(c == C('D')){  // EOF
@@ -259,7 +263,7 @@ consoleread(struct inode *ip, char *dst, int n)
     if(c == '\n')
       break;
   }
-  release(&input.lock);
+  release(&cons.lock);
   ilock(ip);
 
   return target - n;
@@ -284,7 +288,6 @@ void
 consoleinit(void)
 {
   initlock(&cons.lock, "console");
-  initlock(&input.lock, "input");
 
   devsw[CONSOLE].write = consolewrite;
   devsw[CONSOLE].read = consoleread;