- gpCurrentThread->State = 3;
- if( setjmp(&gpCurrentThread->CurState) == 0 ) {
- // Return to user wait
- // Hmm... maybe I should have a "kernel" thread for every "user" thread
- }
- else {
- // Just woken up, return
- return ;
+ memset(Sem, 0, sizeof(tSemaphore));
+ // HACK: Use `Sem->Protector` as space for the semaphore pointer
+ Threads_Glue_SemInit( &Sem->Protector.Mutex, InitValue );
+}
+
+int Semaphore_Wait(tSemaphore *Sem, int MaxToTake)
+{
+ return Threads_Glue_SemWait( Sem->Protector.Mutex, MaxToTake );
+}
+
+int Semaphore_Signal(tSemaphore *Sem, int AmmountToAdd)
+{
+ return Threads_Glue_SemSignal( Sem->Protector.Mutex, AmmountToAdd );
+}
+
+// --------------------------------------------------------------------
+// Event handling
+// --------------------------------------------------------------------
+Uint32 Threads_WaitEvents(Uint32 Mask)
+{
+ Uint32 rv;
+
+ //Log_Debug("Threads", "Mask = %x, ->Events = %x", Mask, gpCurrentThread->Events);
+
+ gpCurrentThread->WaitMask = Mask;
+ if( !(gpCurrentThread->Events & Mask) )
+ {
+ if( Threads_Glue_SemWait(gpCurrentThread->EventSem, INT_MAX) == -1 ) {
+ Log_Warning("Threads", "Wait on eventsem of %p, %p failed",
+ gpCurrentThread, gpCurrentThread->EventSem);
+ }
+ //Log_Debug("Threads", "Woken from nap (%i here)", SDL_SemValue(gpCurrentThread->EventSem));