diff options
author | Richard Braun <rbraun@sceen.net> | 2012-11-02 00:52:31 +0100 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2012-11-02 00:52:35 +0100 |
commit | 76a74e68486b03173f17d8e49d8aedc071969326 (patch) | |
tree | 2abc7b3b2abc79104565b2161871062d10e49413 /kern | |
parent | c5b665a6f71cc1cda5dbef9b9a32248fb12a7af0 (diff) |
kern/printk: protect the printk buffer with a spin lock
Diffstat (limited to 'kern')
-rw-r--r-- | kern/printk.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/kern/printk.c b/kern/printk.c index fc609c3..38d835c 100644 --- a/kern/printk.c +++ b/kern/printk.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Richard Braun. + * Copyright (c) 2010, 2012 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,8 +16,8 @@ */ #include <kern/printk.h> +#include <kern/spinlock.h> #include <lib/sprintf.h> -#include <machine/cpu.h> /* * Size of the static buffer. @@ -30,6 +30,7 @@ extern void console_write_byte(char c); static char printk_buffer[PRINTK_BUFSIZE]; +static struct spinlock printk_lock = SPINLOCK_INITIALIZER; int printk(const char *format, ...) @@ -51,14 +52,14 @@ vprintk(const char *format, va_list ap) int length; char *ptr; - flags = cpu_intr_save(); + flags = spinlock_lock(&printk_lock); length = vsnprintf(printk_buffer, sizeof(printk_buffer), format, ap); for (ptr = printk_buffer; *ptr != '\0'; ptr++) console_write_byte(*ptr); - cpu_intr_restore(flags); + spinlock_unlock(&printk_lock, flags); return length; } |