Added Condition Variables to thread library

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@383 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
mcmartin
2002-12-09 04:01:34 +00:00
parent c1c1c73e39
commit 864e86dc09
6 changed files with 58 additions and 1 deletions
+6 -1
View File
@@ -83,7 +83,6 @@ extern Thread CreateThreadAux (ThreadFunction func, void *data,
# define CreateThread(func, data, stackSize, name) \
CreateThreadAux ((func), (data), (stackSize))
#endif /* !defined(THREAD_NAMES) */
extern void KillThread (Thread thread);
extern void SleepThread (TimePeriod timePeriod);
extern void SleepThreadUntil (TimeCount wakeTime);
extern void TaskSwitch (void);
@@ -106,6 +105,12 @@ extern void DestroyMutex (Mutex sem);
extern int LockMutex (Mutex sem);
extern void UnlockMutex (Mutex sem);
typedef void *CondVar;
extern CondVar CreateCondVar (void);
extern void DestroyCondVar (CondVar);
extern void WaitCondVar (CondVar);
extern void SignalCondVar (CondVar);
extern void BroadcastCondVar (CondVar);
#endif /* _THREADLIB_H */
@@ -66,3 +66,15 @@ SDLWrapper_TaskSwitch (void) {
SDL_Delay (1);
}
void
SDLWrapper_WaitCondVar (CondVar cv) {
int result;
Mutex temp = CreateMutex ();
LockMutex (temp);
result = SDL_CondWait (cv, temp);
UnlockMutex (temp);
DestroyMutex (temp);
if (result != 0) {
fprintf (stderr, "Error result from SDL_CondWait: %d\n", result);
}
}
@@ -77,5 +77,18 @@ typedef SDL_mutex *NativeMutex;
#define NativeUnlockMutex(mutex) \
SDL_mutexV ((mutex))
typedef SDL_cond *NativeCondVar;
#define NativeCreateCondVar() \
SDL_CreateCond ()
#define NativeDestroyCondVar(condvar) \
SDL_DestroyCond((condvar))
#define NativeWaitCondVar(condvar) \
SDLWrapper_WaitCondVar((condvar))
#define NativeSignalCondVar(condvar) \
SDL_CondSignal((condvar))
#define NativeBroadcastCondVar(condvar) \
SDL_CondBroadcast((condvar))
#endif /* _SDLTHREAD_H */
+23
View File
@@ -353,4 +353,27 @@ UnlockMutex (Mutex sem)
NativeUnlockMutex ((NativeMutex) sem);
}
CondVar
CreateCondVar ()
{
return NativeCreateCondVar ();
}
void DestroyCondVar (CondVar cv)
{
NativeDestroyCondVar (cv);
}
void WaitCondVar (CondVar cv)
{
NativeWaitCondVar (cv);
}
void SignalCondVar (CondVar cv)
{
NativeSignalCondVar (cv);
}
void BroadcastCondVar (CondVar cv)
{
NativeBroadcastCondVar (cv);
}