X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flib%2Fkernel%2Fconsole.c;h=865b13b2cd810b0805acead8ec9f4e3e038f609a;hb=615bf3b3d2a8573ed6fb9ddc0055745e163ac999;hp=14c707a63681129a66463677d6e7916d80199855;hpb=b567bc2c70ab0e4146fc208bd30224d76ea1cf5f;p=pintos-anon diff --git a/src/lib/kernel/console.c b/src/lib/kernel/console.c index 14c707a..865b13b 100644 --- a/src/lib/kernel/console.c +++ b/src/lib/kernel/console.c @@ -42,11 +42,21 @@ static struct lock console_lock; counter. */ static int console_lock_depth; +/* Number of characters written to console. */ +static int64_t write_cnt; + /* Initializes the console. */ void console_init (void) { - lock_init (&console_lock, "console"); + lock_init (&console_lock); +} + +/* Prints console statistics. */ +void +console_print_stats (void) +{ + printf ("Console: %lld characters output\n", write_cnt); } /* Acquires the console lock. */ @@ -75,6 +85,14 @@ release_console (void) } } +/* 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. */ @@ -140,6 +158,8 @@ vprintf_helper (char c, void *char_cnt_) static void putchar_unlocked (uint8_t c) { + ASSERT (console_locked_by_current_thread ()); + write_cnt++; serial_putc (c); vga_putc (c); }