3 * - By John Hodge (thePowersGang)
6 * - Worker FIFO Queue (Single Consumer, Interrupt Producer)
10 #include <threads_int.h>
12 #define QUEUENEXT(ptr) (*( (void**)(ptr) + Queue->NextOffset/sizeof(void*) ))
15 void Workqueue_Init(tWorkqueue *Queue, const char *Name, size_t NextOfset)
18 Queue->NextOffset = NextOfset;
21 void *Workqueue_GetWork(tWorkqueue *Queue)
28 SHORTLOCK(&Queue->Protector);
31 void *ret = Queue->Head;
32 Queue->Head = QUEUENEXT( ret );
33 if(Queue->Tail == ret)
35 SHORTREL(&Queue->Protector);
40 SHORTLOCK(&glThreadListLock);
41 us = Threads_RemActive();
42 us->WaitPointer = Queue;
43 us->Status = THREAD_STAT_QUEUESLEEP;
45 SHORTREL(&Queue->Protector);
46 SHORTREL(&glThreadListLock);
49 Threads_int_WaitForStatusEnd(THREAD_STAT_QUEUESLEEP);
51 us->WaitPointer = NULL;
55 void Workqueue_AddWork(tWorkqueue *Queue, void *Ptr)
57 SHORTLOCK(&Queue->Protector);
60 QUEUENEXT(Queue->Tail) = Ptr;
64 QUEUENEXT(Ptr) = NULL;
68 if( Queue->Sleeper->Status != THREAD_STAT_ACTIVE )
69 Threads_AddActive(Queue->Sleeper);
70 Queue->Sleeper = NULL;
72 SHORTREL(&Queue->Protector);