From af1ce4b2e637ceb418ea72d51c49a3eee276a938 Mon Sep 17 00:00:00 2001 From: stefan Date: Sat, 15 Apr 2023 05:02:02 +0000 Subject: added multiprocessor support --- sys/kern/printf.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'sys/kern/printf.c') 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 #include +#include #include #include 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; } -- cgit v1.2.3