mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 20:58: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)){ \
|
||||
|
||||
Reference in New Issue
Block a user