From ee2533831d2d0d06fef9afc6cb26f7683fcb9724 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 9 May 2023 22:21:55 -0700 Subject: [PATCH] Util: Add THREAD_EXIT macro --- include/mgba-util/platform/3ds/threading.h | 1 + include/mgba-util/platform/posix/threading.h | 1 + include/mgba-util/platform/psp2/threading.h | 1 + include/mgba-util/platform/switch/threading.h | 1 + include/mgba-util/platform/windows/threading.h | 1 + src/core/rewind.c | 2 +- src/core/thread.c | 2 +- src/feature/gui/gui-runner.c | 1 + src/feature/thread-proxy.c | 2 +- src/platform/psp2/psp2-context.c | 2 +- src/platform/test/cinema-main.c | 1 + 11 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/mgba-util/platform/3ds/threading.h b/include/mgba-util/platform/3ds/threading.h index dfc03342d..8d5555317 100644 --- a/include/mgba-util/platform/3ds/threading.h +++ b/include/mgba-util/platform/3ds/threading.h @@ -12,6 +12,7 @@ #include #define THREAD_ENTRY void +#define THREAD_EXIT(RES) return typedef ThreadFunc ThreadEntry; typedef LightLock Mutex; diff --git a/include/mgba-util/platform/posix/threading.h b/include/mgba-util/platform/posix/threading.h index c8d42ed73..ad6e99690 100644 --- a/include/mgba-util/platform/posix/threading.h +++ b/include/mgba-util/platform/posix/threading.h @@ -20,6 +20,7 @@ CXX_GUARD_START #define THREAD_ENTRY void* typedef THREAD_ENTRY (*ThreadEntry)(void*); +#define THREAD_EXIT(RES) return RES typedef pthread_t Thread; typedef pthread_mutex_t Mutex; diff --git a/include/mgba-util/platform/psp2/threading.h b/include/mgba-util/platform/psp2/threading.h index ba4827229..4c084804c 100644 --- a/include/mgba-util/platform/psp2/threading.h +++ b/include/mgba-util/platform/psp2/threading.h @@ -17,6 +17,7 @@ typedef struct { } Condition; #define THREAD_ENTRY int typedef THREAD_ENTRY (*ThreadEntry)(void*); +#define THREAD_EXIT(RES) return RES static inline int MutexInit(Mutex* mutex) { Mutex id = sceKernelCreateMutex("mutex", 0, 0, 0); diff --git a/include/mgba-util/platform/switch/threading.h b/include/mgba-util/platform/switch/threading.h index 76f1ae8b5..52419fa28 100644 --- a/include/mgba-util/platform/switch/threading.h +++ b/include/mgba-util/platform/switch/threading.h @@ -11,6 +11,7 @@ #include #define THREAD_ENTRY void +#define THREAD_EXIT(RES) return typedef ThreadFunc ThreadEntry; typedef CondVar Condition; diff --git a/include/mgba-util/platform/windows/threading.h b/include/mgba-util/platform/windows/threading.h index 9be6fe53a..3f5de5a77 100644 --- a/include/mgba-util/platform/windows/threading.h +++ b/include/mgba-util/platform/windows/threading.h @@ -12,6 +12,7 @@ #include #define THREAD_ENTRY DWORD WINAPI typedef THREAD_ENTRY ThreadEntry(LPVOID); +#define THREAD_EXIT(RES) return RES typedef HANDLE Thread; typedef CRITICAL_SECTION Mutex; diff --git a/src/core/rewind.c b/src/core/rewind.c index 95f47ece4..95ac03df4 100644 --- a/src/core/rewind.c +++ b/src/core/rewind.c @@ -175,7 +175,7 @@ THREAD_ENTRY _rewindThread(void* context) { rewindContext->ready = false; } MutexUnlock(&rewindContext->mutex); - return 0; + THREAD_EXIT(0); } #endif diff --git a/src/core/thread.c b/src/core/thread.c index 510e45f98..4a0f17e36 100644 --- a/src/core/thread.c +++ b/src/core/thread.c @@ -450,7 +450,7 @@ static THREAD_ENTRY _mCoreThreadRun(void* context) { } logger->filter = NULL; - return 0; + THREAD_EXIT(0); } bool mCoreThreadStart(struct mCoreThread* threadContext) { diff --git a/src/feature/gui/gui-runner.c b/src/feature/gui/gui-runner.c index 3412edc45..ea9ac3bfa 100644 --- a/src/feature/gui/gui-runner.c +++ b/src/feature/gui/gui-runner.c @@ -794,5 +794,6 @@ THREAD_ENTRY mGUIAutosaveThread(void* context) { } } MutexUnlock(&autosave->mutex); + THREAD_EXIT(0); } #endif diff --git a/src/feature/thread-proxy.c b/src/feature/thread-proxy.c index d2956ed95..c3878e896 100644 --- a/src/feature/thread-proxy.c +++ b/src/feature/thread-proxy.c @@ -207,7 +207,7 @@ static THREAD_ENTRY _proxyThread(void* logger) { } } MutexUnlock(&proxyRenderer->mutex); - return 0; + THREAD_EXIT(0); } #endif diff --git a/src/platform/psp2/psp2-context.c b/src/platform/psp2/psp2-context.c index f547b44c8..7ab223039 100644 --- a/src/platform/psp2/psp2-context.c +++ b/src/platform/psp2/psp2-context.c @@ -129,7 +129,7 @@ static THREAD_ENTRY _audioThread(void* context) { sceAudioOutOutput(audioPort, buffer); } sceAudioOutReleasePort(audioPort); - return 0; + THREAD_EXIT(0); } static void _sampleRotation(struct mRotationSource* source) { diff --git a/src/platform/test/cinema-main.c b/src/platform/test/cinema-main.c index 28bb07693..716286c7c 100644 --- a/src/platform/test/cinema-main.c +++ b/src/platform/test/cinema-main.c @@ -1365,6 +1365,7 @@ static THREAD_ENTRY CInemaJob(void* context) { CIflush(&stream.err, stderr); StringListDeinit(&stream.err.lines); StringListDeinit(&stream.err.partial); + THREAD_EXIT(0); } void _log(struct mLogger* log, int category, enum mLogLevel level, const char* format, va_list args) {