diff --git a/src/utils/logger.c b/src/utils/logger.cpp similarity index 94% rename from src/utils/logger.c rename to src/utils/logger.cpp index c443edc..7d27ef9 100644 --- a/src/utils/logger.c +++ b/src/utils/logger.cpp @@ -1,3 +1,5 @@ +#include +#include #include #include #include @@ -13,6 +15,7 @@ static int32_t log_socket __attribute__((section(".data")))= -1; static struct sockaddr_in connect_addr __attribute__((section(".data"))); static volatile int32_t log_lock __attribute__((section(".data"))) = 0; +static std::recursive_mutex _lock; void log_init_() { int32_t broadcastEnable = 1; @@ -34,9 +37,7 @@ void log_print_(const char *str) { return; } - while(log_lock) - OSSleepTicks(OSMicrosecondsToTicks(1000)); - log_lock = 1; + _lock.lock(); int32_t len = strlen(str); int32_t ret; @@ -50,7 +51,7 @@ void log_print_(const char *str) { str += ret; } - log_lock = 0; + _lock.unlock(); } void OSFatal_printf(const char *format, ...) {