Rename SDL semaphore and condition variable functions to match SDL 3.0 naming convention
Fixes https://github.com/libsdl-org/SDL/issues/7642
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user