17
17
18
18
static ushort * crt = (ushort * )0xb8000 ; // CGA memory
19
19
20
- static struct spinlock console_lock ;
21
- int panicked = 0 ;
22
- volatile int use_console_lock = 0 ;
20
+ static struct {
21
+ struct spinlock lock ;
22
+ int locking ;
23
+ } cons ;
24
+
25
+ static int panicked = 0 ;
23
26
24
27
static void
25
28
cgaputc (int c )
@@ -99,9 +102,9 @@ cprintf(char *fmt, ...)
99
102
uint * argp ;
100
103
char * s ;
101
104
102
- locking = use_console_lock ;
105
+ locking = cons . locking ;
103
106
if (locking )
104
- acquire (& console_lock );
107
+ acquire (& cons . lock );
105
108
106
109
argp = (uint * )(void * )& fmt + 1 ;
107
110
state = 0 ;
@@ -146,7 +149,7 @@ cprintf(char *fmt, ...)
146
149
}
147
150
148
151
if (locking )
149
- release (& console_lock );
152
+ release (& cons . lock );
150
153
}
151
154
152
155
int
@@ -155,10 +158,10 @@ consolewrite(struct inode *ip, char *buf, int n)
155
158
int i ;
156
159
157
160
iunlock (ip );
158
- acquire (& console_lock );
161
+ acquire (& cons . lock );
159
162
for (i = 0 ; i < n ; i ++ )
160
163
consputc (buf [i ] & 0xff );
161
- release (& console_lock );
164
+ release (& cons . lock );
162
165
ilock (ip );
163
166
164
167
return n ;
@@ -255,12 +258,12 @@ consoleread(struct inode *ip, char *dst, int n)
255
258
void
256
259
consoleinit (void )
257
260
{
258
- initlock (& console_lock , "console" );
259
- initlock (& input .lock , "console input" );
261
+ initlock (& cons . lock , "console" );
262
+ initlock (& input .lock , "input" );
260
263
261
264
devsw [CONSOLE ].write = consolewrite ;
262
265
devsw [CONSOLE ].read = consoleread ;
263
- use_console_lock = 1 ;
266
+ cons . locking = 1 ;
264
267
265
268
picenable (IRQ_KBD );
266
269
ioapicenable (IRQ_KBD , 0 );
@@ -273,7 +276,7 @@ panic(char *s)
273
276
uint pcs [10 ];
274
277
275
278
cli ();
276
- use_console_lock = 0 ;
279
+ cons . locking = 0 ;
277
280
cprintf ("cpu%d: panic: " , cpu ());
278
281
cprintf (s );
279
282
cprintf ("\n" );
0 commit comments