logging: make term and printf smp safe

This commit is contained in:
Matheus
2023-10-01 19:09:28 -03:00
parent 1bb152b446
commit ba16aa366f
7 changed files with 39 additions and 2 deletions
+8
View File
@@ -1,3 +1,7 @@
#include <mutex.h>
mutex_t printf_mutex;
static void nohook(char c) {
}
@@ -12,3 +16,7 @@ void _putchar(char c) {
void logging_sethook(void (*fun)(char)) {
hook = fun;
}
void logging_init() {
MUTEX_INIT(&printf_mutex);
}
+5
View File
@@ -20,9 +20,12 @@ static void *internalalloc(size_t n) {
}
static struct flanterm_context *term_ctx;
static mutex_t term_mutex;
void term_write(char *str, size_t count) {
MUTEX_ACQUIRE(&term_mutex, false);
flanterm_write(term_ctx, str, count);
MUTEX_RELEASE(&term_mutex);
}
void term_putchar(char c) {
@@ -55,4 +58,6 @@ void term_init() {
ys = term_ctx->rows;
fbxs = fb->width;
fbys = fb->height;
MUTEX_INIT(&term_mutex);
}