void ZCallScheduler::pRun() { ZGuardMtx guard(fMtx); for (;;) { if (fTimeJobs.empty()) { // Nothing pending, wait 100ms in case something else comes along. fCnd.WaitFor(fMtx, 100e-3); if (fTimeJobs.empty()) { // Still nothing pending, exit thread. fThreadRunning = false; break; } } else { const set<TimeJob>::iterator& begin = fTimeJobs.begin(); const double delta = begin->first - ZTime::sSystem(); if (delta > 0) { fCnd.WaitFor(fMtx, delta); } else { ZRef<ZCaller> theCaller = begin->second.first; ZRef<ZCallable_Void> theCallable = begin->second.second; sEraseMust(fJobTimes, JobTime(begin->second, begin->first)); fTimeJobs.erase(begin); guard.Release(); try { theCaller->Enqueue(theCallable); } catch (...) {} guard.Acquire(); } } } }