#include "threads/synch.h"
static void vprintf_helper (char, void *);
-static void putchar_unlocked (uint8_t c);
+static void putchar_have_lock (uint8_t c);
/* The console lock.
Both the vga and serial layers do their own locking, so it's
intr_handler() - timer interrupt
intr_set_level()
serial_putc()
- putchar_unlocked()
+ putchar_have_lock()
putbuf()
sys_write() - one process writing to the console
syscall_handler()
void
console_init (void)
{
- lock_init (&console_lock, "console");
+ lock_init (&console_lock);
}
/* Prints console statistics. */
}
}
+/* Returns true if the current thread has the console lock,
+ false otherwise. */
+static bool
+console_locked_by_current_thread (void)
+{
+ return intr_context () || lock_held_by_current_thread (&console_lock);
+}
+
/* The standard vprintf() function,
which is like printf() but uses a va_list.
Writes its output to both vga display and serial port. */
{
acquire_console ();
while (*s != '\0')
- putchar_unlocked (*s++);
- putchar_unlocked ('\n');
+ putchar_have_lock (*s++);
+ putchar_have_lock ('\n');
release_console ();
return 0;
{
acquire_console ();
while (n-- > 0)
- putchar_unlocked (*buffer++);
+ putchar_have_lock (*buffer++);
release_console ();
}
putchar (int c)
{
acquire_console ();
- putchar_unlocked (c);
+ putchar_have_lock (c);
release_console ();
return c;
{
int *char_cnt = char_cnt_;
(*char_cnt)++;
- putchar_unlocked (c);
+ putchar_have_lock (c);
}
/* Writes C to the vga display and serial port.
The caller has already acquired the console lock if
appropriate. */
static void
-putchar_unlocked (uint8_t c)
+putchar_have_lock (uint8_t c)
{
+ ASSERT (console_locked_by_current_thread ());
write_cnt++;
serial_putc (c);
vga_putc (c);