diff options
Diffstat (limited to 'sys/kern/printf.c')
-rw-r--r-- | sys/kern/printf.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/sys/kern/printf.c b/sys/kern/printf.c index dfd0657..89add9e 100644 --- a/sys/kern/printf.c +++ b/sys/kern/printf.c @@ -1,10 +1,14 @@ #include <printf.h> #include <stdint.h> +#include <spinlock.h> #include <sbi.h> #include <stdarg.h> static char digits[] = "0123456789abcdef"; +struct spinlock mutex; +int locked = 0; + int puts(const char *str) { @@ -52,9 +56,13 @@ void printf(const char *fmt, ...) { va_list ap; - int i, c; + int i, c, _locked; char *s; + _locked = locked; + if (_locked) + acquire(&mutex); + va_start(ap, fmt); for (i = 0; (c = fmt[i] & 0xff) != 0; i++) { @@ -82,4 +90,12 @@ printf(const char *fmt, ...) break; } } + if (_locked) + release(&mutex); +} + +void printf_init(void) +{ + initlock(&mutex); + locked = 1; } |