summaryrefslogtreecommitdiff
path: root/ACE/ace/High_Res_Timer.inl
diff options
context:
space:
mode:
authorJohnny Willemsen <jwillemsen@remedy.nl>2010-03-15 07:58:50 +0000
committerJohnny Willemsen <jwillemsen@remedy.nl>2010-03-15 07:58:50 +0000
commitf4ae2613c87ce239858f59a186003a1af9a51b71 (patch)
tree9b8c1c973166673790471894ab504ad96b41d9eb /ACE/ace/High_Res_Timer.inl
parent7a4083a23538862fc17c025b64f45c29c29ada0c (diff)
downloadATCD-f4ae2613c87ce239858f59a186003a1af9a51b71.tar.gz
Mon Mar 15 07:58:54 UTC 2010 Johnny Willemsen <jwillemsen@remedy.nl>
* ace/High_Res_Timer.cpp * ace/High_Res_Timer.h * ace/High_Res_Timer.inl Use 64bit calculations to increase our precision. If you want to have the 32bit calculations, add ACE_USE_WINDOWS_32BIT_HIGH_RES_TIMER_CALCULATIONS as define. If the scoreboard doesn't show any platforms requiring 32bit, we will remove that code before the next micro release goes out Thanks to Alon Diamant <diamant dot alon at gmail dot com> for supplying the patches. This fixes bugzilla 3703. * ace/Timer_Queue_Adapters.cpp * ace/Timer_Queue_Adapters.h * ace/Timer_Queue_Adapters.inl Make it possible to use a customer event handler in ACE_Thread_Timer_Queue_Adapter. Thanks to Alon Diamant <diamant dot alon at gmail dot com> for supplying the patches. This fixes bugzilla 3614 * tests/tests.mpc: * tests/Thread_Timer_Queue_Adapter_Test.cpp: New test for testing custom event handlers in ACE_Thread_Timer_Queue_Adapter. Thanks to Alon Diamant <diamant dot alon at gmail dot com> for creating this new test
Diffstat (limited to 'ACE/ace/High_Res_Timer.inl')
-rw-r--r--ACE/ace/High_Res_Timer.inl65
1 files changed, 52 insertions, 13 deletions
diff --git a/ACE/ace/High_Res_Timer.inl b/ACE/ace/High_Res_Timer.inl
index 56df6e1f04b..a568d971eda 100644
--- a/ACE/ace/High_Res_Timer.inl
+++ b/ACE/ace/High_Res_Timer.inl
@@ -21,21 +21,37 @@ 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_USE_WINDOWS_32BIT_HIGH_RES_TIMER_CALCULATIONS)
+
+ // 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 /
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 ((long) ((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 ((long) (hrt / global_scale_factor () ));
+
+ // Calculate usec
+ ACE_hrtime_t tmp = tv.sec ();
+ tmp *= global_scale_factor ();
+ tv.usec ((long) ((hrt - tmp) * ACE_HR_SCALE_CONVERSION / global_scale_factor ()));
+
+#endif
}
@@ -139,15 +155,38 @@ 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_USE_WINDOWS_32BIT_HIGH_RES_TIMER_CALCULATIONS)
+
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
}
+#if defined (ACE_USE_WINDOWS_32BIT_HIGH_RES_TIMER_CALCULATIONS)
+
ACE_INLINE void
ACE_High_Res_Timer::global_scale_factor (ACE_UINT32 gsf)
{
global_scale_factor_ = gsf;
}
+#else
+
+ACE_INLINE void
+ACE_High_Res_Timer::global_scale_factor (ACE_UINT64 gsf)
+{
+ global_scale_factor_ = gsf;
+}
+
+#endif
+
ACE_END_VERSIONED_NAMESPACE_DECL