Kernel/x86 - Clean up some of the task switching code (possibly a little broken)
[tpg/acess2.git] / KernelLand / Kernel / events.c
index 2b39714..a572d43 100644 (file)
@@ -7,8 +7,8 @@
  */
 #define DEBUG  0
 #include <acess.h>
-#include <threads_int.h>
 #include <events.h>
+#include <threads_int.h>
 
 // === CODE ===
 void Threads_PostEvent(tThread *Thread, Uint32 EventMask)
@@ -83,10 +83,13 @@ Uint32 Threads_WaitEvents(Uint32 EventMask)
        // Check if a wait is needed
        SHORTLOCK( &us->IsLocked );
        LOG("Locked and preparing for wait");
-       Threads_int_Sleep(THREAD_STAT_EVENTSLEEP, NULL, EventMask,
-               &us, NULL, &us->IsLocked);
-       // Woken when lock is acquired
-       SHORTLOCK( &us->IsLocked );
+       if( (us->EventState & EventMask) == 0 )
+       {
+               Threads_int_Sleep(THREAD_STAT_EVENTSLEEP, NULL, EventMask,
+                       &us, NULL, &us->IsLocked);
+               // Woken when an event fires
+               SHORTLOCK( &us->IsLocked );
+       }
        
        // Get return value and clear changed event bits
        rv = us->EventState & EventMask;

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