group locks into structs they protect.

few naming nits.
This commit is contained in:
rsc 2009-05-31 05:12:21 +00:00
parent 949e55902b
commit 34295f461a
10 changed files with 82 additions and 80 deletions

View file

@ -17,9 +17,12 @@
static ushort *crt = (ushort*)0xb8000; // CGA memory
static struct spinlock console_lock;
int panicked = 0;
volatile int use_console_lock = 0;
static struct {
struct spinlock lock;
int locking;
} cons;
static int panicked = 0;
static void
cgaputc(int c)
@ -99,9 +102,9 @@ cprintf(char *fmt, ...)
uint *argp;
char *s;
locking = use_console_lock;
locking = cons.locking;
if(locking)
acquire(&console_lock);
acquire(&cons.lock);
argp = (uint*)(void*)&fmt + 1;
state = 0;
@ -146,7 +149,7 @@ cprintf(char *fmt, ...)
}
if(locking)
release(&console_lock);
release(&cons.lock);
}
int
@ -155,10 +158,10 @@ consolewrite(struct inode *ip, char *buf, int n)
int i;
iunlock(ip);
acquire(&console_lock);
acquire(&cons.lock);
for(i = 0; i < n; i++)
consputc(buf[i] & 0xff);
release(&console_lock);
release(&cons.lock);
ilock(ip);
return n;
@ -255,12 +258,12 @@ consoleread(struct inode *ip, char *dst, int n)
void
consoleinit(void)
{
initlock(&console_lock, "console");
initlock(&input.lock, "console input");
initlock(&cons.lock, "console");
initlock(&input.lock, "input");
devsw[CONSOLE].write = consolewrite;
devsw[CONSOLE].read = consoleread;
use_console_lock = 1;
cons.locking = 1;
picenable(IRQ_KBD);
ioapicenable(IRQ_KBD, 0);
@ -273,7 +276,7 @@ panic(char *s)
uint pcs[10];
cli();
use_console_lock = 0;
cons.locking = 0;
cprintf("cpu%d: panic: ", cpu());
cprintf(s);
cprintf("\n");