bool RunWhile(Service& s,bool (*condition)()) { if(!s.OnStart()) return false; while(condition()) { int n=s.Process(); if(g_doKillService) break; if(n < 0) { if(!s.tolerateReadErrors) { s.OnStop(); return false; } else ThreadSleep(s.waitTime); } if(n == 0) { if(s.sleepTime<=0) ThreadYield(); else ThreadSleep(s.sleepTime); } } s.OnStop(); return true; }
void NetworkManager::Process(void) { // Get the current count of Services to be processed. We can't just check to see if the queue is empty, since // the other threads could keep placing more Service objects in the queue, and this could cause a stall in the // main thread. Service* service = 0; uint32 serviceCount = mServiceProcessQueue.size(); for(uint32 i = 0; i < serviceCount; i++) { // Grab our next Service to process service = mServiceProcessQueue.pop(); if(service) { service->Process(); service->setQueued(false); } } }