X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Fevents.c;h=ec47a169e543856c787cd99e097413858e2a0d2d;hb=3c3c26b58055f511af5b7f0c3ab22e83961c775f;hp=a9eab7865e86244ded7a8cf9dd08bbcf529e7678;hpb=48743e39650eb1ef988380e9d95f27fd40d3a9ce;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/events.c b/KernelLand/Kernel/events.c index a9eab786..ec47a169 100644 --- a/KernelLand/Kernel/events.c +++ b/KernelLand/Kernel/events.c @@ -7,8 +7,8 @@ */ #define DEBUG 0 #include -#include #include +#include // === CODE === void Threads_PostEvent(tThread *Thread, Uint32 EventMask) @@ -26,21 +26,41 @@ void Threads_PostEvent(tThread *Thread, Uint32 EventMask) LOG("Thread->EventState = 0x%x", Thread->EventState); // Currently sleeping on an event? - if( Thread->Status == THREAD_STAT_EVENTSLEEP ) + switch(Thread->Status) { - // Waiting on this event? + // Waiting on this event? + case THREAD_STAT_EVENTSLEEP: if( (Uint32)Thread->RetStatus & EventMask ) { // Wake up LOG("Waking thread %p(%i %s)", Thread, Thread->TID, Thread->ThreadName); Threads_AddActive(Thread); } + break; + case THREAD_STAT_SEMAPHORESLEEP: + if( EventMask & THREAD_EVENT_TIMER ) + { + LOG("Waking %p(%i %s) from semaphore on timer", + Thread, Thread->TID, Thread->ThreadName); + Semaphore_ForceWake(Thread); + } + break; + default: + break; } SHORTREL( &Thread->IsLocked ); LEAVE('-'); } +/** + * \brief Clear an event without waiting + */ +void Threads_ClearEvent(Uint32 EventMask) +{ + Proc_GetCurThread()->EventState &= ~EventMask; +} + /** * \brief Wait for an event to occur */ @@ -62,18 +82,11 @@ Uint32 Threads_WaitEvents(Uint32 EventMask) // Check if a wait is needed SHORTLOCK( &us->IsLocked ); - while( !(us->EventState & EventMask) ) + LOG("Locked and preparing for wait"); + if( (us->EventState & EventMask) == 0 ) { - LOG("Locked and preparing for wait"); - // Wait - us->RetStatus = EventMask; // HACK: Store EventMask in RetStatus - SHORTLOCK( &glThreadListLock ); - us = Threads_RemActive(); - us->Status = THREAD_STAT_EVENTSLEEP; - // Note stored anywhere because we're woken using other means - SHORTREL( &glThreadListLock ); - SHORTREL( &us->IsLocked ); - while(us->Status == THREAD_STAT_EVENTSLEEP) Threads_Yield(); + Threads_int_Sleep(THREAD_STAT_EVENTSLEEP, NULL, EventMask, + &us, NULL, &us->IsLocked); // Woken when lock is acquired SHORTLOCK( &us->IsLocked ); }