From 34295f461a416e40bb76e67c568a761222dc6913 Mon Sep 17 00:00:00 2001 From: rsc Date: Sun, 31 May 2009 05:12:21 +0000 Subject: group locks into structs they protect. few naming nits. --- console.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'console.c') diff --git a/console.c b/console.c index 8f89b49..6834c6a 100644 --- a/console.c +++ b/console.c @@ -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"); -- cgit v1.2.3