From ec807c5b95ffb495b9004265a8361b0c8bbd64a4 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 31 Jul 2010 23:07:56 +0800 Subject: [PATCH] Makign debug functions thread safe --- Kernel/debug.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ Kernel/logging.c | 4 ++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Kernel/debug.c b/Kernel/debug.c index 66c20597..3a776102 100644 --- a/Kernel/debug.c +++ b/Kernel/debug.c @@ -13,6 +13,8 @@ #define GDB_SERIAL_PORT 0x2F8 #define DEBUG_MAX_LINE_LEN 256 +#define LOCK_DEBUG_OUTPUT 0 + // === IMPORTS === extern void Threads_Dump(void); extern void KernelPanic_SetMode(void); @@ -32,6 +34,9 @@ void Debug_Fmt(const char *format, va_list args); int gbGDB_SerialSetup = 0; int gbDebug_IsKPanic = 0; volatile int gbInPutChar = 0; +#if LOCK_DEBUG_OUTPUT +tSpinlock glDebug_Lock; +#endif // === CODE === int putDebugChar(char ch) @@ -163,11 +168,19 @@ void LogF(char *Fmt, ...) { va_list args; + #if LOCK_DEBUG_OUTPUT + VTIGHTLOCK(&glDebug_Lock); + #endif + va_start(args, Fmt); Debug_Fmt(Fmt, args); va_end(args); + + #if LOCK_DEBUG_OUTPUT + RELEASE(&glDebug_Lock); + #endif } /** * \fn void Debug(char *Msg, ...) @@ -176,6 +189,10 @@ void LogF(char *Fmt, ...) void Debug(char *Fmt, ...) { va_list args; + + #if LOCK_DEBUG_OUTPUT + LOCK(&glDebug_Lock); + #endif Debug_Puts(0, "Debug: "); va_start(args, Fmt); @@ -183,6 +200,9 @@ void Debug(char *Fmt, ...) va_end(args); Debug_PutCharDebug('\r'); Debug_PutCharDebug('\n'); + #if LOCK_DEBUG_OUTPUT + RELEASE(&glDebug_Lock); + #endif } /** * \fn void Log(char *Msg, ...) @@ -190,6 +210,10 @@ void Debug(char *Fmt, ...) void Log(char *Fmt, ...) { va_list args; + + #if LOCK_DEBUG_OUTPUT + LOCK(&glDebug_Lock); + #endif Debug_Puts(1, "Log: "); va_start(args, Fmt); @@ -197,21 +221,39 @@ void Log(char *Fmt, ...) va_end(args); Debug_Putchar('\r'); Debug_Putchar('\n'); + + #if LOCK_DEBUG_OUTPUT + RELEASE(&glDebug_Lock); + #endif } void Warning(char *Fmt, ...) { va_list args; + + #if LOCK_DEBUG_OUTPUT + LOCK(&glDebug_Lock); + #endif + Debug_Puts(1, "Warning: "); va_start(args, Fmt); Debug_Fmt(Fmt, args); va_end(args); Debug_Putchar('\r'); Debug_Putchar('\n'); + + #if LOCK_DEBUG_OUTPUT + RELEASE(&glDebug_Lock); + #endif } void Panic(char *Fmt, ...) { va_list args; + #if LOCK_DEBUG_OUTPUT + LOCK(&glDebug_Lock); + #endif + // And never release + Debug_KernelPanic(); Debug_Puts(1, "Panic: "); @@ -308,6 +350,10 @@ void Debug_Leave(char *FuncName, char RetType, ...) va_list args; int i = --gDebug_Level; + #if LOCK_DEBUG_OUTPUT + LOCK(&glDebug_Lock); + #endif + va_start(args, RetType); if( i == -1 ) { diff --git a/Kernel/logging.c b/Kernel/logging.c index 3d6351d8..baca0aa8 100644 --- a/Kernel/logging.c +++ b/Kernel/logging.c @@ -149,7 +149,7 @@ void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args) */ void Log_Int_PrintMessage(tLogEntry *Entry) { - //LOCK( &glLogOutput ); + LOCK( &glLogOutput ); LogF("%s%014lli%s [%+8s] %s\x1B[0m\r\n", csaLevelColours[Entry->Level], Entry->Time, @@ -157,7 +157,7 @@ void Log_Int_PrintMessage(tLogEntry *Entry) Entry->Ident, Entry->Data ); - //RELEASE( &glLogOutput ); + RELEASE( &glLogOutput ); } /** -- 2.20.1