mirror of https://github.com/encounter/SDL.git
switch: update for latest libnx
This commit is contained in:
parent
43be1d5030
commit
9e06af0445
|
@ -33,10 +33,14 @@
|
|||
|
||||
struct SDL_cond
|
||||
{
|
||||
Mutex mutex;
|
||||
CondVar var;
|
||||
};
|
||||
|
||||
struct SDL_mutex
|
||||
{
|
||||
RMutex mtx;
|
||||
};
|
||||
|
||||
/* Create a condition variable */
|
||||
SDL_cond *
|
||||
SDL_CreateCond(void)
|
||||
|
@ -45,8 +49,7 @@ SDL_CreateCond(void)
|
|||
|
||||
cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
|
||||
if (cond) {
|
||||
mutexInit(&cond->mutex);
|
||||
condvarInit(&cond->var, &cond->mutex);
|
||||
condvarInit(&cond->var);
|
||||
}
|
||||
else {
|
||||
SDL_OutOfMemory();
|
||||
|
@ -113,17 +116,22 @@ Thread B:
|
|||
int
|
||||
SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
|
||||
{
|
||||
uint32_t mutex_state[2];
|
||||
|
||||
if (!cond) {
|
||||
return SDL_SetError("Passed a NULL condition variable");
|
||||
}
|
||||
|
||||
/* Unlock the mutex, as is required by condition variable semantics */
|
||||
SDL_UnlockMutex(mutex);
|
||||
// backup mutex state
|
||||
mutex_state[0] = mutex->mtx.thread_tag;
|
||||
mutex_state[1] = mutex->mtx.counter;
|
||||
mutex->mtx.thread_tag = 0;
|
||||
mutex->mtx.counter = 0;
|
||||
|
||||
condvarWaitTimeout(&cond->var, ms * 1000000);
|
||||
condvarWaitTimeout(&cond->var, &mutex->mtx.lock, ms * 1000000);
|
||||
|
||||
/* Lock the mutex, as is required by condition variable semantics */
|
||||
SDL_LockMutex(mutex);
|
||||
mutex->mtx.thread_tag = mutex_state[0];
|
||||
mutex->mtx.counter = mutex_state[1];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue