19 #pragma warning(disable:4355)
24 __deref_out
void ** ppv)
28 if (
riid == IID_IReferenceClock)
32 else if (
riid == IID_IReferenceClockTimerControl)
46 PERFLOG_DTOR( L
"CBaseReferenceClock", (IReferenceClock *)
this );
49 if (m_TimerResolution) timeEndPeriod(m_TimerResolution);
60 WaitForSingleObject( m_hThread, INFINITE );
72 __inout_opt LPUNKNOWN pUnk,
77 , m_TimerResolution(0)
96 m_TimerResolution = (TIMERR_NOERROR == timeGetDevCaps(&tc,
sizeof(tc)))
100 timeBeginPeriod(m_TimerResolution);
103 m_dwPrevSystemTime = timeGetTime();
107 m_idGetSystemTime =
MSR_REGISTER(TEXT(
"CBaseReferenceClock::GetTime"));
113 m_hThread = ::CreateThread(
NULL,
115 AdviseThreadFunction,
122 SetThreadPriority( m_hThread, THREAD_PRIORITY_TIME_CRITICAL );
138 m_rtLastGotTime = rtMinTime ;
147 REFERENCE_TIME rtNow;
150 if (rtNow > m_rtLastGotTime)
152 m_rtLastGotTime = rtNow;
159 *pTime = m_rtLastGotTime;
176 REFERENCE_TIME baseTime,
177 REFERENCE_TIME streamTime,
179 __out DWORD_PTR *pdwAdviseCookie)
182 *pdwAdviseCookie = 0;
185 ASSERT(WAIT_TIMEOUT == WaitForSingleObject(
HANDLE(hEvent),0));
189 const REFERENCE_TIME lRefTime = baseTime + streamTime;
190 if ( lRefTime <= 0 || lRefTime ==
MAX_TIME )
197 hr = *pdwAdviseCookie ? NOERROR : E_OUTOFMEMORY;
206 REFERENCE_TIME StartTime,
207 REFERENCE_TIME PeriodTime,
208 HSEMAPHORE hSemaphore,
209 __out DWORD_PTR *pdwAdviseCookie)
212 *pdwAdviseCookie = 0;
215 if (StartTime > 0 && PeriodTime > 0 && StartTime !=
MAX_TIME )
218 hr = *pdwAdviseCookie ? NOERROR : E_OUTOFMEMORY;
220 else hr = E_INVALIDARG;
244 DWORD dwTime = timeGetTime();
246 m_rtPrivateTime += Int32x32To64(
UNITS /
MILLISECONDS, (DWORD)(dwTime - m_dwPrevSystemTime));
247 m_dwPrevSystemTime = dwTime;
250 return m_rtPrivateTime;
269 LONGLONG llDelta = TimeDelta > 0 ? TimeDelta : -TimeDelta;
270 if (llDelta >
UNITS * 1000) {
278 const LONG usDelta = LONG(TimeDelta/10);
280 DWORD delta = abs(usDelta);
291 TEXT(
"Sev %2i: CSystemClock::SetTimeDelta(%8ld us) %lu -> %lu ms."),
296 #ifdef BREAK_ON_SEVERE_TIME_DELTA
298 DbgBreakPoint(TEXT(
"SetTimeDelta > 16 seconds!"),
299 TEXT(__FILE__),__LINE__);
305 m_rtPrivateTime += TimeDelta;
319 DWORD __stdcall CBaseReferenceClock::AdviseThreadFunction(__in LPVOID p)
324 HRESULT CBaseReferenceClock::AdviseThread()
326 DWORD dwWait = INFINITE;
337 DbgLog((
LOG_TIMING, 3, TEXT(
"CBaseRefClock::AdviseThread() Delay: %lu ms"), dwWait ));
349 TEXT(
"CBaseRefClock::AdviseThread() Woke at = %lu ms"),
356 LONGLONG llWait = m_rtNextAdvise - rtNow;
362 dwWait = (llWait > REFERENCE_TIME(UINT_MAX)) ? UINT_MAX : DWORD(llWait);
368 REFERENCE_TIME timerResolution
372 if( 0 == timerResolution ) {
373 if( m_TimerResolution ) {
374 timeEndPeriod( m_TimerResolution );
375 m_TimerResolution = 0;
379 DWORD dwMinResolution = (TIMERR_NOERROR == timeGetDevCaps(&tc,
sizeof(tc)))
382 DWORD dwResolution = max( dwMinResolution, DWORD(timerResolution / 10000) );
383 if( dwResolution != m_TimerResolution ) {
384 timeEndPeriod(m_TimerResolution);
385 m_TimerResolution = dwResolution;
386 timeBeginPeriod( m_TimerResolution );
393 __out REFERENCE_TIME* pTimerResolution
396 if( !pTimerResolution ) {
400 *pTimerResolution = m_TimerResolution * 10000;