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:
Sam Lantinga
2023-04-27 20:49:54 -07:00
parent 170c410d35
commit 61c0c009ab
45 changed files with 458 additions and 362 deletions

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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 */

View File

@@ -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 */

View File

@@ -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. */

View File

@@ -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);

View File

@@ -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;

View File

@@ -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");

View File

@@ -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");

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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

View File

@@ -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;

View File

@@ -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");

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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);
}