From f55d0851628b44ee8fb0a475bba14c27c32f53a0 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Tue, 22 Jul 2014 22:34:08 -0700 Subject: [PATCH] Change log handler API --- src/gba/gba-thread.c | 1 - src/gba/gba-thread.h | 5 ++++- src/gba/gba.c | 15 +++++++-------- src/gba/gba.h | 3 --- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/gba/gba-thread.c b/src/gba/gba-thread.c index 345a2c5bb..9f2eefceb 100644 --- a/src/gba/gba-thread.c +++ b/src/gba/gba-thread.c @@ -110,7 +110,6 @@ static THREAD_ENTRY _GBAThreadRun(void* context) { pthread_sigmask(SIG_SETMASK, &signals, 0); #endif - gba.logHandler = threadContext->logHandler; GBACreate(&gba); ARMSetComponents(&cpu, &gba.d, numComponents, components); ARMInit(&cpu); diff --git a/src/gba/gba-thread.h b/src/gba/gba-thread.h index 3e2c3007e..d8ea033b0 100644 --- a/src/gba/gba-thread.h +++ b/src/gba/gba-thread.h @@ -10,6 +10,7 @@ struct GBAThread; typedef void (*ThreadCallback)(struct GBAThread* threadContext); +typedef void (*LogHandler)(struct GBAThread*, enum GBALogLevel, const char* format, va_list args); enum ThreadState { THREAD_INITIALIZED = -1, @@ -55,6 +56,8 @@ struct GBAThread { struct VFile* patch; const char* fname; int activeKeys; + + // Run-time options int frameskip; float fpsTarget; size_t audioBuffers; @@ -66,7 +69,7 @@ struct GBAThread { Condition stateCond; enum ThreadState savedState; - GBALogHandler logHandler; + LogHandler logHandler; int logLevel; ThreadCallback startCallback; ThreadCallback cleanCallback; diff --git a/src/gba/gba.c b/src/gba/gba.c index 05f97a0d5..3d48df4a9 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -537,16 +537,15 @@ void GBAHalt(struct GBA* gba) { } static void _GBAVLog(struct GBA* gba, enum GBALogLevel level, const char* format, va_list args) { - if (!gba) { - struct GBAThread* threadContext = GBAThreadGetContext(); - if (threadContext) { + struct GBAThread* threadContext = GBAThreadGetContext(); + if (threadContext) { + if (!gba) { gba = threadContext->gba; } - } - - if (gba && gba->logHandler) { - gba->logHandler(gba, level, format, args); - return; + if (threadContext->logHandler) { + threadContext->logHandler(threadContext, level, format, args); + return; + } } if (gba && !(level & gba->logLevel) && level != GBA_LOG_FATAL) { diff --git a/src/gba/gba.h b/src/gba/gba.h index f4e20c340..3927d35bf 100644 --- a/src/gba/gba.h +++ b/src/gba/gba.h @@ -65,8 +65,6 @@ struct GBARotationSource; struct Patch; struct VFile; -typedef void (*GBALogHandler)(struct GBA*, enum GBALogLevel, const char* format, va_list args); - struct GBA { struct ARMComponent d; @@ -108,7 +106,6 @@ struct GBA { const char* activeFile; int logLevel; - GBALogHandler logHandler; }; struct GBACartridge {