fix (kernel): Made logger thread safe

This commit is contained in:
antifallobst 2023-02-12 10:37:19 +01:00
parent a57f2c25de
commit 79003bf2db
1 changed files with 10 additions and 2 deletions

View File

@ -15,8 +15,9 @@
#include "utils/logger.h"
#include "utils/io.h"
#include "utils/core.h"
string_t log_prefixes[LOG_ENUM_END] = {
string_t g_log_prefixes[LOG_ENUM_END] = {
"", // LOG_NONE
"[ Info ] ",
"[ Debug ] ",
@ -24,6 +25,8 @@ string_t log_prefixes[LOG_ENUM_END] = {
"[ Error ] ",
};
bool g_logger_blocked = false;
void log_send_string_to_port(string_t str) {
char* c = (char*)str;
while (*c != '\0') {
@ -33,6 +36,9 @@ void log_send_string_to_port(string_t str) {
}
void log(log_level_E log_level, string_t str, ...) {
CORE_HALT_WHILE(g_logger_blocked)
g_logger_blocked = true;
va_list args;
va_start(args, str);
@ -44,7 +50,9 @@ void log(log_level_E log_level, string_t str, ...) {
va_end(args);
log_send_string_to_port(log_prefixes[log_level]);
log_send_string_to_port(g_log_prefixes[log_level]);
log_send_string_to_port(formatted_string);
log_send_string_to_port("\n");
g_logger_blocked = false;
}