X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Fworkqueue.c;h=f5d78f80511a82401f5a51ea0c5afed9ce59768f;hb=d8238c6af5d96fb4c3638a253d16fb497f865f16;hp=2cd6a2581a86e94fd81753db64a63277f7daa481;hpb=083c31409b9f25c96807ab8fef8ac79e8fe4cf9e;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/workqueue.c b/KernelLand/Kernel/workqueue.c index 2cd6a258..f5d78f80 100644 --- a/KernelLand/Kernel/workqueue.c +++ b/KernelLand/Kernel/workqueue.c @@ -16,12 +16,12 @@ void Workqueue_Init(tWorkqueue *Queue, const char *Name, size_t NextOfset) { Queue->Name = Name; Queue->NextOffset = NextOfset; + Queue->Sleeper = NULL; + Queue->SleepTail = NULL; } void *Workqueue_GetWork(tWorkqueue *Queue) { - tThread *us; - for( ;; ) { // Check for work @@ -36,19 +36,9 @@ void *Workqueue_GetWork(tWorkqueue *Queue) return ret; } - // Go to sleep - SHORTLOCK(&glThreadListLock); - us = Threads_RemActive(); - us->WaitPointer = Queue; - us->Status = THREAD_STAT_QUEUESLEEP; - Queue->Sleeper = us; - SHORTREL(&Queue->Protector); - SHORTREL(&glThreadListLock); - - // Yield and sleep - Threads_int_WaitForStatusEnd(THREAD_STAT_QUEUESLEEP); - - us->WaitPointer = NULL; + Threads_int_Sleep(THREAD_STAT_QUEUESLEEP, + Queue, 0, + &Queue->Sleeper, &Queue->SleepTail, &Queue->Protector); } } @@ -65,9 +55,12 @@ void Workqueue_AddWork(tWorkqueue *Queue, void *Ptr) if( Queue->Sleeper ) { - if( Queue->Sleeper->Status != THREAD_STAT_ACTIVE ) - Threads_AddActive(Queue->Sleeper); - Queue->Sleeper = NULL; + ASSERTC( Queue->Sleeper->Status, !=, THREAD_STAT_ACTIVE ); + tThread *next_sleeper = Queue->Sleeper->Next; + Threads_AddActive(Queue->Sleeper); + Queue->Sleeper = next_sleeper; + if(!next_sleeper) + Queue->SleepTail = NULL; } SHORTREL(&Queue->Protector); }