3 * - By John Hodge (thePowersGang)
6 * - Thread level event handling
9 #include <threads_int.h>
13 void Threads_PostEvent(tThread *Thread, Uint32 EventMask)
15 // TODO: Check that only one bit is set?
16 if( EventMask == 0 ) return ;
18 SHORTLOCK( &Thread->IsLocked );
20 Thread->EventState |= EventMask;
22 // Currently sleeping on an event?
23 if( Thread->Status == THREAD_STAT_EVENTSLEEP )
25 // Waiting on this event?
26 if( (Uint32)Thread->RetStatus & EventMask )
29 // TODO: Does it matter if the thread is locked here?
30 Threads_AddActive(Thread);
34 SHORTREL( &Thread->IsLocked );
37 Uint32 Threads_WaitEvents(Uint32 EventMask)
40 tThread *us = Proc_GetCurThread();
48 // Check if a wait is needed
49 SHORTLOCK( &us->IsLocked );
50 if( !(us->EventState & EventMask) )
53 us->RetStatus = EventMask; // HACK: Store EventMask in RetStatus
54 SHORTLOCK( &glThreadListLock );
55 us = Threads_RemActive();
56 us->Status = THREAD_STAT_EVENTSLEEP;
57 SHORTREL( &glThreadListLock );
58 SHORTREL( &us->IsLocked );
59 while(us->Status == THREAD_STAT_MUTEXSLEEP) Threads_Yield();
60 // Woken when lock is acquired
61 SHORTLOCK( &us->IsLocked );
64 // Get return value and clear changed event bits
65 rv = us->EventState & EventMask;
66 us->EventState &= ~EventMask;
68 SHORTREL( &us->IsLocked );