// virtual void TITthread::OnStart() { while (mRunning) { mThread.MsSleep(10); { nglCriticalSectionGuard guard(mRunCS); mLockedA = false; mLockedB = false; mLockedC = false; if (!WaitForLock()) continue; // will block 'til the blocked cs while (mLockedA || mLockedB || mLockedC) { mThread.MsSleep(10); if (!WaitForLockOrUnlock()) continue; } } } }
/** \fn SignalMonitor::WaitForLock(int) * \brief Wait for a StatusSignaLock(int) of true. * * This can be called whether or not the signal * monitoring thread has been started. * * \param timeout maximum time to wait in milliseconds. * \return true if signal was acquired. */ bool SignalMonitor::WaitForLock(int timeout) { statusLock.lock(); if (-1 == timeout) timeout = signalLock.GetTimeout(); statusLock.unlock(); if (timeout<0) return false; MythTimer t; t.start(); if (running) { while (t.elapsed()<timeout && running) { Kick(); statusLock.lock(); bool ok = signalLock.IsGood(); statusLock.unlock(); if (ok) return true; usleep(50); } if (!running) return WaitForLock(timeout-t.elapsed()); } else { while (t.elapsed()<timeout && !running) { UpdateValues(); statusLock.lock(); bool ok = signalLock.IsGood(); statusLock.unlock(); if (ok) return true; usleep(50); } if (running) return WaitForLock(timeout-t.elapsed()); } return false; }