3 * - By John Hodge (thePowersGang)
6 * - Thread level event handling
9 #include <threads_int.h>
13 void Threads_PostEvent(tThread *Thread, int EventID)
15 if( EventID < 0 || EventID > N_EVENTS )
20 SHORTLOCK( Thread->IsLocked );
22 Thread->EventState |= 1 << EventID;
24 // Currently sleeping on an event?
25 if( Thread->State == THREAD_STAT_EVENTSLEEP )
27 // Waiting on this event?
28 if( (Uint32)Thread->RetStatus & (1 << EventID) )
31 Threads_AddActive(Thread);
35 SHORTREL( Thread->IsLocked );
38 Uint32 Threads_WaitEvents(Uint32 EventMask)
41 tThread *us = Proc_GetCurThread();
49 // Check if a wait is needed
50 SHORTLOCK( &us->IsLocked );
51 if( !(us->EventState & EventMask) )
54 us->RetStatus = EventMask; // HACK: Store EventMask in RetStatus
55 SHORTLOCK( &glThreadListLock );
56 us = Threads_RemActive();
57 us->Status = THREAD_STAT_EVENTSLEEP;
58 SHORTREL( &glThreadListLock );
59 SHORTREL( &us->IsLocked );
60 while(us->Status == THREAD_STAT_MUTEXSLEEP) Threads_Yield();
61 // Woken when lock is acquired
62 SHORTLOCK( &us->IsLocked );
65 // Get return value and clear changed event bits
66 rv = us->EventState & EventMask;
67 us->EventState &= ~EventMask;
69 SHORTREL( us->IsLocked );