void CDVDMsgGeneralSynchronize::Wait(volatile bool *abort, DWORD source) { /* if we are not requested to wait on this object just return, reference count will be decremented */ if (source && !(m_sources & source)) return; InterlockedIncrement(&m_objects); DWORD timeout = CTimeUtils::GetTimeMS() + m_timeout; if (abort) while( m_objects < GetNrOfReferences() && timeout > CTimeUtils::GetTimeMS() && !(*abort)) Sleep(1); else while( m_objects < GetNrOfReferences() && timeout > CTimeUtils::GetTimeMS() ) Sleep(1); }
bool CDVDMsgGeneralSynchronize::Wait(unsigned long milliseconds, unsigned int source) { if(source == 0) source = SYNCSOURCE_OWNER; /* if we are not requested to wait on this object just return, reference count will be decremented */ if (!(m_p->sources & source)) return true; CSingleLock lock(m_p->section); XbmcThreads::EndTime timeout(milliseconds); m_p->reached |= source & m_p->sources; while( (long)MathUtils::bitcount(m_p->reached) < GetNrOfReferences() ) { milliseconds = std::min(m_p->timeout.MillisLeft(), timeout.MillisLeft()); if(m_p->condition.wait(lock, milliseconds)) continue; if(m_p->timeout.IsTimePast()) return true; /* global timeout, we are done */ if(timeout.IsTimePast()) return false; /* request timeout, should be retried */ } return true; }