3 #ifndef CDSLIB_OS_SUNOS_TIMER_H
4 #define CDSLIB_OS_SUNOS_TIMER_H
6 #ifndef CDSLIB_OS_TIMER_H
7 # error "<cds/os/timer.h> must be included"
13 namespace cds { namespace OS {
14 CDS_CXX11_INLINE_NAMESPACE namespace Sun {
16 // High resolution timer
20 typedef hrtime_t native_timer_type;
21 typedef long long native_duration_type;
23 Timer() : m_tmStart( current() ) {}
25 static native_timer_type current() { return gethrtime(); }
26 static void current( native_timer_type& tmr ) { tmr = gethrtime(); }
30 native_timer_type tt = current();
31 double ret = (tt - m_tmStart) / 1.0E9; //gethrtime() freq = nanoseconds
36 double duration( native_duration_type dur )
38 return double( dur ) / 1.0E9;
43 return duration( native_duration() );
46 native_duration_type native_duration()
48 return native_duration( m_tmStart, current() );
51 static native_duration_type native_duration( native_timer_type nStart, native_timer_type nEnd )
53 return native_duration_type( nEnd - nStart );
56 static unsigned long long random_seed()
58 return (unsigned long long) current();
64 #ifndef CDS_CXX11_INLINE_NAMESPACE_SUPPORT
65 typedef Sun::Timer Timer;
68 }} // namespace cds::OS
71 #endif // #ifndef CDSLIB_OS_SUNOS_TIMER_H