mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
logging: make term and printf smp safe
This commit is contained in:
@@ -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,6 +1,7 @@
|
||||
#ifndef _SEMAPHORE_H
|
||||
#define _SEMAPHORE_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <spinlock.h>
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user