diff --git a/console.c b/console.c index 46c867b..a699dd0 100644 --- 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;