AcessNative - Implemented events, don't trust them
[tpg/acess2.git] / AcessNative / acesskernel_src / threads.c
index 1e7d0c3..a39fb5e 100644 (file)
@@ -70,6 +70,9 @@ typedef struct sThread
 
        tProcess        *Process;       
 
+       Uint32  Events, WaitMask;
+       SDL_sem *EventSem;
+
 }      tThread;
 
 // === PROTOTYPES ===
@@ -359,3 +362,23 @@ int Semaphore_Signal(tSemaphore *Sem, int AmmountToAdd)
        return AmmountToAdd;
 }
 
+Uint32 Threads_WaitEvents(Uint32 Mask)
+{
+       Uint32  rv;
+       gpCurrentThread->WaitMask = Mask;
+       if( !(gpCurrentThread->Events & Mask) )
+               SDL_SemWait( gpCurrentThread->EventSem );
+       rv = gpCurrentThread->Events & Mask;
+       gpCurrentThread->Events &= ~Mask;
+       gpCurrentThread->WaitMask = -1;
+       return rv;
+}
+
+void Threads_PostEvent(tThread *Thread, Uint32 Events)
+{
+       Thread->Events |= Events;
+       
+       if( Thread->WaitMask & Events )
+               SDL_SemPost( gpCurrentThread->EventSem );
+}
+

UCC git Repository :: git.ucc.asn.au