void Worker::_Work() { while (true) { MutexLocker locker(fLock); Task* task = fTasks.First(); if (task == NULL) return; Job* job = task->NextJob(); if (job == NULL) { fTasks.Remove(task); return; } locker.Unlock(); job->Do(); task->JobDone(job); } }
status_t Volume::_PackageLoader() { while (!fTerminating) { MutexLocker jobQueueLocker(fJobQueueLock); Job* job = fJobQueue.RemoveHead(); if (job == NULL) { // no job yet -- wait for someone notifying us ConditionVariableEntry waitEntry; fJobQueueCondition.Add(&waitEntry); jobQueueLocker.Unlock(); waitEntry.Wait(); continue; } // do the job jobQueueLocker.Unlock(); job->Do(); delete job; } return B_OK; }