summaryrefslogtreecommitdiff
path: root/sys/kern/printf.c
diff options
context:
space:
mode:
authorstefan <stefan@s00.xyz>2023-04-15 05:02:02 +0000
committerstefan <stefan@s00.xyz>2023-04-15 05:02:02 +0000
commitaf1ce4b2e637ceb418ea72d51c49a3eee276a938 (patch)
tree4d6a33644f8489e4f582f6e320bd6581b94fb642 /sys/kern/printf.c
parent8cceb31dcaf4641d43f324fa3301b37859ebfade (diff)
downloadsv-af1ce4b2e637ceb418ea72d51c49a3eee276a938.tar.gz
added multiprocessor support
Diffstat (limited to 'sys/kern/printf.c')
-rw-r--r--sys/kern/printf.c18
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;
}