|
@@ -52,9 +52,9 @@ typedef struct SDL_cond_generic
|
|
|
/* Create a condition variable */
|
|
|
SDL_Condition *SDL_CreateCondition_generic(void)
|
|
|
{
|
|
|
- SDL_cond_generic *cond;
|
|
|
+ SDL_cond_generic *cond = (SDL_cond_generic *)SDL_calloc(1, sizeof(*cond));
|
|
|
|
|
|
- cond = (SDL_cond_generic *)SDL_malloc(sizeof(SDL_cond_generic));
|
|
|
+#ifndef SDL_THREADS_DISABLED
|
|
|
if (cond) {
|
|
|
cond->lock = SDL_CreateMutex();
|
|
|
cond->wait_sem = SDL_CreateSemaphore(0);
|
|
@@ -65,6 +65,8 @@ SDL_Condition *SDL_CreateCondition_generic(void)
|
|
|
cond = NULL;
|
|
|
}
|
|
|
}
|
|
|
+#endif
|
|
|
+
|
|
|
return (SDL_Condition *)cond;
|
|
|
}
|
|
|
|
|
@@ -94,6 +96,7 @@ int SDL_SignalCondition_generic(SDL_Condition *_cond)
|
|
|
return SDL_InvalidParamError("cond");
|
|
|
}
|
|
|
|
|
|
+#ifndef SDL_THREADS_DISABLED
|
|
|
/* If there are waiting threads not already signalled, then
|
|
|
signal the condition and wait for the thread to respond.
|
|
|
*/
|
|
@@ -106,6 +109,7 @@ int SDL_SignalCondition_generic(SDL_Condition *_cond)
|
|
|
} else {
|
|
|
SDL_UnlockMutex(cond->lock);
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -118,6 +122,7 @@ int SDL_BroadcastCondition_generic(SDL_Condition *_cond)
|
|
|
return SDL_InvalidParamError("cond");
|
|
|
}
|
|
|
|
|
|
+#ifndef SDL_THREADS_DISABLED
|
|
|
/* If there are waiting threads not already signalled, then
|
|
|
signal the condition and wait for the thread to respond.
|
|
|
*/
|
|
@@ -140,6 +145,7 @@ int SDL_BroadcastCondition_generic(SDL_Condition *_cond)
|
|
|
} else {
|
|
|
SDL_UnlockMutex(cond->lock);
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -168,12 +174,13 @@ Thread B:
|
|
|
int SDL_WaitConditionTimeoutNS_generic(SDL_Condition *_cond, SDL_Mutex *mutex, Sint64 timeoutNS)
|
|
|
{
|
|
|
SDL_cond_generic *cond = (SDL_cond_generic *)_cond;
|
|
|
- int retval;
|
|
|
+ int retval = 0;
|
|
|
|
|
|
if (!cond) {
|
|
|
return SDL_InvalidParamError("cond");
|
|
|
}
|
|
|
|
|
|
+#ifndef SDL_THREADS_DISABLED
|
|
|
/* Obtain the protection mutex, and increment the number of waiters.
|
|
|
This allows the signal mechanism to only perform a signal if there
|
|
|
are waiting threads.
|
|
@@ -211,6 +218,7 @@ int SDL_WaitConditionTimeoutNS_generic(SDL_Condition *_cond, SDL_Mutex *mutex, S
|
|
|
|
|
|
/* Lock the mutex, as is required by condition variable semantics */
|
|
|
SDL_LockMutex(mutex);
|
|
|
+#endif
|
|
|
|
|
|
return retval;
|
|
|
}
|