3 * - By John Hodge (thePowersGang)
6 * - Worker FIFO Queue (Single Consumer, Interrupt Producer)
10 #include <threads_int.h>
13 void Workqueue_Init(tWorkqueue *Queue, const char *Name, size_t NextOfset)
16 Queue->NextOffset = NextOfset;
19 void *Workqueue_GetWork(tWorkqueue *Queue)
26 SHORTLOCK(&Queue->Protector);
29 void *ret = Queue->Head;
30 Queue->Head = *( (void**)ret + Queue->NextOffset/sizeof(void*) );
31 if(Queue->Tail == ret)
33 SHORTREL(&Queue->Protector);
38 SHORTLOCK(&glThreadListLock);
39 us = Threads_RemActive();
40 us->WaitPointer = Queue;
41 us->Status = THREAD_STAT_QUEUESLEEP;
43 SHORTREL(&Queue->Protector);
44 SHORTREL(&glThreadListLock);
48 if(us->Status == THREAD_STAT_QUEUESLEEP) {
52 us->WaitPointer = NULL;
56 void Workqueue_AddWork(tWorkqueue *Queue, void *Ptr)
58 SHORTLOCK(&Queue->Protector);
61 *( (void**)Queue->Tail + Queue->NextOffset/sizeof(void*) ) = Ptr;
68 if( Queue->Sleeper->Status != THREAD_STAT_ACTIVE )
69 Threads_AddActive(Queue->Sleeper);
70 Queue->Sleeper = NULL;
72 SHORTREL(&Queue->Protector);