3 #ifndef CDSLIB_OS_AIX_TIMER_H
4 #define CDSLIB_OS_AIX_TIMER_H
6 // Source: http://publib16.boulder.ibm.com/doc_link/en_US/a_doc_lib/libs/basetrf2/read_real_time.htm
8 #ifndef CDSLIB_OS_TIMER_H
9 # error "<cds/os/timer.h> must be included"
13 #include <sys/systemcfg.h>
16 namespace cds { namespace OS {
17 CDS_CXX11_INLINE_NAMESPACE namespace Aix {
19 // High resolution timer
21 timebasestruct_t m_tmStart;
24 static unsigned long long nano( native_timer_type const& nStart, native_timer_type const& nEnd )
26 return (((unsigned long long) (nEnd.tb_high - nStart.tb_high)) << 32) + (nEnd.tb_low - nStart.tb_low);
30 typedef timebasestruct_t native_timer_type;
31 typedef long long native_duration_type;
33 Timer() : m_tmStart( current() ) {}
35 static native_timer_type current()
41 static void current( native_timer_type& tmr )
43 read_real_time( &tmr, sizeof(tmr) );
44 time_base_to_time( &tmr, sizeof(tmr ));
51 double ret = nano( m_tmStart, tt ) / 1.0E9;
56 double duration( native_duration_type dur )
58 return double( dur ) / 1.0E9;
63 return duration( native_duration() );
66 native_duration_type native_duration()
68 return native_duration( m_tmStart, current() );
71 static native_duration_type native_duration( native_timer_type const & nStart, native_timer_type const & nEnd )
73 return nano( nStart, nEnd );
76 static unsigned long long random_seed()
78 native_timer_type tmr;
79 read_real_time( &tmr, sizeof(tmr) );
80 return ( ((unsigned long long)(tmr.tb_hight)) << 32 ) + tmr.tb_low;
85 #ifndef CDS_CXX11_INLINE_NAMESPACE_SUPPORT
86 typedef Aix::Timer Timer;
89 }} // namespace cds::OS
92 #endif // #ifndef CDSLIB_OS_AIX_TIMER_H