From 61c0c009abd597bc7c3d9d99e4fc4cb26cfd3b67 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Apr 2023 20:49:54 -0700 Subject: [PATCH] Rename SDL semaphore and condition variable functions to match SDL 3.0 naming convention Fixes https://github.com/libsdl-org/SDL/issues/7642 --- build-scripts/SDL_migration.cocci | 55 ++++++++ docs/README-migration.md | 15 +++ docs/README-n3ds.md | 2 +- include/SDL3/SDL_mutex.h | 144 ++++++++++----------- include/SDL3/SDL_oldnames.h | 26 ++++ src/SDL_internal.h | 4 +- src/audio/coreaudio/SDL_coreaudio.m | 6 +- src/audio/jack/SDL_jackaudio.c | 12 +- src/audio/openslES/SDL_openslES.c | 10 +- src/audio/wasapi/SDL_wasapi_winrt.cpp | 6 +- src/core/android/SDL_android.c | 12 +- src/dynapi/SDL_dynapi.sym | 22 ++-- src/dynapi/SDL_dynapi_overrides.h | 22 ++-- src/dynapi/SDL_dynapi_procs.h | 22 ++-- src/hidapi/libusb/hid.c | 20 +-- src/joystick/hidapi/SDL_hidapi_rumble.c | 6 +- src/joystick/windows/SDL_windowsjoystick.c | 8 +- src/thread/SDL_thread.c | 20 +-- src/thread/generic/SDL_syscond.c | 40 +++--- src/thread/generic/SDL_syscond_c.h | 10 +- src/thread/generic/SDL_sysmutex.c | 6 +- src/thread/generic/SDL_sysrwlock.c | 8 +- src/thread/generic/SDL_syssem.c | 22 ++-- src/thread/n3ds/SDL_syscond.c | 14 +- src/thread/n3ds/SDL_syssem.c | 6 +- src/thread/ngage/SDL_syssem.cpp | 6 +- src/thread/ps2/SDL_syssem.c | 6 +- src/thread/psp/SDL_syscond.c | 30 ++--- src/thread/psp/SDL_syssem.c | 6 +- src/thread/pthread/SDL_syscond.c | 10 +- src/thread/pthread/SDL_syssem.c | 6 +- src/thread/stdcpp/SDL_syscond.cpp | 14 +- src/thread/vita/SDL_syscond.c | 30 ++--- src/thread/vita/SDL_syssem.c | 6 +- src/thread/windows/SDL_syscond_cv.c | 60 ++++----- src/thread/windows/SDL_syssem.c | 42 +++--- src/timer/SDL_timer.c | 6 +- src/video/android/SDL_androidevents.c | 12 +- src/video/cocoa/SDL_cocoaopengl.m | 10 +- src/video/psp/SDL_pspevents.c | 8 +- src/video/raspberry/SDL_rpiopengles.c | 2 +- src/video/raspberry/SDL_rpivideo.c | 8 +- src/video/winrt/SDL_winrtevents.cpp | 12 +- test/testatomic.c | 4 +- test/testsem.c | 24 ++-- 45 files changed, 458 insertions(+), 362 deletions(-) diff --git a/build-scripts/SDL_migration.cocci b/build-scripts/SDL_migration.cocci index 9bb8d8ba4..2f0469418 100644 --- a/build-scripts/SDL_migration.cocci +++ b/build-scripts/SDL_migration.cocci @@ -2538,3 +2538,58 @@ typedef SDL_atomic_t, SDL_AtomicInt; @@ - SDL_atomic_t + SDL_AtomicInt +@@ +@@ +- SDL_SemWait ++ SDL_WaitSemaphore + (...) +@@ +@@ +- SDL_SemTryWait ++ SDL_TryWaitSemaphore + (...) +@@ +@@ +- SDL_SemWaitTimeout ++ SDL_WaitSemaphoreTimeout + (...) +@@ +@@ +- SDL_SemPost ++ SDL_PostSemaphore + (...) +@@ +@@ +- SDL_SemValue ++ SDL_GetSemaphoreValue + (...) +@@ +@@ +- SDL_CreateCond ++ SDL_CreateCondition + (...) +@@ +@@ +- SDL_DestroyCond ++ SDL_DestroyCondition + (...) +@@ +@@ +- SDL_CondSignal ++ SDL_SignalCondition + (...) +@@ +@@ +- SDL_CondBroadcast ++ SDL_BroadcastCondition + (...) +@@ +@@ +- SDL_CondWait ++ SDL_WaitCondition + (...) +@@ +@@ +- SDL_CondWaitTimeout ++ SDL_WaitConditionTimeout + (...) diff --git a/docs/README-migration.md b/docs/README-migration.md index 736869ff7..25d762ffb 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -554,6 +554,21 @@ SDL_GetMouseState(), SDL_GetGlobalMouseState(), SDL_GetRelativeMouseState(), SDL The following functions have been renamed: * SDL_FreeCursor() => SDL_DestroyCursor() +## SDL_mutex.h + +The following functions have been renamed: +* SDL_CondBroadcast() => SDL_BroadcastCondition() +* SDL_CondSignal() => SDL_SignalCondition() +* SDL_CondWait() => SDL_WaitCondition() +* SDL_CondWaitTimeout() => SDL_WaitConditionTimeout() +* SDL_CreateCond() => SDL_CreateCondition() +* SDL_DestroyCond() => SDL_DestroyCondition() +* SDL_SemPost() => SDL_PostSemaphore() +* SDL_SemTryWait() => SDL_TryWaitSemaphore() +* SDL_SemValue() => SDL_GetSemaphoreValue() +* SDL_SemWait() => SDL_WaitSemaphore() +* SDL_SemWaitTimeout() => SDL_WaitSemaphoreTimeout() + ## SDL_pixels.h SDL_CalculateGammaRamp has been removed, because SDL_SetWindowGammaRamp has been removed as well due to poor support in modern operating systems (see [SDL_video.h](#sdl_videoh)). diff --git a/docs/README-n3ds.md b/docs/README-n3ds.md index 33ac08446..80da3802d 100644 --- a/docs/README-n3ds.md +++ b/docs/README-n3ds.md @@ -25,4 +25,4 @@ cmake --install build - SDL3_main should be used to ensure ROMFS is enabled - this is done with `#include ` in the source file that contains your main function. - By default, the extra L2 cache and higher clock speeds of the New 2/3DS lineup are enabled. If you wish to turn it off, use `osSetSpeedupEnable(false)` in your main function. - `SDL_GetBasePath` returns the romfs root instead of the executable's directory. -- The Nintendo 3DS uses a cooperative threading model on a single core, meaning a thread will never yield unless done manually through the `SDL_Delay` functions, or blocking waits (`SDL_LockMutex`, `SDL_SemWait`, `SDL_CondWait`, `SDL_WaitThread`). To avoid starving other threads, `SDL_SemTryWait` and `SDL_SemWaitTimeout` will yield if they fail to acquire the semaphore, see https://github.com/libsdl-org/SDL/pull/6776 for more information. +- The Nintendo 3DS uses a cooperative threading model on a single core, meaning a thread will never yield unless done manually through the `SDL_Delay` functions, or blocking waits (`SDL_LockMutex`, `SDL_WaitSemaphore`, `SDL_WaitCondition`, `SDL_WaitThread`). To avoid starving other threads, `SDL_TryWaitSemaphore` and `SDL_WaitSemaphoreTimeout` will yield if they fail to acquire the semaphore, see https://github.com/libsdl-org/SDL/pull/6776 for more information. diff --git a/include/SDL3/SDL_mutex.h b/include/SDL3/SDL_mutex.h index a25d8b839..67741abc3 100644 --- a/include/SDL3/SDL_mutex.h +++ b/include/SDL3/SDL_mutex.h @@ -481,11 +481,11 @@ typedef struct SDL_semaphore SDL_sem; * \since This function is available since SDL 3.0.0. * * \sa SDL_DestroySemaphore - * \sa SDL_SemPost - * \sa SDL_SemTryWait - * \sa SDL_SemValue - * \sa SDL_SemWait - * \sa SDL_SemWaitTimeout + * \sa SDL_PostSemaphore + * \sa SDL_TryWaitSemaphore + * \sa SDL_GetSemaphoreValue + * \sa SDL_WaitSemaphore + * \sa SDL_WaitSemaphoreTimeout */ extern DECLSPEC SDL_sem *SDLCALL SDL_CreateSemaphore(Uint32 initial_value); @@ -500,11 +500,11 @@ extern DECLSPEC SDL_sem *SDLCALL SDL_CreateSemaphore(Uint32 initial_value); * \since This function is available since SDL 3.0.0. * * \sa SDL_CreateSemaphore - * \sa SDL_SemPost - * \sa SDL_SemTryWait - * \sa SDL_SemValue - * \sa SDL_SemWait - * \sa SDL_SemWaitTimeout + * \sa SDL_PostSemaphore + * \sa SDL_TryWaitSemaphore + * \sa SDL_GetSemaphoreValue + * \sa SDL_WaitSemaphore + * \sa SDL_WaitSemaphoreTimeout */ extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem); @@ -516,7 +516,7 @@ extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem); * signal or error. If the call is successful it will atomically decrement the * semaphore value. * - * This function is the equivalent of calling SDL_SemWaitTimeout() with a time + * This function is the equivalent of calling SDL_WaitSemaphoreTimeout() with a time * length of `SDL_MUTEX_MAXWAIT`. * * \param sem the semaphore wait on @@ -527,13 +527,13 @@ extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem); * * \sa SDL_CreateSemaphore * \sa SDL_DestroySemaphore - * \sa SDL_SemPost - * \sa SDL_SemTryWait - * \sa SDL_SemValue - * \sa SDL_SemWait - * \sa SDL_SemWaitTimeout + * \sa SDL_PostSemaphore + * \sa SDL_TryWaitSemaphore + * \sa SDL_GetSemaphoreValue + * \sa SDL_WaitSemaphore + * \sa SDL_WaitSemaphoreTimeout */ -extern DECLSPEC int SDLCALL SDL_SemWait(SDL_sem *sem); +extern DECLSPEC int SDLCALL SDL_WaitSemaphore(SDL_sem *sem); /** * See if a semaphore has a positive value and decrement it if it does. @@ -552,12 +552,12 @@ extern DECLSPEC int SDLCALL SDL_SemWait(SDL_sem *sem); * * \sa SDL_CreateSemaphore * \sa SDL_DestroySemaphore - * \sa SDL_SemPost - * \sa SDL_SemValue - * \sa SDL_SemWait - * \sa SDL_SemWaitTimeout + * \sa SDL_PostSemaphore + * \sa SDL_GetSemaphoreValue + * \sa SDL_WaitSemaphore + * \sa SDL_WaitSemaphoreTimeout */ -extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem *sem); +extern DECLSPEC int SDLCALL SDL_TryWaitSemaphore(SDL_sem *sem); /** * Wait until a semaphore has a positive value and then decrements it. @@ -577,12 +577,12 @@ extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem *sem); * * \sa SDL_CreateSemaphore * \sa SDL_DestroySemaphore - * \sa SDL_SemPost - * \sa SDL_SemTryWait - * \sa SDL_SemValue - * \sa SDL_SemWait + * \sa SDL_PostSemaphore + * \sa SDL_TryWaitSemaphore + * \sa SDL_GetSemaphoreValue + * \sa SDL_WaitSemaphore */ -extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem *sem, Sint32 timeoutMS); +extern DECLSPEC int SDLCALL SDL_WaitSemaphoreTimeout(SDL_sem *sem, Sint32 timeoutMS); /** * Atomically increment a semaphore's value and wake waiting threads. @@ -595,12 +595,12 @@ extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem *sem, Sint32 timeoutMS); * * \sa SDL_CreateSemaphore * \sa SDL_DestroySemaphore - * \sa SDL_SemTryWait - * \sa SDL_SemValue - * \sa SDL_SemWait - * \sa SDL_SemWaitTimeout + * \sa SDL_TryWaitSemaphore + * \sa SDL_GetSemaphoreValue + * \sa SDL_WaitSemaphore + * \sa SDL_WaitSemaphoreTimeout */ -extern DECLSPEC int SDLCALL SDL_SemPost(SDL_sem *sem); +extern DECLSPEC int SDLCALL SDL_PostSemaphore(SDL_sem *sem); /** * Get the current value of a semaphore. @@ -612,7 +612,7 @@ extern DECLSPEC int SDLCALL SDL_SemPost(SDL_sem *sem); * * \sa SDL_CreateSemaphore */ -extern DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem *sem); +extern DECLSPEC Uint32 SDLCALL SDL_GetSemaphoreValue(SDL_sem *sem); /* @} *//* Semaphore functions */ @@ -634,13 +634,13 @@ typedef struct SDL_cond SDL_cond; * * \since This function is available since SDL 3.0.0. * - * \sa SDL_CondBroadcast - * \sa SDL_CondSignal - * \sa SDL_CondWait - * \sa SDL_CondWaitTimeout - * \sa SDL_DestroyCond + * \sa SDL_BroadcastCondition + * \sa SDL_SignalCondition + * \sa SDL_WaitCondition + * \sa SDL_WaitConditionTimeout + * \sa SDL_DestroyCondition */ -extern DECLSPEC SDL_cond *SDLCALL SDL_CreateCond(void); +extern DECLSPEC SDL_cond *SDLCALL SDL_CreateCondition(void); /** * Destroy a condition variable. @@ -649,13 +649,13 @@ extern DECLSPEC SDL_cond *SDLCALL SDL_CreateCond(void); * * \since This function is available since SDL 3.0.0. * - * \sa SDL_CondBroadcast - * \sa SDL_CondSignal - * \sa SDL_CondWait - * \sa SDL_CondWaitTimeout - * \sa SDL_CreateCond + * \sa SDL_BroadcastCondition + * \sa SDL_SignalCondition + * \sa SDL_WaitCondition + * \sa SDL_WaitConditionTimeout + * \sa SDL_CreateCondition */ -extern DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond *cond); +extern DECLSPEC void SDLCALL SDL_DestroyCondition(SDL_cond *cond); /** * Restart one of the threads that are waiting on the condition variable. @@ -666,13 +666,13 @@ extern DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond *cond); * * \since This function is available since SDL 3.0.0. * - * \sa SDL_CondBroadcast - * \sa SDL_CondWait - * \sa SDL_CondWaitTimeout - * \sa SDL_CreateCond - * \sa SDL_DestroyCond + * \sa SDL_BroadcastCondition + * \sa SDL_WaitCondition + * \sa SDL_WaitConditionTimeout + * \sa SDL_CreateCondition + * \sa SDL_DestroyCondition */ -extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond *cond); +extern DECLSPEC int SDLCALL SDL_SignalCondition(SDL_cond *cond); /** * Restart all threads that are waiting on the condition variable. @@ -683,19 +683,19 @@ extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond *cond); * * \since This function is available since SDL 3.0.0. * - * \sa SDL_CondSignal - * \sa SDL_CondWait - * \sa SDL_CondWaitTimeout - * \sa SDL_CreateCond - * \sa SDL_DestroyCond + * \sa SDL_SignalCondition + * \sa SDL_WaitCondition + * \sa SDL_WaitConditionTimeout + * \sa SDL_CreateCondition + * \sa SDL_DestroyCondition */ -extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond *cond); +extern DECLSPEC int SDLCALL SDL_BroadcastCondition(SDL_cond *cond); /** * Wait until a condition variable is signaled. * * This function unlocks the specified `mutex` and waits for another thread to - * call SDL_CondSignal() or SDL_CondBroadcast() on the condition variable + * call SDL_SignalCondition() or SDL_BroadcastCondition() on the condition variable * `cond`. Once the condition variable is signaled, the mutex is re-locked and * the function returns. * @@ -703,7 +703,7 @@ extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond *cond); * recursively (more than once) is not supported and leads to undefined * behavior. * - * This function is the equivalent of calling SDL_CondWaitTimeout() with a + * This function is the equivalent of calling SDL_WaitConditionTimeout() with a * time length of `SDL_MUTEX_MAXWAIT`. * * \param cond the condition variable to wait on @@ -713,19 +713,19 @@ extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond *cond); * * \since This function is available since SDL 3.0.0. * - * \sa SDL_CondBroadcast - * \sa SDL_CondSignal - * \sa SDL_CondWaitTimeout - * \sa SDL_CreateCond - * \sa SDL_DestroyCond + * \sa SDL_BroadcastCondition + * \sa SDL_SignalCondition + * \sa SDL_WaitConditionTimeout + * \sa SDL_CreateCondition + * \sa SDL_DestroyCondition */ -extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex); +extern DECLSPEC int SDLCALL SDL_WaitCondition(SDL_cond *cond, SDL_mutex *mutex); /** * Wait until a condition variable is signaled or a certain time has passed. * * This function unlocks the specified `mutex` and waits for another thread to - * call SDL_CondSignal() or SDL_CondBroadcast() on the condition variable + * call SDL_SignalCondition() or SDL_BroadcastCondition() on the condition variable * `cond`, or for the specified time to elapse. Once the condition variable is * signaled or the time elapsed, the mutex is re-locked and the function * returns. @@ -744,13 +744,13 @@ extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex); * * \since This function is available since SDL 3.0.0. * - * \sa SDL_CondBroadcast - * \sa SDL_CondSignal - * \sa SDL_CondWait - * \sa SDL_CreateCond - * \sa SDL_DestroyCond + * \sa SDL_BroadcastCondition + * \sa SDL_SignalCondition + * \sa SDL_WaitCondition + * \sa SDL_CreateCondition + * \sa SDL_DestroyCondition */ -extern DECLSPEC int SDLCALL SDL_CondWaitTimeout(SDL_cond *cond, +extern DECLSPEC int SDLCALL SDL_WaitConditionTimeout(SDL_cond *cond, SDL_mutex *mutex, Sint32 timeoutMS); /* @} *//* Condition variable functions */ diff --git a/include/SDL3/SDL_oldnames.h b/include/SDL3/SDL_oldnames.h index 48966e4d4..e9348eca9 100644 --- a/include/SDL3/SDL_oldnames.h +++ b/include/SDL3/SDL_oldnames.h @@ -314,6 +314,19 @@ /* ##SDL_mouse.h */ #define SDL_FreeCursor SDL_DestroyCursor +/* ##SDL_mutex.h */ +#define SDL_CondBroadcast SDL_BroadcastCondition +#define SDL_CondSignal SDL_SignalCondition +#define SDL_CondWait SDL_WaitCondition +#define SDL_CondWaitTimeout SDL_WaitConditionTimeout +#define SDL_CreateCond SDL_CreateCondition +#define SDL_DestroyCond SDL_DestroyCondition +#define SDL_SemPost SDL_PostSemaphore +#define SDL_SemTryWait SDL_TryWaitSemaphore +#define SDL_SemValue SDL_GetSemaphoreValue +#define SDL_SemWait SDL_WaitSemaphore +#define SDL_SemWaitTimeout SDL_WaitSemaphoreTimeout + /* ##SDL_pixels.h */ #define SDL_AllocFormat SDL_CreatePixelFormat #define SDL_AllocPalette SDL_CreatePalette @@ -711,6 +724,19 @@ /* ##SDL_mouse.h */ #define SDL_FreeCursor SDL_FreeCursor_renamed_SDL_DestroyCursor +/* ##SDL_mutex.h */ +#define SDL_CondBroadcast SDL_CondBroadcast_renamed_SDL_BroadcastCondition +#define SDL_CondSignal SDL_CondSignal_renamed_SDL_SignalCondition +#define SDL_CondWait SDL_CondWait_renamed_SDL_WaitCondition +#define SDL_CondWaitTimeout SDL_CondWaitTimeout_renamed_SDL_WaitConditionTimeout +#define SDL_CreateCond SDL_CreateCond_renamed_SDL_CreateCondition +#define SDL_DestroyCond SDL_DestroyCond_renamed_SDL_DestroyCondition +#define SDL_SemPost SDL_SemPost_renamed_SDL_PostSemaphore +#define SDL_SemTryWait SDL_SemTryWait_renamed_SDL_TryWaitSemaphore +#define SDL_SemValue SDL_SemValue_renamed_SDL_GetSemaphoreValue +#define SDL_SemWait SDL_SemWait_renamed_SDL_WaitSemaphore +#define SDL_SemWaitTimeout SDL_SemWaitTimeout_renamed_SDL_WaitSemaphoreTimeout + /* ##SDL_pixels.h */ #define SDL_AllocFormat SDL_AllocFormat_renamed_SDL_CreatePixelFormat #define SDL_AllocPalette SDL_AllocPalette_renamed_SDL_CreatePalette diff --git a/src/SDL_internal.h b/src/SDL_internal.h index 7dfcdc859..4cc6319cb 100644 --- a/src/SDL_internal.h +++ b/src/SDL_internal.h @@ -197,8 +197,8 @@ extern "C" { #endif -extern DECLSPEC int SDLCALL SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS); -extern DECLSPEC int SDLCALL SDL_CondWaitTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS); +extern DECLSPEC int SDLCALL SDL_WaitSemaphoreTimeoutNS(SDL_sem *sem, Sint64 timeoutNS); +extern DECLSPEC int SDLCALL SDL_WaitConditionTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS); extern DECLSPEC int SDLCALL SDL_WaitEventTimeoutNS(SDL_Event *event, Sint64 timeoutNS); /* Ends C function definitions when using C++ */ diff --git a/src/audio/coreaudio/SDL_coreaudio.m b/src/audio/coreaudio/SDL_coreaudio.m index 48573f96a..53ff5353c 100644 --- a/src/audio/coreaudio/SDL_coreaudio.m +++ b/src/audio/coreaudio/SDL_coreaudio.m @@ -950,14 +950,14 @@ static int audioqueue_thread(void *arg) rc = prepare_audioqueue(this); if (!rc) { this->hidden->thread_error = SDL_strdup(SDL_GetError()); - SDL_SemPost(this->hidden->ready_semaphore); + SDL_PostSemaphore(this->hidden->ready_semaphore); return 0; } SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH); /* init was successful, alert parent thread and start running... */ - SDL_SemPost(this->hidden->ready_semaphore); + SDL_PostSemaphore(this->hidden->ready_semaphore); while (!SDL_AtomicGet(&this->shutdown)) { CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.10, 1); @@ -1119,7 +1119,7 @@ static int COREAUDIO_OpenDevice(_THIS, const char *devname) return -1; } - SDL_SemWait(this->hidden->ready_semaphore); + SDL_WaitSemaphore(this->hidden->ready_semaphore); SDL_DestroySemaphore(this->hidden->ready_semaphore); this->hidden->ready_semaphore = NULL; diff --git a/src/audio/jack/SDL_jackaudio.c b/src/audio/jack/SDL_jackaudio.c index 19ed12822..43916bbe5 100644 --- a/src/audio/jack/SDL_jackaudio.c +++ b/src/audio/jack/SDL_jackaudio.c @@ -137,7 +137,7 @@ static void jackShutdownCallback(void *arg) /* JACK went away; device is lost. * { SDL_AudioDevice *this = (SDL_AudioDevice *)arg; SDL_OpenedAudioDeviceDisconnected(this); - SDL_SemPost(this->hidden->iosem); /* unblock the SDL thread. */ + SDL_PostSemaphore(this->hidden->iosem); /* unblock the SDL thread. */ } // !!! FIXME: implement and register these! @@ -169,7 +169,7 @@ static int jackProcessPlaybackCallback(jack_nframes_t nframes, void *arg) } } - SDL_SemPost(this->hidden->iosem); /* tell SDL thread we're done; refill the buffer. */ + SDL_PostSemaphore(this->hidden->iosem); /* tell SDL thread we're done; refill the buffer. */ return 0; } @@ -177,7 +177,7 @@ static int jackProcessPlaybackCallback(jack_nframes_t nframes, void *arg) static void JACK_WaitDevice(_THIS) { if (SDL_AtomicGet(&this->enabled)) { - if (SDL_SemWait(this->hidden->iosem) == -1) { + if (SDL_WaitSemaphore(this->hidden->iosem) == -1) { SDL_OpenedAudioDeviceDisconnected(this); } } @@ -210,7 +210,7 @@ static int jackProcessCaptureCallback(jack_nframes_t nframes, void *arg) } } - SDL_SemPost(this->hidden->iosem); /* tell SDL thread we're done; new buffer is ready! */ + SDL_PostSemaphore(this->hidden->iosem); /* tell SDL thread we're done; new buffer is ready! */ return 0; } @@ -219,7 +219,7 @@ static int JACK_CaptureFromDevice(_THIS, void *buffer, int buflen) SDL_assert(buflen == this->spec.size); /* we always fill a full buffer. */ /* Wait for JACK to fill the iobuffer */ - if (SDL_SemWait(this->hidden->iosem) == -1) { + if (SDL_WaitSemaphore(this->hidden->iosem) == -1) { return -1; } @@ -229,7 +229,7 @@ static int JACK_CaptureFromDevice(_THIS, void *buffer, int buflen) static void JACK_FlushCapture(_THIS) { - SDL_SemWait(this->hidden->iosem); + SDL_WaitSemaphore(this->hidden->iosem); } static void JACK_CloseDevice(_THIS) diff --git a/src/audio/openslES/SDL_openslES.c b/src/audio/openslES/SDL_openslES.c index 6966355f6..626df9420 100644 --- a/src/audio/openslES/SDL_openslES.c +++ b/src/audio/openslES/SDL_openslES.c @@ -186,7 +186,7 @@ static void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void *context) struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *)context; LOGV("SLES: Recording Callback"); - SDL_SemPost(audiodata->playsem); + SDL_PostSemaphore(audiodata->playsem); } static void openslES_DestroyPCMRecorder(_THIS) @@ -363,7 +363,7 @@ static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context) struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *)context; LOGV("SLES: Playback Callback"); - SDL_SemPost(audiodata->playsem); + SDL_PostSemaphore(audiodata->playsem); } static void openslES_DestroyPCMPlayer(_THIS) @@ -625,7 +625,7 @@ static void openslES_WaitDevice(_THIS) LOGV("openslES_WaitDevice()"); /* Wait for an audio chunk to finish */ - SDL_SemWait(audiodata->playsem); + SDL_WaitSemaphore(audiodata->playsem); } static void openslES_PlayDevice(_THIS) @@ -646,7 +646,7 @@ static void openslES_PlayDevice(_THIS) /* If Enqueue fails, callback won't be called. * Post the semphore, not to run out of buffer */ if (SL_RESULT_SUCCESS != result) { - SDL_SemPost(audiodata->playsem); + SDL_PostSemaphore(audiodata->playsem); } } @@ -676,7 +676,7 @@ static int openslES_CaptureFromDevice(_THIS, void *buffer, int buflen) SLresult result; /* Wait for new recorded data */ - SDL_SemWait(audiodata->playsem); + SDL_WaitSemaphore(audiodata->playsem); /* Copy it to the output buffer */ SDL_assert(buflen == this->spec.size); diff --git a/src/audio/wasapi/SDL_wasapi_winrt.cpp b/src/audio/wasapi/SDL_wasapi_winrt.cpp index 879ac9232..f60180c77 100644 --- a/src/audio/wasapi/SDL_wasapi_winrt.cpp +++ b/src/audio/wasapi/SDL_wasapi_winrt.cpp @@ -175,7 +175,7 @@ void SDL_WasapiDeviceEventHandler::OnDeviceUpdated(DeviceWatcher ^ sender, Devic void SDL_WasapiDeviceEventHandler::OnEnumerationCompleted(DeviceWatcher ^ sender, Platform::Object ^ args) { SDL_assert(sender == this->watcher); - SDL_SemPost(this->completed); + SDL_PostSemaphore(this->completed); } void SDL_WasapiDeviceEventHandler::OnDefaultRenderDeviceChanged(Platform::Object ^ sender, DefaultAudioRenderDeviceChangedEventArgs ^ args) @@ -225,8 +225,8 @@ void WASAPI_EnumerateEndpoints(void) // listening for updates. playback_device_event_handler = new SDL_WasapiDeviceEventHandler(SDL_FALSE); capture_device_event_handler = new SDL_WasapiDeviceEventHandler(SDL_TRUE); - SDL_SemWait(playback_device_event_handler->completed); - SDL_SemWait(capture_device_event_handler->completed); + SDL_WaitSemaphore(playback_device_event_handler->completed); + SDL_WaitSemaphore(capture_device_event_handler->completed); } struct SDL_WasapiActivationHandler : public RuntimeClass, FtmBase, IActivateAudioInterfaceCompletionHandler> diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index 064b0be36..937723a70 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -859,8 +859,8 @@ retry: SDL_LockMutex(Android_ActivityMutex); - pauseSignaled = SDL_SemValue(Android_PauseSem); - resumeSignaled = SDL_SemValue(Android_ResumeSem); + pauseSignaled = SDL_GetSemaphoreValue(Android_PauseSem); + resumeSignaled = SDL_GetSemaphoreValue(Android_ResumeSem); if (pauseSignaled > resumeSignaled) { SDL_UnlockMutex(Android_ActivityMutex); @@ -1225,12 +1225,12 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSendQuit)( SDL_SendQuit(); SDL_SendAppEvent(SDL_EVENT_TERMINATING); /* Robustness: clear any pending Pause */ - while (SDL_SemTryWait(Android_PauseSem) == 0) { + while (SDL_TryWaitSemaphore(Android_PauseSem) == 0) { /* empty */ } /* Resume the event loop so that the app can catch SDL_EVENT_QUIT which * should now be the top event in the event queue. */ - SDL_SemPost(Android_ResumeSem); + SDL_PostSemaphore(Android_ResumeSem); } /* Activity ends */ @@ -1272,7 +1272,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)( /* Signal the pause semaphore so the event loop knows to pause and (optionally) block itself. * Sometimes 2 pauses can be queued (eg pause/resume/pause), so it's always increased. */ - SDL_SemPost(Android_PauseSem); + SDL_PostSemaphore(Android_PauseSem); } /* Resume */ @@ -1285,7 +1285,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeResume)( * We can't restore the GL Context here because it needs to be done on the SDL main thread * and this function will be called from the Java thread instead. */ - SDL_SemPost(Android_ResumeSem); + SDL_PostSemaphore(Android_ResumeSem); } JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeFocusChanged)( diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym index 2a1dd322d..3870424b2 100644 --- a/src/dynapi/SDL_dynapi.sym +++ b/src/dynapi/SDL_dynapi.sym @@ -44,16 +44,16 @@ SDL3_0.0.0 { SDL_CloseJoystick; SDL_CloseSensor; SDL_ComposeCustomBlendMode; - SDL_CondBroadcast; - SDL_CondSignal; - SDL_CondWait; - SDL_CondWaitTimeout; + SDL_BroadcastCondition; + SDL_SignalCondition; + SDL_WaitCondition; + SDL_WaitConditionTimeout; SDL_ConvertPixels; SDL_ConvertSurface; SDL_ConvertSurfaceFormat; SDL_CreateAudioStream; SDL_CreateColorCursor; - SDL_CreateCond; + SDL_CreateCondition; SDL_CreateCursor; SDL_CreateMutex; SDL_CreatePalette; @@ -80,7 +80,7 @@ SDL3_0.0.0 { SDL_DelayNS; SDL_DequeueAudio; SDL_DestroyAudioStream; - SDL_DestroyCond; + SDL_DestroyCondition; SDL_DestroyMutex; SDL_DestroyPalette; SDL_DestroyPixelFormat; @@ -548,11 +548,11 @@ SDL3_0.0.0 { SDL_SaveBMP_RW; SDL_ScreenKeyboardShown; SDL_ScreenSaverEnabled; - SDL_SemPost; - SDL_SemTryWait; - SDL_SemValue; - SDL_SemWait; - SDL_SemWaitTimeout; + SDL_PostSemaphore; + SDL_TryWaitSemaphore; + SDL_GetSemaphoreValue; + SDL_WaitSemaphore; + SDL_WaitSemaphoreTimeout; SDL_SendGamepadEffect; SDL_SendJoystickEffect; SDL_SetAssertionHandler; diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index d9095bec7..5c78a8c00 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -68,16 +68,16 @@ #define SDL_CloseJoystick SDL_CloseJoystick_REAL #define SDL_CloseSensor SDL_CloseSensor_REAL #define SDL_ComposeCustomBlendMode SDL_ComposeCustomBlendMode_REAL -#define SDL_CondBroadcast SDL_CondBroadcast_REAL -#define SDL_CondSignal SDL_CondSignal_REAL -#define SDL_CondWait SDL_CondWait_REAL -#define SDL_CondWaitTimeout SDL_CondWaitTimeout_REAL +#define SDL_BroadcastCondition SDL_BroadcastCondition_REAL +#define SDL_SignalCondition SDL_SignalCondition_REAL +#define SDL_WaitCondition SDL_WaitCondition_REAL +#define SDL_WaitConditionTimeout SDL_WaitConditionTimeout_REAL #define SDL_ConvertPixels SDL_ConvertPixels_REAL #define SDL_ConvertSurface SDL_ConvertSurface_REAL #define SDL_ConvertSurfaceFormat SDL_ConvertSurfaceFormat_REAL #define SDL_CreateAudioStream SDL_CreateAudioStream_REAL #define SDL_CreateColorCursor SDL_CreateColorCursor_REAL -#define SDL_CreateCond SDL_CreateCond_REAL +#define SDL_CreateCondition SDL_CreateCondition_REAL #define SDL_CreateCursor SDL_CreateCursor_REAL #define SDL_CreateMutex SDL_CreateMutex_REAL #define SDL_CreatePalette SDL_CreatePalette_REAL @@ -104,7 +104,7 @@ #define SDL_DelayNS SDL_DelayNS_REAL #define SDL_DequeueAudio SDL_DequeueAudio_REAL #define SDL_DestroyAudioStream SDL_DestroyAudioStream_REAL -#define SDL_DestroyCond SDL_DestroyCond_REAL +#define SDL_DestroyCondition SDL_DestroyCondition_REAL #define SDL_DestroyMutex SDL_DestroyMutex_REAL #define SDL_DestroyPalette SDL_DestroyPalette_REAL #define SDL_DestroyPixelFormat SDL_DestroyPixelFormat_REAL @@ -572,11 +572,11 @@ #define SDL_SaveBMP_RW SDL_SaveBMP_RW_REAL #define SDL_ScreenKeyboardShown SDL_ScreenKeyboardShown_REAL #define SDL_ScreenSaverEnabled SDL_ScreenSaverEnabled_REAL -#define SDL_SemPost SDL_SemPost_REAL -#define SDL_SemTryWait SDL_SemTryWait_REAL -#define SDL_SemValue SDL_SemValue_REAL -#define SDL_SemWait SDL_SemWait_REAL -#define SDL_SemWaitTimeout SDL_SemWaitTimeout_REAL +#define SDL_PostSemaphore SDL_PostSemaphore_REAL +#define SDL_TryWaitSemaphore SDL_TryWaitSemaphore_REAL +#define SDL_GetSemaphoreValue SDL_GetSemaphoreValue_REAL +#define SDL_WaitSemaphore SDL_WaitSemaphore_REAL +#define SDL_WaitSemaphoreTimeout SDL_WaitSemaphoreTimeout_REAL #define SDL_SendGamepadEffect SDL_SendGamepadEffect_REAL #define SDL_SendJoystickEffect SDL_SendJoystickEffect_REAL #define SDL_SetAssertionHandler SDL_SetAssertionHandler_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index bd97581e1..fae09a670 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -149,16 +149,16 @@ SDL_DYNAPI_PROC(void,SDL_CloseGamepad,(SDL_Gamepad *a),(a),) SDL_DYNAPI_PROC(void,SDL_CloseJoystick,(SDL_Joystick *a),(a),) SDL_DYNAPI_PROC(void,SDL_CloseSensor,(SDL_Sensor *a),(a),) SDL_DYNAPI_PROC(SDL_BlendMode,SDL_ComposeCustomBlendMode,(SDL_BlendFactor a, SDL_BlendFactor b, SDL_BlendOperation c, SDL_BlendFactor d, SDL_BlendFactor e, SDL_BlendOperation f),(a,b,c,d,e,f),return) -SDL_DYNAPI_PROC(int,SDL_CondBroadcast,(SDL_cond *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_CondSignal,(SDL_cond *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_CondWait,(SDL_cond *a, SDL_mutex *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_CondWaitTimeout,(SDL_cond *a, SDL_mutex *b, Sint32 c),(a,b,c),return) +SDL_DYNAPI_PROC(int,SDL_BroadcastCondition,(SDL_cond *a),(a),return) +SDL_DYNAPI_PROC(int,SDL_SignalCondition,(SDL_cond *a),(a),return) +SDL_DYNAPI_PROC(int,SDL_WaitCondition,(SDL_cond *a, SDL_mutex *b),(a,b),return) +SDL_DYNAPI_PROC(int,SDL_WaitConditionTimeout,(SDL_cond *a, SDL_mutex *b, Sint32 c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_ConvertPixels,(int a, int b, Uint32 c, const void *d, int e, Uint32 f, void *g, int h),(a,b,c,d,e,f,g,h),return) SDL_DYNAPI_PROC(SDL_Surface*,SDL_ConvertSurface,(SDL_Surface *a, const SDL_PixelFormat *b),(a,b),return) SDL_DYNAPI_PROC(SDL_Surface*,SDL_ConvertSurfaceFormat,(SDL_Surface *a, Uint32 b),(a,b),return) SDL_DYNAPI_PROC(SDL_AudioStream*,SDL_CreateAudioStream,(SDL_AudioFormat a, int b, int c, SDL_AudioFormat d, int e, int f),(a,b,c,d,e,f),return) SDL_DYNAPI_PROC(SDL_Cursor*,SDL_CreateColorCursor,(SDL_Surface *a, int b, int c),(a,b,c),return) -SDL_DYNAPI_PROC(SDL_cond*,SDL_CreateCond,(void),(),return) +SDL_DYNAPI_PROC(SDL_cond*,SDL_CreateCondition,(void),(),return) SDL_DYNAPI_PROC(SDL_Cursor*,SDL_CreateCursor,(const Uint8 *a, const Uint8 *b, int c, int d, int e, int f),(a,b,c,d,e,f),return) SDL_DYNAPI_PROC(SDL_mutex*,SDL_CreateMutex,(void),(),return) SDL_DYNAPI_PROC(SDL_Palette*,SDL_CreatePalette,(int a),(a),return) @@ -182,7 +182,7 @@ SDL_DYNAPI_PROC(void,SDL_Delay,(Uint32 a),(a),) SDL_DYNAPI_PROC(void,SDL_DelayNS,(Uint64 a),(a),) SDL_DYNAPI_PROC(Uint32,SDL_DequeueAudio,(SDL_AudioDeviceID a, void *b, Uint32 c),(a,b,c),return) SDL_DYNAPI_PROC(void,SDL_DestroyAudioStream,(SDL_AudioStream *a),(a),) -SDL_DYNAPI_PROC(void,SDL_DestroyCond,(SDL_cond *a),(a),) +SDL_DYNAPI_PROC(void,SDL_DestroyCondition,(SDL_cond *a),(a),) SDL_DYNAPI_PROC(void,SDL_DestroyMutex,(SDL_mutex *a),(a),) SDL_DYNAPI_PROC(void,SDL_DestroyPalette,(SDL_Palette *a),(a),) SDL_DYNAPI_PROC(void,SDL_DestroyPixelFormat,(SDL_PixelFormat *a),(a),) @@ -628,11 +628,11 @@ SDL_DYNAPI_PROC(size_t,SDL_SIMDGetAlignment,(void),(),return) SDL_DYNAPI_PROC(int,SDL_SaveBMP_RW,(SDL_Surface *a, SDL_RWops *b, int c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_bool,SDL_ScreenKeyboardShown,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_ScreenSaverEnabled,(void),(),return) -SDL_DYNAPI_PROC(int,SDL_SemPost,(SDL_sem *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_SemTryWait,(SDL_sem *a),(a),return) -SDL_DYNAPI_PROC(Uint32,SDL_SemValue,(SDL_sem *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_SemWait,(SDL_sem *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_SemWaitTimeout,(SDL_sem *a, Sint32 b),(a,b),return) +SDL_DYNAPI_PROC(int,SDL_PostSemaphore,(SDL_sem *a),(a),return) +SDL_DYNAPI_PROC(int,SDL_TryWaitSemaphore,(SDL_sem *a),(a),return) +SDL_DYNAPI_PROC(Uint32,SDL_GetSemaphoreValue,(SDL_sem *a),(a),return) +SDL_DYNAPI_PROC(int,SDL_WaitSemaphore,(SDL_sem *a),(a),return) +SDL_DYNAPI_PROC(int,SDL_WaitSemaphoreTimeout,(SDL_sem *a, Sint32 b),(a,b),return) SDL_DYNAPI_PROC(int,SDL_SendGamepadEffect,(SDL_Gamepad *a, const void *b, int c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_SendJoystickEffect,(SDL_Joystick *a, const void *b, int c),(a,b,c),return) SDL_DYNAPI_PROC(void,SDL_SetAssertionHandler,(SDL_AssertionHandler a, void *b),(a,b),) diff --git a/src/hidapi/libusb/hid.c b/src/hidapi/libusb/hid.c index 07c6fd390..31359dc16 100644 --- a/src/hidapi/libusb/hid.c +++ b/src/hidapi/libusb/hid.c @@ -108,7 +108,7 @@ static int SDL_CreateThreadBarrier(SDL_ThreadBarrier *barrier, Uint32 count) if (barrier->mutex == NULL) { return -1; /* Error set by CreateMutex */ } - barrier->cond = SDL_CreateCond(); + barrier->cond = SDL_CreateCondition(); if (barrier->cond == NULL) { return -1; /* Error set by CreateCond */ } @@ -121,7 +121,7 @@ static int SDL_CreateThreadBarrier(SDL_ThreadBarrier *barrier, Uint32 count) static void SDL_DestroyThreadBarrier(SDL_ThreadBarrier *barrier) { - SDL_DestroyCond(barrier->cond); + SDL_DestroyCondition(barrier->cond); SDL_DestroyMutex(barrier->mutex); } @@ -131,11 +131,11 @@ static int SDL_WaitThreadBarrier(SDL_ThreadBarrier *barrier) barrier->count += 1; if (barrier->count >= barrier->trip_count) { barrier->count = 0; - SDL_CondBroadcast(barrier->cond); + SDL_BroadcastCondition(barrier->cond); SDL_UnlockMutex(barrier->mutex); return 1; } - SDL_CondWait(barrier->cond, barrier->mutex); + SDL_WaitCondition(barrier->cond, barrier->mutex); SDL_UnlockMutex(barrier->mutex); return 0; } @@ -219,7 +219,7 @@ static hid_device *new_hid_device(void) dev->blocking = 1; dev->mutex = SDL_CreateMutex(); - dev->condition = SDL_CreateCond(); + dev->condition = SDL_CreateCondition(); SDL_CreateThreadBarrier(&dev->barrier, 2); return dev; @@ -229,7 +229,7 @@ static void free_hid_device(hid_device *dev) { /* Clean up the thread objects */ SDL_DestroyThreadBarrier(&dev->barrier); - SDL_DestroyCond(dev->condition); + SDL_DestroyCondition(dev->condition); SDL_DestroyMutex(dev->mutex); /* Free the device itself */ @@ -1011,7 +1011,7 @@ static void LIBUSB_CALL read_callback(struct libusb_transfer *transfer) if (dev->input_reports == NULL) { /* The list is empty. Put it at the root. */ dev->input_reports = rpt; - SDL_CondSignal(dev->condition); + SDL_SignalCondition(dev->condition); } else { /* Find the end of the list and attach. */ @@ -1122,7 +1122,7 @@ static int SDLCALL read_thread(void *param) the condition actually will go to sleep before the condition is signaled. */ SDL_LockMutex(dev->mutex); - SDL_CondBroadcast(dev->condition); + SDL_BroadcastCondition(dev->condition); SDL_UnlockMutex(dev->mutex); /* The dev->transfer->buffer and dev->transfer objects are cleaned up @@ -1466,7 +1466,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t if (milliseconds == -1) { /* Blocking */ while (!dev->input_reports && !dev->shutdown_thread) { - SDL_CondWait(dev->condition, dev->mutex); + SDL_WaitCondition(dev->condition, dev->mutex); } if (dev->input_reports) { bytes_read = return_data(dev, data, length); @@ -1477,7 +1477,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t int res; while (!dev->input_reports && !dev->shutdown_thread) { - res = SDL_CondWaitTimeout(dev->condition, dev->mutex, milliseconds); + res = SDL_WaitConditionTimeout(dev->condition, dev->mutex, milliseconds); if (res == 0) { if (dev->input_reports) { bytes_read = return_data(dev, data, length); diff --git a/src/joystick/hidapi/SDL_hidapi_rumble.c b/src/joystick/hidapi/SDL_hidapi_rumble.c index fc01a029a..3b88044b1 100644 --- a/src/joystick/hidapi/SDL_hidapi_rumble.c +++ b/src/joystick/hidapi/SDL_hidapi_rumble.c @@ -64,7 +64,7 @@ static int SDLCALL SDL_HIDAPI_RumbleThread(void *data) while (SDL_AtomicGet(&ctx->running)) { SDL_HIDAPI_RumbleRequest *request = NULL; - SDL_SemWait(ctx->request_sem); + SDL_WaitSemaphore(ctx->request_sem); SDL_LockMutex(SDL_HIDAPI_rumble_lock); request = ctx->requests_tail; @@ -107,7 +107,7 @@ static void SDL_HIDAPI_StopRumbleThread(SDL_HIDAPI_RumbleContext *ctx) if (ctx->thread) { int result; - SDL_SemPost(ctx->request_sem); + SDL_PostSemaphore(ctx->request_sem); SDL_WaitThread(ctx->thread, &result); ctx->thread = NULL; } @@ -236,7 +236,7 @@ int SDL_HIDAPI_SendRumbleWithCallbackAndUnlock(SDL_HIDAPI_Device *device, const /* Make sure we unlock before posting the semaphore so the rumble thread can run immediately */ SDL_HIDAPI_UnlockRumble(); - SDL_SemPost(ctx->request_sem); + SDL_PostSemaphore(ctx->request_sem); return size; } diff --git a/src/joystick/windows/SDL_windowsjoystick.c b/src/joystick/windows/SDL_windowsjoystick.c index 994cb24b9..6db79f9d4 100644 --- a/src/joystick/windows/SDL_windowsjoystick.c +++ b/src/joystick/windows/SDL_windowsjoystick.c @@ -365,7 +365,7 @@ static int SDLCALL SDL_JoystickThread(void *_data) #endif #ifdef SDL_JOYSTICK_XINPUT /* WM_DEVICECHANGE not working, poll for new XINPUT controllers */ - SDL_CondWaitTimeout(s_condJoystickThread, s_mutexJoyStickEnum, 1000); + SDL_WaitConditionTimeout(s_condJoystickThread, s_mutexJoyStickEnum, 1000); if (SDL_XINPUT_Enabled() && XINPUTGETCAPABILITIES) { /* scan for any change in XInput devices */ Uint8 userId; @@ -403,7 +403,7 @@ static int SDL_StartJoystickThread(void) return -1; } - s_condJoystickThread = SDL_CreateCond(); + s_condJoystickThread = SDL_CreateCondition(); if (s_condJoystickThread == NULL) { return -1; } @@ -424,7 +424,7 @@ static void SDL_StopJoystickThread(void) SDL_LockMutex(s_mutexJoyStickEnum); s_bJoystickThreadQuit = SDL_TRUE; - SDL_CondBroadcast(s_condJoystickThread); /* signal the joystick thread to quit */ + SDL_BroadcastCondition(s_condJoystickThread); /* signal the joystick thread to quit */ SDL_UnlockMutex(s_mutexJoyStickEnum); PostThreadMessage(SDL_GetThreadID(s_joystickThread), WM_QUIT, 0, 0); @@ -434,7 +434,7 @@ static void SDL_StopJoystickThread(void) SDL_WaitThread(s_joystickThread, NULL); /* wait for it to bugger off */ SDL_LockJoysticks(); - SDL_DestroyCond(s_condJoystickThread); + SDL_DestroyCondition(s_condJoystickThread); s_condJoystickThread = NULL; SDL_DestroyMutex(s_mutexJoyStickEnum); diff --git a/src/thread/SDL_thread.c b/src/thread/SDL_thread.c index 9bbecd82c..b95ee1718 100644 --- a/src/thread/SDL_thread.c +++ b/src/thread/SDL_thread.c @@ -481,17 +481,17 @@ void SDL_DetachThread(SDL_Thread *thread) } } -int SDL_SemWait(SDL_sem *sem) +int SDL_WaitSemaphore(SDL_sem *sem) { - return SDL_SemWaitTimeoutNS(sem, SDL_MUTEX_MAXWAIT); + return SDL_WaitSemaphoreTimeoutNS(sem, SDL_MUTEX_MAXWAIT); } -int SDL_SemTryWait(SDL_sem *sem) +int SDL_TryWaitSemaphore(SDL_sem *sem) { - return SDL_SemWaitTimeoutNS(sem, 0); + return SDL_WaitSemaphoreTimeoutNS(sem, 0); } -int SDL_SemWaitTimeout(SDL_sem *sem, Sint32 timeoutMS) +int SDL_WaitSemaphoreTimeout(SDL_sem *sem, Sint32 timeoutMS) { Sint64 timeoutNS; @@ -500,15 +500,15 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Sint32 timeoutMS) } else { timeoutNS = -1; } - return SDL_SemWaitTimeoutNS(sem, timeoutNS); + return SDL_WaitSemaphoreTimeoutNS(sem, timeoutNS); } -int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex) +int SDL_WaitCondition(SDL_cond *cond, SDL_mutex *mutex) { - return SDL_CondWaitTimeoutNS(cond, mutex, SDL_MUTEX_MAXWAIT); + return SDL_WaitConditionTimeoutNS(cond, mutex, SDL_MUTEX_MAXWAIT); } -int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Sint32 timeoutMS) +int SDL_WaitConditionTimeout(SDL_cond *cond, SDL_mutex *mutex, Sint32 timeoutMS) { Sint64 timeoutNS; @@ -517,5 +517,5 @@ int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Sint32 timeoutMS) } else { timeoutNS = -1; } - return SDL_CondWaitTimeoutNS(cond, mutex, timeoutNS); + return SDL_WaitConditionTimeoutNS(cond, mutex, timeoutNS); } diff --git a/src/thread/generic/SDL_syscond.c b/src/thread/generic/SDL_syscond.c index 1e1eb1690..e5868d5b9 100644 --- a/src/thread/generic/SDL_syscond.c +++ b/src/thread/generic/SDL_syscond.c @@ -33,11 +33,11 @@ * suffixed */ #ifndef SDL_THREAD_GENERIC_COND_SUFFIX -#define SDL_CreateCond_generic SDL_CreateCond -#define SDL_DestroyCond_generic SDL_DestroyCond -#define SDL_CondSignal_generic SDL_CondSignal -#define SDL_CondBroadcast_generic SDL_CondBroadcast -#define SDL_CondWaitTimeoutNS_generic SDL_CondWaitTimeoutNS +#define SDL_CreateCondition_generic SDL_CreateCondition +#define SDL_DestroyCondition_generic SDL_DestroyCondition +#define SDL_SignalCondition_generic SDL_SignalCondition +#define SDL_BroadcastCondition_generic SDL_BroadcastCondition +#define SDL_WaitConditionTimeoutNS_generic SDL_WaitConditionTimeoutNS #endif typedef struct SDL_cond_generic @@ -51,7 +51,7 @@ typedef struct SDL_cond_generic /* Create a condition variable */ SDL_cond * -SDL_CreateCond_generic(void) +SDL_CreateCondition_generic(void) { SDL_cond_generic *cond; @@ -62,7 +62,7 @@ SDL_CreateCond_generic(void) cond->wait_done = SDL_CreateSemaphore(0); cond->waiting = cond->signals = 0; if (!cond->lock || !cond->wait_sem || !cond->wait_done) { - SDL_DestroyCond_generic((SDL_cond *)cond); + SDL_DestroyCondition_generic((SDL_cond *)cond); cond = NULL; } } else { @@ -72,7 +72,7 @@ SDL_CreateCond_generic(void) } /* Destroy a condition variable */ -void SDL_DestroyCond_generic(SDL_cond *_cond) +void SDL_DestroyCondition_generic(SDL_cond *_cond) { SDL_cond_generic *cond = (SDL_cond_generic *)_cond; if (cond) { @@ -90,7 +90,7 @@ void SDL_DestroyCond_generic(SDL_cond *_cond) } /* Restart one of the threads that are waiting on the condition variable */ -int SDL_CondSignal_generic(SDL_cond *_cond) +int SDL_SignalCondition_generic(SDL_cond *_cond) { SDL_cond_generic *cond = (SDL_cond_generic *)_cond; if (cond == NULL) { @@ -103,9 +103,9 @@ int SDL_CondSignal_generic(SDL_cond *_cond) SDL_LockMutex(cond->lock); if (cond->waiting > cond->signals) { ++cond->signals; - SDL_SemPost(cond->wait_sem); + SDL_PostSemaphore(cond->wait_sem); SDL_UnlockMutex(cond->lock); - SDL_SemWait(cond->wait_done); + SDL_WaitSemaphore(cond->wait_done); } else { SDL_UnlockMutex(cond->lock); } @@ -114,7 +114,7 @@ int SDL_CondSignal_generic(SDL_cond *_cond) } /* Restart all threads that are waiting on the condition variable */ -int SDL_CondBroadcast_generic(SDL_cond *_cond) +int SDL_BroadcastCondition_generic(SDL_cond *_cond) { SDL_cond_generic *cond = (SDL_cond_generic *)_cond; if (cond == NULL) { @@ -131,14 +131,14 @@ int SDL_CondBroadcast_generic(SDL_cond *_cond) num_waiting = (cond->waiting - cond->signals); cond->signals = cond->waiting; for (i = 0; i < num_waiting; ++i) { - SDL_SemPost(cond->wait_sem); + SDL_PostSemaphore(cond->wait_sem); } /* Now all released threads are blocked here, waiting for us. Collect them all (and win fabulous prizes!) :-) */ SDL_UnlockMutex(cond->lock); for (i = 0; i < num_waiting; ++i) { - SDL_SemWait(cond->wait_done); + SDL_WaitSemaphore(cond->wait_done); } } else { SDL_UnlockMutex(cond->lock); @@ -156,7 +156,7 @@ Typical use: Thread A: SDL_LockMutex(lock); while ( ! condition ) { - SDL_CondWait(cond, lock); + SDL_WaitCondition(cond, lock); } SDL_UnlockMutex(lock); @@ -165,10 +165,10 @@ Thread B: ... condition = true; ... - SDL_CondSignal(cond); + SDL_SignalCondition(cond); SDL_UnlockMutex(lock); */ -int SDL_CondWaitTimeoutNS_generic(SDL_cond *_cond, SDL_mutex *mutex, Sint64 timeoutNS) +int SDL_WaitConditionTimeoutNS_generic(SDL_cond *_cond, SDL_mutex *mutex, Sint64 timeoutNS) { SDL_cond_generic *cond = (SDL_cond_generic *)_cond; int retval; @@ -189,7 +189,7 @@ int SDL_CondWaitTimeoutNS_generic(SDL_cond *_cond, SDL_mutex *mutex, Sint64 time SDL_UnlockMutex(mutex); /* Wait for a signal */ - retval = SDL_SemWaitTimeoutNS(cond->wait_sem, timeoutNS); + retval = SDL_WaitSemaphoreTimeoutNS(cond->wait_sem, timeoutNS); /* Let the signaler know we have completed the wait, otherwise the signaler can race ahead and get the condition semaphore @@ -201,10 +201,10 @@ int SDL_CondWaitTimeoutNS_generic(SDL_cond *_cond, SDL_mutex *mutex, Sint64 time if (cond->signals > 0) { /* If we timed out, we need to eat a condition signal */ if (retval > 0) { - SDL_SemWait(cond->wait_sem); + SDL_WaitSemaphore(cond->wait_sem); } /* We always notify the signal thread that we are done */ - SDL_SemPost(cond->wait_done); + SDL_PostSemaphore(cond->wait_done); /* Signal handshake complete */ --cond->signals; diff --git a/src/thread/generic/SDL_syscond_c.h b/src/thread/generic/SDL_syscond_c.h index b0fc3195c..56a1172be 100644 --- a/src/thread/generic/SDL_syscond_c.h +++ b/src/thread/generic/SDL_syscond_c.h @@ -25,11 +25,11 @@ #ifdef SDL_THREAD_GENERIC_COND_SUFFIX -SDL_cond *SDL_CreateCond_generic(void); -void SDL_DestroyCond_generic(SDL_cond *cond); -int SDL_CondSignal_generic(SDL_cond *cond); -int SDL_CondBroadcast_generic(SDL_cond *cond); -int SDL_CondWaitTimeoutNS_generic(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS); +SDL_cond *SDL_CreateCondition_generic(void); +void SDL_DestroyCondition_generic(SDL_cond *cond); +int SDL_SignalCondition_generic(SDL_cond *cond); +int SDL_BroadcastCondition_generic(SDL_cond *cond); +int SDL_WaitConditionTimeoutNS_generic(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS); #endif /* SDL_THREAD_GENERIC_COND_SUFFIX */ diff --git a/src/thread/generic/SDL_sysmutex.c b/src/thread/generic/SDL_sysmutex.c index a5c5ec962..98a722d24 100644 --- a/src/thread/generic/SDL_sysmutex.c +++ b/src/thread/generic/SDL_sysmutex.c @@ -89,7 +89,7 @@ int SDL_LockMutex(SDL_mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS /* clang doesn We set the locking thread id after we obtain the lock so unlocks from other threads will fail. */ - SDL_SemWait(mutex->sem); + SDL_WaitSemaphore(mutex->sem); mutex->owner = this_thread; mutex->recursive = 0; } @@ -119,7 +119,7 @@ int SDL_TryLockMutex(SDL_mutex *mutex) We set the locking thread id after we obtain the lock so unlocks from other threads will fail. */ - retval = SDL_SemWait(mutex->sem); + retval = SDL_WaitSemaphore(mutex->sem); if (retval == 0) { mutex->owner = this_thread; mutex->recursive = 0; @@ -154,7 +154,7 @@ int SDL_UnlockMutex(SDL_mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS /* clang doe then release the lock semaphore. */ mutex->owner = 0; - SDL_SemPost(mutex->sem); + SDL_PostSemaphore(mutex->sem); } return 0; #endif /* SDL_THREADS_DISABLED */ diff --git a/src/thread/generic/SDL_sysrwlock.c b/src/thread/generic/SDL_sysrwlock.c index 01aa97652..8cb8dbd4a 100644 --- a/src/thread/generic/SDL_sysrwlock.c +++ b/src/thread/generic/SDL_sysrwlock.c @@ -65,7 +65,7 @@ SDL_rwlock *SDL_CreateRWLock_generic(void) return NULL; } - rwlock->condition = SDL_CreateCond(); + rwlock->condition = SDL_CreateCondition(); if (!rwlock->condition) { SDL_DestroyMutex(rwlock->lock); SDL_free(rwlock); @@ -82,7 +82,7 @@ void SDL_DestroyRWLock_generic(SDL_rwlock *rwlock) { if (rwlock) { SDL_DestroyMutex(rwlock->lock); - SDL_DestroyCond(rwlock->condition); + SDL_DestroyCondition(rwlock->condition); SDL_free(rwlock); } } @@ -111,7 +111,7 @@ int SDL_LockRWLockForWriting_generic(SDL_rwlock *rwlock) SDL_NO_THREAD_SAFETY_AN } while (SDL_AtomicGet(&rwlock->reader_count) > 0) { /* while something is holding the shared lock, keep waiting. */ - SDL_CondWait(rwlock->condition, rwlock->lock); /* release the lock and wait for readers holding the shared lock to release it, regrab the lock. */ + SDL_WaitCondition(rwlock->condition, rwlock->lock); /* release the lock and wait for readers holding the shared lock to release it, regrab the lock. */ } /* we hold the lock! */ @@ -172,7 +172,7 @@ int SDL_UnlockRWLock_generic(SDL_rwlock *rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS / if (SDL_AtomicGet(&rwlock->reader_count) > 0) { /* we're a reader */ SDL_AtomicAdd(&rwlock->reader_count, -1); - SDL_CondBroadcast(rwlock->condition); /* alert any pending writers to attempt to try to grab the lock again. */ + SDL_BroadcastCondition(rwlock->condition); /* alert any pending writers to attempt to try to grab the lock again. */ } else if (SDL_AtomicGet(&rwlock->writer_count) > 0) { /* we're a writer */ SDL_AtomicAdd(&rwlock->writer_count, -1); SDL_UnlockMutex(rwlock->lock); /* recursive unlock. */ diff --git a/src/thread/generic/SDL_syssem.c b/src/thread/generic/SDL_syssem.c index 82bd17d2e..8788d9a41 100644 --- a/src/thread/generic/SDL_syssem.c +++ b/src/thread/generic/SDL_syssem.c @@ -37,18 +37,18 @@ void SDL_DestroySemaphore(SDL_sem *sem) { } -int SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) +int SDL_WaitSemaphoreTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) { return SDL_SetError("SDL not built with thread support"); } Uint32 -SDL_SemValue(SDL_sem *sem) +SDL_GetSemaphoreValue(SDL_sem *sem) { return 0; } -int SDL_SemPost(SDL_sem *sem) +int SDL_PostSemaphore(SDL_sem *sem) { return SDL_SetError("SDL not built with thread support"); } @@ -77,7 +77,7 @@ SDL_CreateSemaphore(Uint32 initial_value) sem->waiters_count = 0; sem->count_lock = SDL_CreateMutex(); - sem->count_nonzero = SDL_CreateCond(); + sem->count_nonzero = SDL_CreateCondition(); if (!sem->count_lock || !sem->count_nonzero) { SDL_DestroySemaphore(sem); return NULL; @@ -94,10 +94,10 @@ void SDL_DestroySemaphore(SDL_sem *sem) if (sem) { sem->count = 0xFFFFFFFF; while (sem->waiters_count > 0) { - SDL_CondSignal(sem->count_nonzero); + SDL_SignalCondition(sem->count_nonzero); SDL_Delay(10); } - SDL_DestroyCond(sem->count_nonzero); + SDL_DestroyCondition(sem->count_nonzero); if (sem->count_lock) { SDL_LockMutex(sem->count_lock); SDL_UnlockMutex(sem->count_lock); @@ -107,7 +107,7 @@ void SDL_DestroySemaphore(SDL_sem *sem) } } -int SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) +int SDL_WaitSemaphoreTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) { int retval; @@ -132,7 +132,7 @@ int SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) ++sem->waiters_count; retval = 0; while ((sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT)) { - retval = SDL_CondWaitTimeoutNS(sem->count_nonzero, + retval = SDL_WaitConditionTimeoutNS(sem->count_nonzero, sem->count_lock, timeoutNS); } --sem->waiters_count; @@ -145,7 +145,7 @@ int SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) } Uint32 -SDL_SemValue(SDL_sem *sem) +SDL_GetSemaphoreValue(SDL_sem *sem) { Uint32 value; @@ -158,7 +158,7 @@ SDL_SemValue(SDL_sem *sem) return value; } -int SDL_SemPost(SDL_sem *sem) +int SDL_PostSemaphore(SDL_sem *sem) { if (sem == NULL) { return SDL_InvalidParamError("sem"); @@ -166,7 +166,7 @@ int SDL_SemPost(SDL_sem *sem) SDL_LockMutex(sem->count_lock); if (sem->waiters_count > 0) { - SDL_CondSignal(sem->count_nonzero); + SDL_SignalCondition(sem->count_nonzero); } ++sem->count; SDL_UnlockMutex(sem->count_lock); diff --git a/src/thread/n3ds/SDL_syscond.c b/src/thread/n3ds/SDL_syscond.c index f5d350ff6..7faccf4d7 100644 --- a/src/thread/n3ds/SDL_syscond.c +++ b/src/thread/n3ds/SDL_syscond.c @@ -33,7 +33,7 @@ struct SDL_cond /* Create a condition variable */ SDL_cond * -SDL_CreateCond(void) +SDL_CreateCondition(void) { SDL_cond *cond = (SDL_cond *)SDL_malloc(sizeof(SDL_cond)); if (cond) { @@ -45,7 +45,7 @@ SDL_CreateCond(void) } /* Destroy a condition variable */ -void SDL_DestroyCond(SDL_cond *cond) +void SDL_DestroyCondition(SDL_cond *cond) { if (cond) { SDL_free(cond); @@ -53,7 +53,7 @@ void SDL_DestroyCond(SDL_cond *cond) } /* Restart one of the threads that are waiting on the condition variable */ -int SDL_CondSignal(SDL_cond *cond) +int SDL_SignalCondition(SDL_cond *cond) { if (cond == NULL) { return SDL_InvalidParamError("cond"); @@ -64,7 +64,7 @@ int SDL_CondSignal(SDL_cond *cond) } /* Restart all threads that are waiting on the condition variable */ -int SDL_CondBroadcast(SDL_cond *cond) +int SDL_BroadcastCondition(SDL_cond *cond) { if (cond == NULL) { return SDL_InvalidParamError("cond"); @@ -83,7 +83,7 @@ Typical use: Thread A: SDL_LockMutex(lock); while ( ! condition ) { - SDL_CondWait(cond, lock); + SDL_WaitCondition(cond, lock); } SDL_UnlockMutex(lock); @@ -92,10 +92,10 @@ Thread B: ... condition = true; ... - SDL_CondSignal(cond); + SDL_SignalCondition(cond); SDL_UnlockMutex(lock); */ -int SDL_CondWaitTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS) +int SDL_WaitConditionTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS) { Result res; diff --git a/src/thread/n3ds/SDL_syssem.c b/src/thread/n3ds/SDL_syssem.c index ca3107a07..c15d5ee88 100644 --- a/src/thread/n3ds/SDL_syssem.c +++ b/src/thread/n3ds/SDL_syssem.c @@ -61,7 +61,7 @@ void SDL_DestroySemaphore(SDL_sem *sem) SDL_free(sem); } -int SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) +int SDL_WaitSemaphoreTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) { if (sem == NULL) { return SDL_InvalidParamError("sem"); @@ -97,7 +97,7 @@ int WaitOnSemaphoreFor(SDL_sem *sem, Sint64 timeout) return SDL_MUTEX_TIMEDOUT; } -Uint32 SDL_SemValue(SDL_sem *sem) +Uint32 SDL_GetSemaphoreValue(SDL_sem *sem) { if (sem == NULL) { SDL_InvalidParamError("sem"); @@ -106,7 +106,7 @@ Uint32 SDL_SemValue(SDL_sem *sem) return sem->semaphore.current_count; } -int SDL_SemPost(SDL_sem *sem) +int SDL_PostSemaphore(SDL_sem *sem) { if (sem == NULL) { return SDL_InvalidParamError("sem"); diff --git a/src/thread/ngage/SDL_syssem.cpp b/src/thread/ngage/SDL_syssem.cpp index 01c352238..aca4c5960 100644 --- a/src/thread/ngage/SDL_syssem.cpp +++ b/src/thread/ngage/SDL_syssem.cpp @@ -101,7 +101,7 @@ void SDL_DestroySemaphore(SDL_sem *sem) } } -int SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) +int SDL_WaitSemaphoreTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) { if (sem == NULL) { return SDL_InvalidParamError("sem"); @@ -140,7 +140,7 @@ int SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) } Uint32 -SDL_SemValue(SDL_sem *sem) +SDL_GetSemaphoreValue(SDL_sem *sem) { if (sem == NULL) { SDL_InvalidParamError("sem"); @@ -149,7 +149,7 @@ SDL_SemValue(SDL_sem *sem) return sem->count; } -int SDL_SemPost(SDL_sem *sem) +int SDL_PostSemaphore(SDL_sem *sem) { if (sem == NULL) { return SDL_InvalidParamError("sem"); diff --git a/src/thread/ps2/SDL_syssem.c b/src/thread/ps2/SDL_syssem.c index 2c951cf46..83c0a1be7 100644 --- a/src/thread/ps2/SDL_syssem.c +++ b/src/thread/ps2/SDL_syssem.c @@ -79,7 +79,7 @@ void SDL_DestroySemaphore(SDL_sem *sem) } } -int SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) +int SDL_WaitSemaphoreTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) { int ret; struct timer_alarm_t alarm; @@ -110,7 +110,7 @@ int SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) } /* Returns the current count of the semaphore */ -Uint32 SDL_SemValue(SDL_sem *sem) +Uint32 SDL_GetSemaphoreValue(SDL_sem *sem) { ee_sema_t info; @@ -126,7 +126,7 @@ Uint32 SDL_SemValue(SDL_sem *sem) return 0; } -int SDL_SemPost(SDL_sem *sem) +int SDL_PostSemaphore(SDL_sem *sem) { int res; diff --git a/src/thread/psp/SDL_syscond.c b/src/thread/psp/SDL_syscond.c index 2d7ba3e1c..87e6fa5d7 100644 --- a/src/thread/psp/SDL_syscond.c +++ b/src/thread/psp/SDL_syscond.c @@ -39,7 +39,7 @@ struct SDL_cond /* Create a condition variable */ SDL_cond * -SDL_CreateCond(void) +SDL_CreateCondition(void) { SDL_cond *cond; @@ -50,7 +50,7 @@ SDL_CreateCond(void) cond->wait_done = SDL_CreateSemaphore(0); cond->waiting = cond->signals = 0; if (!cond->lock || !cond->wait_sem || !cond->wait_done) { - SDL_DestroyCond(cond); + SDL_DestroyCondition(cond); cond = NULL; } } else { @@ -60,7 +60,7 @@ SDL_CreateCond(void) } /* Destroy a condition variable */ -void SDL_DestroyCond(SDL_cond *cond) +void SDL_DestroyCondition(SDL_cond *cond) { if (cond) { if (cond->wait_sem) { @@ -77,7 +77,7 @@ void SDL_DestroyCond(SDL_cond *cond) } /* Restart one of the threads that are waiting on the condition variable */ -int SDL_CondSignal(SDL_cond *cond) +int SDL_SignalCondition(SDL_cond *cond) { if (cond == NULL) { return SDL_InvalidParamError("cond"); @@ -89,9 +89,9 @@ int SDL_CondSignal(SDL_cond *cond) SDL_LockMutex(cond->lock); if (cond->waiting > cond->signals) { ++cond->signals; - SDL_SemPost(cond->wait_sem); + SDL_PostSemaphore(cond->wait_sem); SDL_UnlockMutex(cond->lock); - SDL_SemWait(cond->wait_done); + SDL_WaitSemaphore(cond->wait_done); } else { SDL_UnlockMutex(cond->lock); } @@ -100,7 +100,7 @@ int SDL_CondSignal(SDL_cond *cond) } /* Restart all threads that are waiting on the condition variable */ -int SDL_CondBroadcast(SDL_cond *cond) +int SDL_BroadcastCondition(SDL_cond *cond) { if (cond == NULL) { return SDL_InvalidParamError("cond"); @@ -116,14 +116,14 @@ int SDL_CondBroadcast(SDL_cond *cond) num_waiting = (cond->waiting - cond->signals); cond->signals = cond->waiting; for (i = 0; i < num_waiting; ++i) { - SDL_SemPost(cond->wait_sem); + SDL_PostSemaphore(cond->wait_sem); } /* Now all released threads are blocked here, waiting for us. Collect them all (and win fabulous prizes!) :-) */ SDL_UnlockMutex(cond->lock); for (i = 0; i < num_waiting; ++i) { - SDL_SemWait(cond->wait_done); + SDL_WaitSemaphore(cond->wait_done); } } else { SDL_UnlockMutex(cond->lock); @@ -141,7 +141,7 @@ Typical use: Thread A: SDL_LockMutex(lock); while ( ! condition ) { - SDL_CondWait(cond, lock); + SDL_WaitCondition(cond, lock); } SDL_UnlockMutex(lock); @@ -150,10 +150,10 @@ Thread B: ... condition = true; ... - SDL_CondSignal(cond); + SDL_SignalCondition(cond); SDL_UnlockMutex(lock); */ -int SDL_CondWaitTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS) +int SDL_WaitConditionTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS) { int retval; @@ -173,7 +173,7 @@ int SDL_CondWaitTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS) SDL_UnlockMutex(mutex); /* Wait for a signal */ - retval = SDL_SemWaitTimeout(cond->wait_sem, timeoutNS); + retval = SDL_WaitSemaphoreTimeout(cond->wait_sem, timeoutNS); /* Let the signaler know we have completed the wait, otherwise the signaler can race ahead and get the condition semaphore @@ -185,10 +185,10 @@ int SDL_CondWaitTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS) if (cond->signals > 0) { /* If we timed out, we need to eat a condition signal */ if (retval > 0) { - SDL_SemWait(cond->wait_sem); + SDL_WaitSemaphore(cond->wait_sem); } /* We always notify the signal thread that we are done */ - SDL_SemPost(cond->wait_done); + SDL_PostSemaphore(cond->wait_done); /* Signal handshake complete */ --cond->signals; diff --git a/src/thread/psp/SDL_syssem.c b/src/thread/psp/SDL_syssem.c index dbad71e96..e43b4c64c 100644 --- a/src/thread/psp/SDL_syssem.c +++ b/src/thread/psp/SDL_syssem.c @@ -73,7 +73,7 @@ void SDL_DestroySemaphore(SDL_sem *sem) * If the timeout is 0 then just poll the semaphore; if it's SDL_MUTEX_MAXWAIT, pass * NULL to sceKernelWaitSema() so that it waits indefinitely; and if the timeout * is specified, convert it to microseconds. */ -int SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) +int SDL_WaitSemaphoreTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) { SceUInt timeoutUS; SceUInt *pTimeout; @@ -110,7 +110,7 @@ int SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) } /* Returns the current count of the semaphore */ -Uint32 SDL_SemValue(SDL_sem *sem) +Uint32 SDL_GetSemaphoreValue(SDL_sem *sem) { SceKernelSemaInfo info; @@ -126,7 +126,7 @@ Uint32 SDL_SemValue(SDL_sem *sem) return 0; } -int SDL_SemPost(SDL_sem *sem) +int SDL_PostSemaphore(SDL_sem *sem) { int res; diff --git a/src/thread/pthread/SDL_syscond.c b/src/thread/pthread/SDL_syscond.c index f828440d7..ff32d4689 100644 --- a/src/thread/pthread/SDL_syscond.c +++ b/src/thread/pthread/SDL_syscond.c @@ -35,7 +35,7 @@ struct SDL_cond /* Create a condition variable */ SDL_cond * -SDL_CreateCond(void) +SDL_CreateCondition(void) { SDL_cond *cond; @@ -51,7 +51,7 @@ SDL_CreateCond(void) } /* Destroy a condition variable */ -void SDL_DestroyCond(SDL_cond *cond) +void SDL_DestroyCondition(SDL_cond *cond) { if (cond) { pthread_cond_destroy(&cond->cond); @@ -60,7 +60,7 @@ void SDL_DestroyCond(SDL_cond *cond) } /* Restart one of the threads that are waiting on the condition variable */ -int SDL_CondSignal(SDL_cond *cond) +int SDL_SignalCondition(SDL_cond *cond) { int retval; @@ -76,7 +76,7 @@ int SDL_CondSignal(SDL_cond *cond) } /* Restart all threads that are waiting on the condition variable */ -int SDL_CondBroadcast(SDL_cond *cond) +int SDL_BroadcastCondition(SDL_cond *cond) { int retval; @@ -91,7 +91,7 @@ int SDL_CondBroadcast(SDL_cond *cond) return retval; } -int SDL_CondWaitTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS) +int SDL_WaitConditionTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS) { int retval; #ifndef HAVE_CLOCK_GETTIME diff --git a/src/thread/pthread/SDL_syssem.c b/src/thread/pthread/SDL_syssem.c index a8c257f4d..f341552ff 100644 --- a/src/thread/pthread/SDL_syssem.c +++ b/src/thread/pthread/SDL_syssem.c @@ -63,7 +63,7 @@ void SDL_DestroySemaphore(SDL_sem *sem) } } -int SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) +int SDL_WaitSemaphoreTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) { int retval = 0; #ifdef HAVE_SEM_TIMEDWAIT @@ -150,7 +150,7 @@ int SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) } Uint32 -SDL_SemValue(SDL_sem *sem) +SDL_GetSemaphoreValue(SDL_sem *sem) { int ret = 0; @@ -166,7 +166,7 @@ SDL_SemValue(SDL_sem *sem) return (Uint32)ret; } -int SDL_SemPost(SDL_sem *sem) +int SDL_PostSemaphore(SDL_sem *sem) { int retval; diff --git a/src/thread/stdcpp/SDL_syscond.cpp b/src/thread/stdcpp/SDL_syscond.cpp index 30defc054..764ec9fb9 100644 --- a/src/thread/stdcpp/SDL_syscond.cpp +++ b/src/thread/stdcpp/SDL_syscond.cpp @@ -37,7 +37,7 @@ struct SDL_cond /* Create a condition variable */ extern "C" SDL_cond * -SDL_CreateCond(void) +SDL_CreateCondition(void) { /* Allocate and initialize the condition variable */ try { @@ -54,7 +54,7 @@ SDL_CreateCond(void) /* Destroy a condition variable */ extern "C" void -SDL_DestroyCond(SDL_cond *cond) +SDL_DestroyCondition(SDL_cond *cond) { if (cond != NULL) { delete cond; @@ -63,7 +63,7 @@ SDL_DestroyCond(SDL_cond *cond) /* Restart one of the threads that are waiting on the condition variable */ extern "C" int -SDL_CondSignal(SDL_cond *cond) +SDL_SignalCondition(SDL_cond *cond) { if (cond == NULL) { return SDL_InvalidParamError("cond"); @@ -75,7 +75,7 @@ SDL_CondSignal(SDL_cond *cond) /* Restart all threads that are waiting on the condition variable */ extern "C" int -SDL_CondBroadcast(SDL_cond *cond) +SDL_BroadcastCondition(SDL_cond *cond) { if (cond == NULL) { return SDL_InvalidParamError("cond"); @@ -94,7 +94,7 @@ Typical use: Thread A: SDL_LockMutex(lock); while ( ! condition ) { - SDL_CondWait(cond, lock); + SDL_WaitCondition(cond, lock); } SDL_UnlockMutex(lock); @@ -103,11 +103,11 @@ Thread B: ... condition = true; ... - SDL_CondSignal(cond); + SDL_SignalCondition(cond); SDL_UnlockMutex(lock); */ extern "C" int -SDL_CondWaitTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS) +SDL_WaitConditionTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS) { if (cond == NULL) { return SDL_InvalidParamError("cond"); diff --git a/src/thread/vita/SDL_syscond.c b/src/thread/vita/SDL_syscond.c index 182cccd4e..d9a6f5f8d 100644 --- a/src/thread/vita/SDL_syscond.c +++ b/src/thread/vita/SDL_syscond.c @@ -39,7 +39,7 @@ struct SDL_cond /* Create a condition variable */ SDL_cond * -SDL_CreateCond(void) +SDL_CreateCondition(void) { SDL_cond *cond; @@ -50,7 +50,7 @@ SDL_CreateCond(void) cond->wait_done = SDL_CreateSemaphore(0); cond->waiting = cond->signals = 0; if (!cond->lock || !cond->wait_sem || !cond->wait_done) { - SDL_DestroyCond(cond); + SDL_DestroyCondition(cond); cond = NULL; } } else { @@ -60,7 +60,7 @@ SDL_CreateCond(void) } /* Destroy a condition variable */ -void SDL_DestroyCond(SDL_cond *cond) +void SDL_DestroyCondition(SDL_cond *cond) { if (cond != NULL) { if (cond->wait_sem) { @@ -77,7 +77,7 @@ void SDL_DestroyCond(SDL_cond *cond) } /* Restart one of the threads that are waiting on the condition variable */ -int SDL_CondSignal(SDL_cond *cond) +int SDL_SignalCondition(SDL_cond *cond) { if (cond == NULL) { return SDL_InvalidParamError("cond"); @@ -89,9 +89,9 @@ int SDL_CondSignal(SDL_cond *cond) SDL_LockMutex(cond->lock); if (cond->waiting > cond->signals) { ++cond->signals; - SDL_SemPost(cond->wait_sem); + SDL_PostSemaphore(cond->wait_sem); SDL_UnlockMutex(cond->lock); - SDL_SemWait(cond->wait_done); + SDL_WaitSemaphore(cond->wait_done); } else { SDL_UnlockMutex(cond->lock); } @@ -100,7 +100,7 @@ int SDL_CondSignal(SDL_cond *cond) } /* Restart all threads that are waiting on the condition variable */ -int SDL_CondBroadcast(SDL_cond *cond) +int SDL_BroadcastCondition(SDL_cond *cond) { if (cond == NULL) { return SDL_InvalidParamError("cond"); @@ -116,14 +116,14 @@ int SDL_CondBroadcast(SDL_cond *cond) num_waiting = (cond->waiting - cond->signals); cond->signals = cond->waiting; for (i = 0; i < num_waiting; ++i) { - SDL_SemPost(cond->wait_sem); + SDL_PostSemaphore(cond->wait_sem); } /* Now all released threads are blocked here, waiting for us. Collect them all (and win fabulous prizes!) :-) */ SDL_UnlockMutex(cond->lock); for (i = 0; i < num_waiting; ++i) { - SDL_SemWait(cond->wait_done); + SDL_WaitSemaphore(cond->wait_done); } } else { SDL_UnlockMutex(cond->lock); @@ -141,7 +141,7 @@ Typical use: Thread A: SDL_LockMutex(lock); while ( ! condition ) { - SDL_CondWait(cond, lock); + SDL_WaitCondition(cond, lock); } SDL_UnlockMutex(lock); @@ -150,10 +150,10 @@ Thread B: ... condition = true; ... - SDL_CondSignal(cond); + SDL_SignalCondition(cond); SDL_UnlockMutex(lock); */ -int SDL_CondWaitTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS) +int SDL_WaitConditionTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS) { int retval; @@ -173,7 +173,7 @@ int SDL_CondWaitTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS) SDL_UnlockMutex(mutex); /* Wait for a signal */ - retval = SDL_SemWaitTimeoutNS(cond->wait_sem, timeoutNS); + retval = SDL_WaitSemaphoreTimeoutNS(cond->wait_sem, timeoutNS); /* Let the signaler know we have completed the wait, otherwise the signaler can race ahead and get the condition semaphore @@ -185,10 +185,10 @@ int SDL_CondWaitTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS) if (cond->signals > 0) { /* If we timed out, we need to eat a condition signal */ if (retval > 0) { - SDL_SemWait(cond->wait_sem); + SDL_WaitSemaphore(cond->wait_sem); } /* We always notify the signal thread that we are done */ - SDL_SemPost(cond->wait_done); + SDL_PostSemaphore(cond->wait_done); /* Signal handshake complete */ --cond->signals; diff --git a/src/thread/vita/SDL_syssem.c b/src/thread/vita/SDL_syssem.c index d13e83499..1efdcb491 100644 --- a/src/thread/vita/SDL_syssem.c +++ b/src/thread/vita/SDL_syssem.c @@ -74,7 +74,7 @@ void SDL_DestroySemaphore(SDL_sem *sem) * If the timeout is 0 then just poll the semaphore; if it's SDL_MUTEX_MAXWAIT, pass * NULL to sceKernelWaitSema() so that it waits indefinitely; and if the timeout * is specified, convert it to microseconds. */ -int SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) +int SDL_WaitSemaphoreTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) { SceUInt timeoutUS; SceUInt *pTimeout; @@ -111,7 +111,7 @@ int SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) } /* Returns the current count of the semaphore */ -Uint32 SDL_SemValue(SDL_sem *sem) +Uint32 SDL_GetSemaphoreValue(SDL_sem *sem) { SceKernelSemaInfo info; info.size = sizeof(info); @@ -128,7 +128,7 @@ Uint32 SDL_SemValue(SDL_sem *sem) return 0; } -int SDL_SemPost(SDL_sem *sem) +int SDL_PostSemaphore(SDL_sem *sem) { int res; diff --git a/src/thread/windows/SDL_syscond_cv.c b/src/thread/windows/SDL_syscond_cv.c index e0ac306ad..cfd1ba6d5 100644 --- a/src/thread/windows/SDL_syscond_cv.c +++ b/src/thread/windows/SDL_syscond_cv.c @@ -23,19 +23,19 @@ #include "../generic/SDL_syscond_c.h" #include "SDL_sysmutex_c.h" -typedef SDL_cond *(*pfnSDL_CreateCond)(void); -typedef void (*pfnSDL_DestroyCond)(SDL_cond *); -typedef int (*pfnSDL_CondSignal)(SDL_cond *); -typedef int (*pfnSDL_CondBroadcast)(SDL_cond *); -typedef int (*pfnSDL_CondWaitTimeoutNS)(SDL_cond *, SDL_mutex *, Sint64); +typedef SDL_cond *(*pfnSDL_CreateCondition)(void); +typedef void (*pfnSDL_DestroyCondition)(SDL_cond *); +typedef int (*pfnSDL_SignalCondition)(SDL_cond *); +typedef int (*pfnSDL_BroadcastCondition)(SDL_cond *); +typedef int (*pfnSDL_WaitConditionTimeoutNS)(SDL_cond *, SDL_mutex *, Sint64); typedef struct SDL_cond_impl_t { - pfnSDL_CreateCond Create; - pfnSDL_DestroyCond Destroy; - pfnSDL_CondSignal Signal; - pfnSDL_CondBroadcast Broadcast; - pfnSDL_CondWaitTimeoutNS WaitTimeoutNS; + pfnSDL_CreateCondition Create; + pfnSDL_DestroyCondition Destroy; + pfnSDL_SignalCondition Signal; + pfnSDL_BroadcastCondition Broadcast; + pfnSDL_WaitConditionTimeoutNS WaitTimeoutNS; } SDL_cond_impl_t; /* Implementation will be chosen at runtime based on available Kernel features */ @@ -78,7 +78,7 @@ typedef struct SDL_cond_cv CONDITION_VARIABLE cond; } SDL_cond_cv; -static SDL_cond *SDL_CreateCond_cv(void) +static SDL_cond *SDL_CreateCondition_cv(void) { SDL_cond_cv *cond; @@ -91,7 +91,7 @@ static SDL_cond *SDL_CreateCond_cv(void) return (SDL_cond *)cond; } -static void SDL_DestroyCond_cv(SDL_cond *cond) +static void SDL_DestroyCondition_cv(SDL_cond *cond) { if (cond != NULL) { /* There are no kernel allocated resources */ @@ -99,7 +99,7 @@ static void SDL_DestroyCond_cv(SDL_cond *cond) } } -static int SDL_CondSignal_cv(SDL_cond *_cond) +static int SDL_SignalCondition_cv(SDL_cond *_cond) { SDL_cond_cv *cond = (SDL_cond_cv *)_cond; if (cond == NULL) { @@ -111,7 +111,7 @@ static int SDL_CondSignal_cv(SDL_cond *_cond) return 0; } -static int SDL_CondBroadcast_cv(SDL_cond *_cond) +static int SDL_BroadcastCondition_cv(SDL_cond *_cond) { SDL_cond_cv *cond = (SDL_cond_cv *)_cond; if (cond == NULL) { @@ -123,7 +123,7 @@ static int SDL_CondBroadcast_cv(SDL_cond *_cond) return 0; } -static int SDL_CondWaitTimeoutNS_cv(SDL_cond *_cond, SDL_mutex *_mutex, Sint64 timeoutNS) +static int SDL_WaitConditionTimeoutNS_cv(SDL_cond *_cond, SDL_mutex *_mutex, Sint64 timeoutNS) { SDL_cond_cv *cond = (SDL_cond_cv *)_cond; DWORD timeout; @@ -187,27 +187,27 @@ static int SDL_CondWaitTimeoutNS_cv(SDL_cond *_cond, SDL_mutex *_mutex, Sint64 t } static const SDL_cond_impl_t SDL_cond_impl_cv = { - &SDL_CreateCond_cv, - &SDL_DestroyCond_cv, - &SDL_CondSignal_cv, - &SDL_CondBroadcast_cv, - &SDL_CondWaitTimeoutNS_cv, + &SDL_CreateCondition_cv, + &SDL_DestroyCondition_cv, + &SDL_SignalCondition_cv, + &SDL_BroadcastCondition_cv, + &SDL_WaitConditionTimeoutNS_cv, }; #ifndef __WINRT__ /* Generic Condition Variable implementation using SDL_mutex and SDL_sem */ static const SDL_cond_impl_t SDL_cond_impl_generic = { - &SDL_CreateCond_generic, - &SDL_DestroyCond_generic, - &SDL_CondSignal_generic, - &SDL_CondBroadcast_generic, - &SDL_CondWaitTimeoutNS_generic, + &SDL_CreateCondition_generic, + &SDL_DestroyCondition_generic, + &SDL_SignalCondition_generic, + &SDL_BroadcastCondition_generic, + &SDL_WaitConditionTimeoutNS_generic, }; #endif SDL_cond * -SDL_CreateCond(void) +SDL_CreateCondition(void) { if (SDL_cond_impl_active.Create == NULL) { const SDL_cond_impl_t *impl = NULL; @@ -249,22 +249,22 @@ SDL_CreateCond(void) return SDL_cond_impl_active.Create(); } -void SDL_DestroyCond(SDL_cond *cond) +void SDL_DestroyCondition(SDL_cond *cond) { SDL_cond_impl_active.Destroy(cond); } -int SDL_CondSignal(SDL_cond *cond) +int SDL_SignalCondition(SDL_cond *cond) { return SDL_cond_impl_active.Signal(cond); } -int SDL_CondBroadcast(SDL_cond *cond) +int SDL_BroadcastCondition(SDL_cond *cond) { return SDL_cond_impl_active.Broadcast(cond); } -int SDL_CondWaitTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS) +int SDL_WaitConditionTimeoutNS(SDL_cond *cond, SDL_mutex *mutex, Sint64 timeoutNS) { return SDL_cond_impl_active.WaitTimeoutNS(cond, mutex, timeoutNS); } diff --git a/src/thread/windows/SDL_syssem.c b/src/thread/windows/SDL_syssem.c index 034681fa9..408923a42 100644 --- a/src/thread/windows/SDL_syssem.c +++ b/src/thread/windows/SDL_syssem.c @@ -37,17 +37,17 @@ typedef SDL_sem *(*pfnSDL_CreateSemaphore)(Uint32); typedef void (*pfnSDL_DestroySemaphore)(SDL_sem *); -typedef int (*pfnSDL_SemWaitTimeoutNS)(SDL_sem *, Sint64); -typedef Uint32 (*pfnSDL_SemValue)(SDL_sem *); -typedef int (*pfnSDL_SemPost)(SDL_sem *); +typedef int (*pfnSDL_WaitSemaphoreTimeoutNS)(SDL_sem *, Sint64); +typedef Uint32 (*pfnSDL_GetSemaphoreValue)(SDL_sem *); +typedef int (*pfnSDL_PostSemaphore)(SDL_sem *); typedef struct SDL_semaphore_impl_t { pfnSDL_CreateSemaphore Create; pfnSDL_DestroySemaphore Destroy; - pfnSDL_SemWaitTimeoutNS WaitTimeoutNS; - pfnSDL_SemValue Value; - pfnSDL_SemPost Post; + pfnSDL_WaitSemaphoreTimeoutNS WaitTimeoutNS; + pfnSDL_GetSemaphoreValue Value; + pfnSDL_PostSemaphore Post; } SDL_sem_impl_t; /* Implementation will be chosen at runtime based on available Kernel features */ @@ -98,7 +98,7 @@ static void SDL_DestroySemaphore_atom(SDL_sem *sem) } } -static int SDL_SemWaitTimeoutNS_atom(SDL_sem *_sem, Sint64 timeoutNS) +static int SDL_WaitSemaphoreTimeoutNS_atom(SDL_sem *_sem, Sint64 timeoutNS) { SDL_sem_atom *sem = (SDL_sem_atom *)_sem; LONG count; @@ -172,7 +172,7 @@ static int SDL_SemWaitTimeoutNS_atom(SDL_sem *_sem, Sint64 timeoutNS) } } -static Uint32 SDL_SemValue_atom(SDL_sem *_sem) +static Uint32 SDL_GetSemaphoreValue_atom(SDL_sem *_sem) { SDL_sem_atom *sem = (SDL_sem_atom *)_sem; @@ -184,7 +184,7 @@ static Uint32 SDL_SemValue_atom(SDL_sem *_sem) return (Uint32)sem->count; } -static int SDL_SemPost_atom(SDL_sem *_sem) +static int SDL_PostSemaphore_atom(SDL_sem *_sem) { SDL_sem_atom *sem = (SDL_sem_atom *)_sem; @@ -201,9 +201,9 @@ static int SDL_SemPost_atom(SDL_sem *_sem) static const SDL_sem_impl_t SDL_sem_impl_atom = { &SDL_CreateSemaphore_atom, &SDL_DestroySemaphore_atom, - &SDL_SemWaitTimeoutNS_atom, - &SDL_SemValue_atom, - &SDL_SemPost_atom, + &SDL_WaitSemaphoreTimeoutNS_atom, + &SDL_GetSemaphoreValue_atom, + &SDL_PostSemaphore_atom, }; #endif /* !SDL_WINAPI_FAMILY_PHONE */ @@ -256,7 +256,7 @@ static void SDL_DestroySemaphore_kern(SDL_sem *_sem) } } -static int SDL_SemWaitTimeoutNS_kern(SDL_sem *_sem, Sint64 timeoutNS) +static int SDL_WaitSemaphoreTimeoutNS_kern(SDL_sem *_sem, Sint64 timeoutNS) { SDL_sem_kern *sem = (SDL_sem_kern *)_sem; int retval; @@ -287,7 +287,7 @@ static int SDL_SemWaitTimeoutNS_kern(SDL_sem *_sem, Sint64 timeoutNS) } /* Returns the current count of the semaphore */ -static Uint32 SDL_SemValue_kern(SDL_sem *_sem) +static Uint32 SDL_GetSemaphoreValue_kern(SDL_sem *_sem) { SDL_sem_kern *sem = (SDL_sem_kern *)_sem; if (sem == NULL) { @@ -297,7 +297,7 @@ static Uint32 SDL_SemValue_kern(SDL_sem *_sem) return (Uint32)sem->count; } -static int SDL_SemPost_kern(SDL_sem *_sem) +static int SDL_PostSemaphore_kern(SDL_sem *_sem) { SDL_sem_kern *sem = (SDL_sem_kern *)_sem; if (sem == NULL) { @@ -319,9 +319,9 @@ static int SDL_SemPost_kern(SDL_sem *_sem) static const SDL_sem_impl_t SDL_sem_impl_kern = { &SDL_CreateSemaphore_kern, &SDL_DestroySemaphore_kern, - &SDL_SemWaitTimeoutNS_kern, - &SDL_SemValue_kern, - &SDL_SemPost_kern, + &SDL_WaitSemaphoreTimeoutNS_kern, + &SDL_GetSemaphoreValue_kern, + &SDL_PostSemaphore_kern, }; /** @@ -372,18 +372,18 @@ void SDL_DestroySemaphore(SDL_sem *sem) SDL_sem_impl_active.Destroy(sem); } -int SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) +int SDL_WaitSemaphoreTimeoutNS(SDL_sem *sem, Sint64 timeoutNS) { return SDL_sem_impl_active.WaitTimeoutNS(sem, timeoutNS); } Uint32 -SDL_SemValue(SDL_sem *sem) +SDL_GetSemaphoreValue(SDL_sem *sem) { return SDL_sem_impl_active.Value(sem); } -int SDL_SemPost(SDL_sem *sem) +int SDL_PostSemaphore(SDL_sem *sem) { return SDL_sem_impl_active.Post(sem); } diff --git a/src/timer/SDL_timer.c b/src/timer/SDL_timer.c index 5e7f0b0f1..18d703905 100644 --- a/src/timer/SDL_timer.c +++ b/src/timer/SDL_timer.c @@ -197,7 +197,7 @@ static int SDLCALL SDL_TimerThread(void *_data) That's okay, it just means we run through the loop a few extra times. */ - SDL_SemWaitTimeoutNS(data->sem, delay); + SDL_WaitSemaphoreTimeoutNS(data->sem, delay); } return 0; } @@ -242,7 +242,7 @@ void SDL_QuitTimers(void) if (SDL_AtomicCAS(&data->active, 1, 0)) { /* active? Move to inactive. */ /* Shutdown the timer thread */ if (data->thread) { - SDL_SemPost(data->sem); + SDL_PostSemaphore(data->sem); SDL_WaitThread(data->thread, NULL); data->thread = NULL; } @@ -329,7 +329,7 @@ SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *para SDL_AtomicUnlock(&data->lock); /* Wake up the timer thread if necessary */ - SDL_SemPost(data->sem); + SDL_PostSemaphore(data->sem); return entry->timerID; } diff --git a/src/video/android/SDL_androidevents.c b/src/video/android/SDL_androidevents.c index a9e7bef40..a924a23c4 100644 --- a/src/video/android/SDL_androidevents.c +++ b/src/video/android/SDL_androidevents.c @@ -138,7 +138,7 @@ void Android_PumpEvents_Blocking(_THIS) openslES_PauseDevices(); aaudio_PauseDevices(); - if (SDL_SemWait(Android_ResumeSem) == 0) { + if (SDL_WaitSemaphore(Android_ResumeSem) == 0) { videodata->isPaused = 0; @@ -166,7 +166,7 @@ void Android_PumpEvents_Blocking(_THIS) } } } else { - if (videodata->isPausing || SDL_SemTryWait(Android_PauseSem) == 0) { + if (videodata->isPausing || SDL_TryWaitSemaphore(Android_PauseSem) == 0) { /* Android_PauseSem was signaled */ if (videodata->isPausing == 0) { @@ -178,7 +178,7 @@ void Android_PumpEvents_Blocking(_THIS) /* We've been signaled to pause (potentially several times), but before we block ourselves, * we need to make sure that the very last event (of the first pause sequence, if several) * has reached the app */ - if (SDL_NumberOfEvents(SDL_EVENT_DID_ENTER_BACKGROUND) > SDL_SemValue(Android_PauseSem)) { + if (SDL_NumberOfEvents(SDL_EVENT_DID_ENTER_BACKGROUND) > SDL_GetSemaphoreValue(Android_PauseSem)) { videodata->isPausing = 1; } else { videodata->isPausing = 0; @@ -220,7 +220,7 @@ void Android_PumpEvents_NonBlocking(_THIS) backup_context = 0; } - if (SDL_SemTryWait(Android_ResumeSem) == 0) { + if (SDL_TryWaitSemaphore(Android_ResumeSem) == 0) { videodata->isPaused = 0; @@ -250,7 +250,7 @@ void Android_PumpEvents_NonBlocking(_THIS) } } } else { - if (videodata->isPausing || SDL_SemTryWait(Android_PauseSem) == 0) { + if (videodata->isPausing || SDL_TryWaitSemaphore(Android_PauseSem) == 0) { /* Android_PauseSem was signaled */ if (videodata->isPausing == 0) { @@ -262,7 +262,7 @@ void Android_PumpEvents_NonBlocking(_THIS) /* We've been signaled to pause (potentially several times), but before we block ourselves, * we need to make sure that the very last event (of the first pause sequence, if several) * has reached the app */ - if (SDL_NumberOfEvents(SDL_EVENT_DID_ENTER_BACKGROUND) > SDL_SemValue(Android_PauseSem)) { + if (SDL_NumberOfEvents(SDL_EVENT_DID_ENTER_BACKGROUND) > SDL_GetSemaphoreValue(Android_PauseSem)) { videodata->isPausing = 1; } else { videodata->isPausing = 0; diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m index 2da540ca7..a61e8f2ac 100644 --- a/src/video/cocoa/SDL_cocoaopengl.m +++ b/src/video/cocoa/SDL_cocoaopengl.m @@ -68,7 +68,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt if (setting != 0) { /* nothing to do if vsync is disabled, don't even lock */ SDL_LockMutex(nscontext->swapIntervalMutex); SDL_AtomicAdd(&nscontext->swapIntervalsPassed, 1); - SDL_CondSignal(nscontext->swapIntervalCond); + SDL_SignalCondition(nscontext->swapIntervalCond); SDL_UnlockMutex(nscontext->swapIntervalMutex); } @@ -87,7 +87,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt self->window = NULL; SDL_AtomicSet(&self->swapIntervalSetting, 0); SDL_AtomicSet(&self->swapIntervalsPassed, 0); - self->swapIntervalCond = SDL_CreateCond(); + self->swapIntervalCond = SDL_CreateCondition(); self->swapIntervalMutex = SDL_CreateMutex(); if (!self->swapIntervalCond || !self->swapIntervalMutex) { return nil; @@ -214,7 +214,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt self->displayLink = nil; } if (self->swapIntervalCond) { - SDL_DestroyCond(self->swapIntervalCond); + SDL_DestroyCondition(self->swapIntervalCond); self->swapIntervalCond = NULL; } if (self->swapIntervalMutex) { @@ -498,14 +498,14 @@ int Cocoa_GL_SwapWindow(_THIS, SDL_Window *window) } else if (setting < 0) { /* late swap tearing */ SDL_LockMutex(nscontext->swapIntervalMutex); while (SDL_AtomicGet(&nscontext->swapIntervalsPassed) == 0) { - SDL_CondWait(nscontext->swapIntervalCond, nscontext->swapIntervalMutex); + SDL_WaitCondition(nscontext->swapIntervalCond, nscontext->swapIntervalMutex); } SDL_AtomicSet(&nscontext->swapIntervalsPassed, 0); SDL_UnlockMutex(nscontext->swapIntervalMutex); } else { SDL_LockMutex(nscontext->swapIntervalMutex); do { /* always wait here so we know we just hit a swap interval. */ - SDL_CondWait(nscontext->swapIntervalCond, nscontext->swapIntervalMutex); + SDL_WaitCondition(nscontext->swapIntervalCond, nscontext->swapIntervalMutex); } while ((SDL_AtomicGet(&nscontext->swapIntervalsPassed) % setting) != 0); SDL_AtomicSet(&nscontext->swapIntervalsPassed, 0); SDL_UnlockMutex(nscontext->swapIntervalMutex); diff --git a/src/video/psp/SDL_pspevents.c b/src/video/psp/SDL_pspevents.c index f17b618b1..ba5dd767c 100644 --- a/src/video/psp/SDL_pspevents.c +++ b/src/video/psp/SDL_pspevents.c @@ -64,9 +64,9 @@ static struct int EventUpdate(void *data) { while (running) { - SDL_SemWait(event_sem); + SDL_WaitSemaphore(event_sem); sceHprmPeekCurrentKey((u32 *)&hprm); - SDL_SemPost(event_sem); + SDL_PostSemaphore(event_sem); /* Delay 1/60th of a second */ sceKernelDelayThread(1000000 / 60); } @@ -80,9 +80,9 @@ void PSP_PumpEvents(_THIS) enum PspHprmKeys changed; static enum PspHprmKeys old_keys = 0; - SDL_SemWait(event_sem); + SDL_WaitSemaphore(event_sem); keys = hprm; - SDL_SemPost(event_sem); + SDL_PostSemaphore(event_sem); /* HPRM Keyboard */ changed = old_keys ^ keys; diff --git a/src/video/raspberry/SDL_rpiopengles.c b/src/video/raspberry/SDL_rpiopengles.c index 11c99e1ca..7ccc6aebc 100644 --- a/src/video/raspberry/SDL_rpiopengles.c +++ b/src/video/raspberry/SDL_rpiopengles.c @@ -52,7 +52,7 @@ int RPI_GLES_SwapWindow(_THIS, SDL_Window *window) * Run your SDL program with "SDL_RPI_DOUBLE_BUFFER=1 " to enable this. */ if (wdata->double_buffer) { SDL_LockMutex(wdata->vsync_cond_mutex); - SDL_CondWait(wdata->vsync_cond, wdata->vsync_cond_mutex); + SDL_WaitCondition(wdata->vsync_cond, wdata->vsync_cond_mutex); SDL_UnlockMutex(wdata->vsync_cond_mutex); } diff --git a/src/video/raspberry/SDL_rpivideo.c b/src/video/raspberry/SDL_rpivideo.c index c0a45fe05..7b1934292 100644 --- a/src/video/raspberry/SDL_rpivideo.c +++ b/src/video/raspberry/SDL_rpivideo.c @@ -215,7 +215,7 @@ static void RPI_vsync_callback(DISPMANX_UPDATE_HANDLE_T u, void *data) SDL_WindowData *wdata = (SDL_WindowData *)data; SDL_LockMutex(wdata->vsync_cond_mutex); - SDL_CondSignal(wdata->vsync_cond); + SDL_SignalCondition(wdata->vsync_cond); SDL_UnlockMutex(wdata->vsync_cond_mutex); } @@ -296,7 +296,7 @@ int RPI_CreateWindow(_THIS, SDL_Window *window) /* Start generating vsync callbacks if necesary */ wdata->double_buffer = SDL_FALSE; if (SDL_GetHintBoolean(SDL_HINT_VIDEO_DOUBLE_BUFFER, SDL_FALSE)) { - wdata->vsync_cond = SDL_CreateCond(); + wdata->vsync_cond = SDL_CreateCondition(); wdata->vsync_cond_mutex = SDL_CreateMutex(); wdata->double_buffer = SDL_TRUE; vc_dispmanx_vsync_callback(displaydata->dispman_display, RPI_vsync_callback, (void *)wdata); @@ -322,12 +322,12 @@ void RPI_DestroyWindow(_THIS, SDL_Window *window) if (data->double_buffer) { /* Wait for vsync, and then stop vsync callbacks and destroy related stuff, if needed */ SDL_LockMutex(data->vsync_cond_mutex); - SDL_CondWait(data->vsync_cond, data->vsync_cond_mutex); + SDL_WaitCondition(data->vsync_cond, data->vsync_cond_mutex); SDL_UnlockMutex(data->vsync_cond_mutex); vc_dispmanx_vsync_callback(displaydata->dispman_display, NULL, NULL); - SDL_DestroyCond(data->vsync_cond); + SDL_DestroyCondition(data->vsync_cond); SDL_DestroyMutex(data->vsync_cond_mutex); } diff --git a/src/video/winrt/SDL_winrtevents.cpp b/src/video/winrt/SDL_winrtevents.cpp index 20d299daf..cc7c1ca16 100644 --- a/src/video/winrt/SDL_winrtevents.cpp +++ b/src/video/winrt/SDL_winrtevents.cpp @@ -78,11 +78,11 @@ static void WINRT_YieldXAMLThread() _threadState = ThreadState_Yielding; SDL_UnlockMutex(_mutex); - SDL_CondSignal(_cond); + SDL_SignalCondition(_cond); SDL_LockMutex(_mutex); while (_threadState != ThreadState_Running) { - SDL_CondWait(_cond, _mutex); + SDL_WaitCondition(_cond, _mutex); } SDL_UnlockMutex(_mutex); } @@ -101,7 +101,7 @@ void WINRT_CycleXAMLThread(void) switch (_threadState) { case ThreadState_NotLaunched: { - _cond = SDL_CreateCond(); + _cond = SDL_CreateCondition(); _mutex = SDL_CreateMutex(); _threadState = ThreadState_Running; @@ -109,7 +109,7 @@ void WINRT_CycleXAMLThread(void) SDL_LockMutex(_mutex); while (_threadState != ThreadState_Yielding) { - SDL_CondWait(_cond, _mutex); + SDL_WaitCondition(_cond, _mutex); } SDL_UnlockMutex(_mutex); @@ -129,11 +129,11 @@ void WINRT_CycleXAMLThread(void) _threadState = ThreadState_Running; SDL_UnlockMutex(_mutex); - SDL_CondSignal(_cond); + SDL_SignalCondition(_cond); SDL_LockMutex(_mutex); while (_threadState != ThreadState_Yielding) { - SDL_CondWait(_cond, _mutex); + SDL_WaitCondition(_cond, _mutex); } SDL_UnlockMutex(_mutex); } diff --git a/test/testatomic.c b/test/testatomic.c index 891f1ac45..7e08f7165 100644 --- a/test/testatomic.c +++ b/test/testatomic.c @@ -121,7 +121,7 @@ static int SDLCALL adder(void *junk) bad -= CountInc; } SDL_AtomicAdd(&threadsRunning, -1); - SDL_SemPost(threadDone); + SDL_PostSemaphore(threadDone); return 0; } @@ -141,7 +141,7 @@ static void runAdder(void) } while (SDL_AtomicGet(&threadsRunning) > 0) { - SDL_SemWait(threadDone); + SDL_WaitSemaphore(threadDone); } SDL_DestroySemaphore(threadDone); diff --git a/test/testsem.c b/test/testsem.c index a1706ca84..3931b6165 100644 --- a/test/testsem.c +++ b/test/testsem.c @@ -52,13 +52,13 @@ ThreadFuncRealWorld(void *data) { Thread_State *state = (Thread_State *)data; while (alive) { - SDL_SemWait(sem); + SDL_WaitSemaphore(sem); SDL_Log("Thread number %d has got the semaphore (value = %" SDL_PRIu32 ")!\n", - state->number, SDL_SemValue(sem)); + state->number, SDL_GetSemaphoreValue(sem)); SDL_Delay(200); - SDL_SemPost(sem); + SDL_PostSemaphore(sem); SDL_Log("Thread number %d has released the semaphore (value = %" SDL_PRIu32 ")!\n", - state->number, SDL_SemValue(sem)); + state->number, SDL_GetSemaphoreValue(sem)); ++state->loop_count; SDL_Delay(1); /* For the scheduler */ } @@ -114,7 +114,7 @@ TestWaitTimeout(void) SDL_Log("Waiting 2 seconds on semaphore\n"); start_ticks = SDL_GetTicks(); - retval = SDL_SemWaitTimeout(sem, 2000); + retval = SDL_WaitSemaphoreTimeout(sem, 2000); end_ticks = SDL_GetTicks(); duration = end_ticks - start_ticks; @@ -125,7 +125,7 @@ TestWaitTimeout(void) /* Check to make sure the return value indicates timed out */ if (retval != SDL_MUTEX_TIMEDOUT) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_SemWaitTimeout returned: %d; expected: %d\n\n", retval, SDL_MUTEX_TIMEDOUT); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_WaitSemaphoreTimeout returned: %d; expected: %d\n\n", retval, SDL_MUTEX_TIMEDOUT); } SDL_DestroySemaphore(sem); @@ -145,10 +145,10 @@ TestOverheadUncontended(void) start_ticks = SDL_GetTicks(); for (i = 0; i < NUM_OVERHEAD_OPS_MULT; i++) { for (j = 0; j < NUM_OVERHEAD_OPS; j++) { - SDL_SemPost(sem); + SDL_PostSemaphore(sem); } for (j = 0; j < NUM_OVERHEAD_OPS; j++) { - SDL_SemWait(sem); + SDL_WaitSemaphore(sem); } } end_ticks = SDL_GetTicks(); @@ -166,7 +166,7 @@ ThreadFuncOverheadContended(void *data) if (state->flag) { while (alive) { - if (SDL_SemTryWait(sem) == SDL_MUTEX_TIMEDOUT) { + if (SDL_TryWaitSemaphore(sem) == SDL_MUTEX_TIMEDOUT) { ++state->content_count; } ++state->loop_count; @@ -174,7 +174,7 @@ ThreadFuncOverheadContended(void *data) } else { while (alive) { /* Timeout needed to allow check on alive flag */ - if (SDL_SemWaitTimeout(sem, 50) == SDL_MUTEX_TIMEDOUT) { + if (SDL_WaitSemaphoreTimeout(sem, 50) == SDL_MUTEX_TIMEDOUT) { ++state->content_count; } ++state->loop_count; @@ -211,10 +211,10 @@ TestOverheadContended(SDL_bool try_wait) start_ticks = SDL_GetTicks(); for (i = 0; i < NUM_OVERHEAD_OPS_MULT; i++) { for (j = 0; j < NUM_OVERHEAD_OPS; j++) { - SDL_SemPost(sem); + SDL_PostSemaphore(sem); } /* Make sure threads consumed everything */ - while (SDL_SemValue(sem)) { + while (SDL_GetSemaphoreValue(sem)) { /* Friendlier with cooperative threading models */ SDL_DelayNS(1); }