summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Huston <shuston@riverace.com>2001-09-12 19:17:13 +0000
committerSteve Huston <shuston@riverace.com>2001-09-12 19:17:13 +0000
commitf90211f8c807c2dc91adbdd494b55ae208796701 (patch)
tree20f696fe7dacde5959006ef0b54629f28718a3d8
parente73b726fa701c524d3f873679e0409018a929850 (diff)
downloadATCD-f90211f8c807c2dc91adbdd494b55ae208796701.tar.gz
ChangeLogTag:Wed Sep 12 15:10:41 2001 Steve Huston <shuston@riverace.com>
-rw-r--r--ace/High_Res_Timer.cpp15
-rw-r--r--ace/High_Res_Timer.i17
2 files changed, 21 insertions, 11 deletions
diff --git a/ace/High_Res_Timer.cpp b/ace/High_Res_Timer.cpp
index b3ac1641913..89840f40cc1 100644
--- a/ace/High_Res_Timer.cpp
+++ b/ace/High_Res_Timer.cpp
@@ -375,14 +375,18 @@ ACE_High_Res_Timer::elapsed_time (ACE_hrtime_t &nanoseconds) const
{
// Please do _not_ rearrange this equation. It is carefully
// designed and tested to avoid overflow on machines that don't have
- // native 64-bit ints.
+ // native 64-bit ints. In particular, division can be a problem.
+ // For more background on this, please see bugzilla #1024.
#if defined (ACE_WIN32)
nanoseconds = (this->end_ - this->start_)
- * (1000000u / ACE_High_Res_Timer::global_scale_factor ());
+ * (1024000000u / ACE_High_Res_Timer::global_scale_factor());
#else
nanoseconds = (this->end_ - this->start_)
- * (1000u / ACE_High_Res_Timer::global_scale_factor ());
+ * (1024000u / ACE_High_Res_Timer::global_scale_factor ());
#endif /* ACE_WIN32 */
+ nanoseconds >>= 10;
+ // Right shift is implemented for non native 64-bit ints
+ // operator/ only for a 32 bit result !
}
void
@@ -391,11 +395,12 @@ ACE_High_Res_Timer::elapsed_time_incr (ACE_hrtime_t &nanoseconds) const
// Same as above.
#if defined (ACE_WIN32)
nanoseconds = this->total_
- / ACE_High_Res_Timer::global_scale_factor () * 1000000u;
+ * (1024000000u / ACE_High_Res_Timer::global_scale_factor());
#else
nanoseconds = this->total_
- / ACE_High_Res_Timer::global_scale_factor () * 1000u;
+ * (1024000u / ACE_High_Res_Timer::global_scale_factor ());
#endif
+ nanoseconds >>= 10;
}
#if !defined (ACE_HAS_WINCE)
diff --git a/ace/High_Res_Timer.i b/ace/High_Res_Timer.i
index e4864adedde..56d1e8dba60 100644
--- a/ace/High_Res_Timer.i
+++ b/ace/High_Res_Timer.i
@@ -128,15 +128,20 @@ 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)
+ // Win32 scale factor is in msec
+ // This could give overflow when measuring a long time with a
+ // big global_scale_factor() (> 48 days with a 4Ghz tick freq.)
+ // To be looked after in the future.
+ usecs = (ACE_hrtime_t) (((this->end_ - this->start_) * 1000) /
+ global_scale_factor ());
+#else
usecs =
(ACE_hrtime_t) ((this->end_ - this->start_) / global_scale_factor ());
-#if defined (ACE_WIN32)
- // Win32 scale factor is in msec, so multiply up to usecs and pick up
- // the straggling usecs from the modulus.
- usecs *= 1000u;
- usecs +=
- (ACE_hrtime_t) (((this->end_ - this->start_) % global_scale_factor ()) * 1000u);
#endif
+
+
+
}
ACE_INLINE void