From 064516c0507baa0e3e474ec34ddef0ddac1ed1f0 Mon Sep 17 00:00:00 2001 From: terminx Date: Wed, 7 Aug 2019 22:43:57 +0000 Subject: [PATCH] Re-implement our mutex_lock() family of functions using SDL's atomic spinlocks git-svn-id: https://svn.eduke32.com/eduke32@7907 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/build/include/mutex.h | 6 +++--- source/build/src/mutex.cpp | 21 ++++++++------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/source/build/include/mutex.h b/source/build/include/mutex.h index ba9c51d32..040279f8e 100644 --- a/source/build/include/mutex.h +++ b/source/build/include/mutex.h @@ -19,12 +19,12 @@ typedef HANDLE mutex_t; #else /* PK: I don't like pointer typedefs, but SDL_CreateMutex() _returns_ one, * so we're out of luck with our interface. */ -typedef SDL_mutex* mutex_t; +typedef SDL_SpinLock mutex_t; #endif extern int32_t mutex_init(mutex_t *mutex); -extern int32_t mutex_lock(mutex_t *mutex); -extern int32_t mutex_unlock(mutex_t *mutex); +extern void mutex_lock(mutex_t *mutex); +extern void mutex_unlock(mutex_t *mutex); #ifdef __cplusplus diff --git a/source/build/src/mutex.cpp b/source/build/src/mutex.cpp index 5e22cad25..e88ae8bc2 100644 --- a/source/build/src/mutex.cpp +++ b/source/build/src/mutex.cpp @@ -13,30 +13,25 @@ int32_t mutex_init(mutex_t *mutex) *mutex = CreateMutex(0, FALSE, 0); return (*mutex == 0); #else - if (mutex) - { - *mutex = SDL_CreateMutex(); - if (*mutex != NULL) - return 0; - } - return -1; + *mutex = 0; + return 0; #endif } -int32_t mutex_lock(mutex_t *mutex) +void mutex_lock(mutex_t *mutex) { #ifdef RENDERTYPEWIN - return (WaitForSingleObject(*mutex, INFINITE) == WAIT_FAILED); + return WaitForSingleObject(*mutex, INFINITE); #else - return SDL_LockMutex(*mutex); + return SDL_AtomicLock(mutex); #endif } -int32_t mutex_unlock(mutex_t *mutex) +void mutex_unlock(mutex_t *mutex) { #ifdef RENDERTYPEWIN - return (ReleaseMutex(*mutex) == 0); + ReleaseMutex(*mutex); #else - return SDL_UnlockMutex(*mutex); + SDL_AtomicUnlock(mutex); #endif }