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
+18
View File
@@ -3,9 +3,27 @@
#include <printf.h>
#include <panic.h>
#include <mutex.h>
#include <arch/cpu.h>
void _putchar(char c);
void logging_sethook(void (*fun)(char));
void logging_init();
extern mutex_t printf_mutex;
#ifdef printf
#undef printf
#endif
#define printf(...) { \
if (_cpu()->thread) {\
MUTEX_ACQUIRE(&printf_mutex, false); \
} else { \
while (MUTEX_TRY(&printf_mutex) == false) CPU_PAUSE(); \
} \
printf_(__VA_ARGS__); \
MUTEX_RELEASE(&printf_mutex); \
}
#define __assert(x) \
if (!(x)){ \
+1
View File
@@ -1,6 +1,7 @@
#ifndef _SEMAPHORE_H
#define _SEMAPHORE_H
#include <stddef.h>
#include <stdbool.h>
#include <spinlock.h>
+1
View File
@@ -34,6 +34,7 @@ typedef struct cpu_t {
} cpu_t;
#define CPU_HALT() asm volatile("hlt")
#define CPU_PAUSE() asm volatile("pause")
static inline cpu_t *_cpu() {
return (cpu_t *)rdmsr(MSR_GSBASE);