X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Tools%2Fnativelib%2Flogging.c;h=292b8a5254dc8f0c1875f12c208b416dca6a2ee9;hb=8a3c7218fb65c46c0876b7033b732188be91ae03;hp=c2d8a76a6140719b4e9f866cff83be27aec5a3aa;hpb=2287a74537b331627d12e2db728886d78ed37900;p=tpg%2Facess2.git diff --git a/Tools/nativelib/logging.c b/Tools/nativelib/logging.c index c2d8a76a..292b8a52 100644 --- a/Tools/nativelib/logging.c +++ b/Tools/nativelib/logging.c @@ -19,16 +19,23 @@ extern int Threads_GetTID(); #define LOGHDR(col,type) fprintf(stderr, "\e["col"m[%-8.8s]"type"%2i ", Ident, Threads_GetTID()) #define LOGTAIL() fprintf(stderr, "\e[0m\n") -#define PUTERR(col,type) {\ +#define LOG_LOCK_ACQUIRE() do{ \ if(!gbThreadInLog) SHORTLOCK(&glDebugLock); \ gbThreadInLog ++; \ +}while(0) +#define LOG_LOCK_RELEASE() do {\ + gbThreadInLog --; \ + if(!gbThreadInLog) SHORTREL(&glDebugLock); \ +} while(0) + +#define PUTERR(col,type) {\ + LOG_LOCK_ACQUIRE(); \ LOGHDR(col,type);\ va_list args; va_start(args, Message);\ vfprintf(stderr, Message, args);\ va_end(args);\ LOGTAIL();\ - gbThreadInLog --; \ - if(!gbThreadInLog) SHORTREL(&glDebugLock); \ + LOG_LOCK_RELEASE(); \ } // === GLOBALS === @@ -53,6 +60,11 @@ void Log_Log(const char *Ident, const char *Message, ...) void Log_Debug(const char *Ident, const char *Message, ...) PUTERR("37", "d") +void Panic(const char *Message, ...) { + const char *Ident = ""; + PUTERR("35", "k") + exit(-1); +} void Warning(const char *Message, ...) { const char *Ident = ""; PUTERR("33", "W") @@ -61,11 +73,16 @@ void Log(const char *Message, ...) { const char *Ident = ""; PUTERR("37", "L") } +void Debug(const char *Message, ...) { + const char *Ident = ""; + PUTERR("38", "D") +} void Debug_HexDump(const char *Prefix, const void *Data, size_t Length) { const uint8_t *data = Data; size_t ofs; + LOG_LOCK_ACQUIRE(); fprintf(stderr, "[HexDump ]d %s: %i bytes\n", Prefix, (int)Length); for( ofs = 0; ofs + 16 <= Length; ofs += 16 ) { @@ -86,14 +103,16 @@ void Debug_HexDump(const char *Prefix, const void *Data, size_t Length) fprintf(stderr, " %02x", data[ofs%16]); } fprintf(stderr, "\n"); + LOG_LOCK_RELEASE(); } int giDebug_TraceLevel = 0; void Debug_TraceEnter(const char *Function, const char *Format, ...) { - const char *Ident = "Trace"; - LOGHDR("37","T"); + LOG_LOCK_ACQUIRE(); + //const char *Ident = "Trace"; + //LOGHDR("37","T"); for( int i = 0; i < giDebug_TraceLevel; i ++ ) fprintf(stderr, " "); fprintf(stderr, "%s: (", Function); @@ -147,12 +166,14 @@ void Debug_TraceEnter(const char *Function, const char *Format, ...) fprintf(stderr, ")"); LOGTAIL(); giDebug_TraceLevel ++; + LOG_LOCK_RELEASE(); } void Debug_TraceLog(const char *Function, const char *Format, ...) { - const char *Ident = "Trace"; - LOGHDR("37","T"); + LOG_LOCK_ACQUIRE(); + //const char *Ident = "Trace"; + //LOGHDR("37","T"); for( int i = 0; i < giDebug_TraceLevel; i ++ ) fprintf(stderr, " "); @@ -165,6 +186,7 @@ void Debug_TraceLog(const char *Function, const char *Format, ...) va_end(args); LOGTAIL(); + LOG_LOCK_RELEASE(); } void Debug_TraceLeave(const char *Function, char Type, ...) @@ -173,8 +195,9 @@ void Debug_TraceLeave(const char *Function, char Type, ...) Log_Error("Debug", "Function %s called LEAVE without ENTER", Function); } - const char *Ident = "Trace"; - LOGHDR("37","T"); + LOG_LOCK_ACQUIRE(); + //const char *Ident = "Trace"; + //LOGHDR("37","T"); va_list args; va_start(args, Type); @@ -215,5 +238,6 @@ void Debug_TraceLeave(const char *Function, char Type, ...) va_end(args); LOGTAIL(); + LOG_LOCK_RELEASE(); }