summaryrefslogtreecommitdiff
path: root/ACE/ace/High_Res_Timer.inl
diff options
context:
space:
mode:
authorJohnny Willemsen <jwillemsen@remedy.nl>2012-05-12 11:18:13 +0000
committerJohnny Willemsen <jwillemsen@remedy.nl>2012-05-12 11:18:13 +0000
commitb48d3b6d549c60df6cea2eb2cce0eab94332fc44 (patch)
treebf2bda66736860a323a46ac6c191e6b59f4e1aa5 /ACE/ace/High_Res_Timer.inl
parentfb27dcac0c7554bb3dd67d679f2665f67e6f27b3 (diff)
downloadATCD-b48d3b6d549c60df6cea2eb2cce0eab94332fc44.tar.gz
Sat May 12 11:11:45 UTC 2012 Johnny Willemsen <jwillemsen@remedy.nl>
* ace/Time_Value.h: * ace/Time_Value.cpp: None of the windows compilers define ACE_LACKS_LONGLONG_T * ace/High_Res_Timer.h: * ace/High_Res_Timer.inl: * ace/High_Res_Timer.cpp: Integrated patches from bugzilla 3703 increasing the precision of the high resolution timers on windows
Diffstat (limited to 'ACE/ace/High_Res_Timer.inl')
-rw-r--r--ACE/ace/High_Res_Timer.inl51
1 files changed, 37 insertions, 14 deletions
diff --git a/ACE/ace/High_Res_Timer.inl b/ACE/ace/High_Res_Timer.inl
index 56df6e1f04b..848d268ebe8 100644
--- a/ACE/ace/High_Res_Timer.inl
+++ b/ACE/ace/High_Res_Timer.inl
@@ -21,21 +21,36 @@ ACE_INLINE void
ACE_High_Res_Timer::hrtime_to_tv (ACE_Time_Value &tv,
const ACE_hrtime_t hrt)
{
- // The following are based on the units of global_scale_factor_
- // being 1/microsecond. Therefore, dividing by it converts
- // clock ticks to microseconds.
- tv.sec ((long) (hrt / (ACE_UINT32) ACE_HR_SCALE_CONVERSION /
+#if !defined (ACE_WIN32)
+ // The following are based on the units of global_scale_factor_
+ // being 1/microsecond. Therefore, dividing by it converts
+ // clock ticks to microseconds.
+ tv.sec ((time_t) (hrt / (ACE_UINT32) ACE_HR_SCALE_CONVERSION /
global_scale_factor ()));
- // Calculate usec in a manner that's compatible with ACE_U_LongLong.
- // hrt = (tv.sec * ACE_ONE_SECOND_IN_USECS + tv.usec) * global_scale_factor_
- // tv.usec = hrt / global_scale_factor_ - tv.sec * ACE_ONE_SECOND_IN_USECS
- // That first term will be lossy, so factor out global_scale_factor_:
- // tv.usec = (hrt - tv.sec * ACE_ONE_SECOND_IN_USECS * global_scale_factor_)/
- // global_scale_factor
- ACE_hrtime_t tmp = tv.sec ();
- tmp *= ((ACE_UINT32) ACE_HR_SCALE_CONVERSION * global_scale_factor ());
- tv.usec ((long) ((hrt - tmp) / global_scale_factor ()));
+ // Calculate usec in a manner that's compatible with ACE_U_LongLong.
+ // hrt = (tv.sec * ACE_ONE_SECOND_IN_USECS + tv.usec) * global_scale_factor_
+ // tv.usec = hrt / global_scale_factor_ - tv.sec * ACE_ONE_SECOND_IN_USECS
+ // That first term will be lossy, so factor out global_scale_factor_:
+ // tv.usec = (hrt - tv.sec * ACE_ONE_SECOND_IN_USECS * global_scale_factor_)/
+ // global_scale_factor
+ ACE_hrtime_t tmp = tv.sec ();
+ tmp *= ((ACE_UINT32) ACE_HR_SCALE_CONVERSION * global_scale_factor ());
+ tv.usec ((suseconds_t) ((hrt - tmp) / global_scale_factor ()));
+#else
+
+ // This a higher-precision version, specific for Windows systems
+ // The following are based on the units of global_scale_factor_
+ // being 1/microsecond. Therefore, dividing by it converts
+ // clock ticks to microseconds.
+ tv.sec ((time_t) (hrt / global_scale_factor () ));
+
+ // Calculate usec
+ ACE_hrtime_t tmp = tv.sec ();
+ tmp *= global_scale_factor ();
+ tv.usec ((suseconds_t) ((hrt - tmp) * ACE_HR_SCALE_CONVERSION / global_scale_factor ()));
+
+#endif
}
@@ -139,13 +154,21 @@ ACE_High_Res_Timer::stop_incr (const ACE_OS::ACE_HRTimer_Op op)
ACE_INLINE void
ACE_High_Res_Timer::elapsed_microseconds (ACE_hrtime_t &usecs) const
{
+
+#if !defined (ACE_WIN32)
ACE_hrtime_t elapsed = ACE_High_Res_Timer::elapsed_hrtime (this->end_,
this->start_);
usecs = (ACE_hrtime_t) (elapsed / global_scale_factor ());
+#else
+ usecs = (ACE_High_Res_Timer::elapsed_hrtime (this->end_, this->start_) *
+ ACE_HR_SCALE_CONVERSION) /
+ global_scale_factor ();
+#endif
}
ACE_INLINE void
-ACE_High_Res_Timer::global_scale_factor (ACE_UINT32 gsf)
+ACE_High_Res_Timer::global_scale_factor (
+ ACE_High_Res_Timer::global_scale_factor_type gsf)
{
global_scale_factor_ = gsf;
}