Remove console input.lock

Use cons.lock for everything.  This eliminates the possibility that two CPUS
independently, simultaneously manipulate the CRTC in cgaputc.
This commit is contained in:
Nathaniel Wesley Filardo 2015-11-07 00:37:23 -05:00 committed by Frans Kaashoek
parent 02530a4859
commit 5906118897

View file

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