3 #ifndef __CDS_OS_WIN_TIMER_H
4 #define __CDS_OS_WIN_TIMER_H
6 #ifndef __CDS_OS_TIMER_H
7 # error "<cds/os/timer.h> must be included"
13 namespace cds { namespace OS {
14 CDS_CXX11_INLINE_NAMESPACE namespace Win32 {
16 /// High resolution timer
18 Implementation of high resolution timer for Windows platforms.
19 The implementation build on QueryPerformanceCounter API.
23 typedef LARGE_INTEGER native_timer_type ; ///< Native timer type
24 typedef long long native_duration_type ; ///< Native duration type
27 native_timer_type m_nFrequency;
28 native_timer_type m_nStart;
33 ::QueryPerformanceFrequency( &m_nFrequency );
37 /// Places into \p tmr the current time in native Windows format
38 static void current( native_timer_type& tmr )
40 ::QueryPerformanceCounter( &tmr );
43 /// Returns current time in native Windows format
44 static native_timer_type current()
46 native_timer_type tmr;
51 /// Sets internal start time to current time. Returns duration from prevoius start time to current.
54 native_timer_type nCur;
56 double dblRet = double(nCur.QuadPart - m_nStart.QuadPart) / m_nFrequency.QuadPart;
57 m_nStart.QuadPart = nCur.QuadPart;
61 /// Translates \p dur from native format to seconds
62 double duration( native_duration_type dur )
64 return double( dur ) / m_nFrequency.QuadPart;
67 /// Returns duration (in seconds) from start time to current
70 return duration( native_duration() );
73 /// Returns duration (in native format) from start time to current
74 native_duration_type native_duration()
78 return native_duration( m_nStart, ts );
81 /// Calculates duration (in native format) between \p nEnd and \p nStart
82 static native_duration_type native_duration( const native_timer_type& nStart, const native_timer_type& nEnd )
84 return nEnd.QuadPart - nStart.QuadPart;
87 static unsigned long long random_seed()
89 return current().QuadPart;
96 #ifndef CDS_CXX11_INLINE_NAMESPACE_SUPPORT
97 typedef Win32::Timer Timer;
100 }} // namespae cds::OS
103 #endif // #ifndef __CDS_OS_WIN_TIMER_H