summaryrefslogtreecommitdiff
path: root/ACE/ace/High_Res_Timer.cpp
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.cpp
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.cpp')
-rw-r--r--ACE/ace/High_Res_Timer.cpp52
1 files changed, 30 insertions, 22 deletions
diff --git a/ACE/ace/High_Res_Timer.cpp b/ACE/ace/High_Res_Timer.cpp
index f62c4597f7b..09034f25cff 100644
--- a/ACE/ace/High_Res_Timer.cpp
+++ b/ACE/ace/High_Res_Timer.cpp
@@ -41,11 +41,11 @@ ACE_END_VERSIONED_NAMESPACE_DECL
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
- // Initialize the global_scale_factor_ to 1. The first
- // ACE_High_Res_Timer instance construction will override this
- // value.
- /* static */
- ACE_UINT32 ACE_High_Res_Timer::global_scale_factor_ = 1u;
+/// Initialize the global_scale_factor_ to 1. The first
+/// ACE_High_Res_Timer instance construction will override this
+/// value.
+/* static */
+ACE_High_Res_Timer::global_scale_factor_type ACE_High_Res_Timer::global_scale_factor_ = 1u;
ACE_END_VERSIONED_NAMESPACE_DECL
@@ -67,8 +67,8 @@ ACE_END_VERSIONED_NAMESPACE_DECL
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
-// This is used to tell if the global_scale_factor_ has been
-// set, and if high resolution timers are supported.
+/// This is used to tell if the global_scale_factor_ has been
+/// set, and if high resolution timers are supported.
/* static */
int ACE_High_Res_Timer::global_scale_factor_status_ = 0;
@@ -187,7 +187,8 @@ ACE_High_Res_Timer::get_cpuinfo (void)
}
#endif /* ACE_LINUX */
-ACE_UINT32
+
+ACE_High_Res_Timer::global_scale_factor_type
ACE_High_Res_Timer::global_scale_factor (void)
{
#if (defined (ACE_WIN32) || defined (ACE_HAS_POWERPC_TIMER) || \
@@ -208,27 +209,20 @@ ACE_High_Res_Timer::global_scale_factor (void)
if (ACE_High_Res_Timer::global_scale_factor_status_ == 0)
{
# if defined (ACE_WIN32)
+ // This a higher-precision version, specific for Windows systems
LARGE_INTEGER freq;
if (::QueryPerformanceFrequency (&freq))
- {
- // We have a high-res timer
-# if defined (ACE_LACKS_LONGLONG_T)
- ACE_UINT64 uint64_freq(freq.u.LowPart, (ACE_UINT32) freq.u.HighPart);
- ACE_High_Res_Timer::global_scale_factor
- (uint64_freq / (ACE_UINT32) ACE_ONE_SECOND_IN_USECS);
-# else
- ACE_High_Res_Timer::global_scale_factor
- (static_cast<unsigned int> (freq.QuadPart / ACE_HR_SCALE_CONVERSION));
-# endif // (ACE_LACKS_LONGLONG_T)
+ {
+ ACE_High_Res_Timer::global_scale_factor(freq.QuadPart);
ACE_High_Res_Timer::global_scale_factor_status_ = 1;
- }
+ }
else
+ {
// High-Res timers not supported
ACE_High_Res_Timer::global_scale_factor_status_ = -1;
-
+ }
return ACE_High_Res_Timer::global_scale_factor_;
-
# elif defined (ACE_LINUX)
ACE_High_Res_Timer::global_scale_factor (ACE_High_Res_Timer::get_cpuinfo ());
# endif /* ! ACE_WIN32 && ! (ACE_LINUX && __alpha__) */
@@ -397,6 +391,7 @@ ACE_High_Res_Timer::elapsed_time_incr (ACE_Time_Value &tv) const
void
ACE_High_Res_Timer::elapsed_time (ACE_hrtime_t &nanoseconds) const
{
+#if !defined (ACE_WIN32)
// 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. In particular, division can be a problem.
@@ -407,16 +402,29 @@ ACE_High_Res_Timer::elapsed_time (ACE_hrtime_t &nanoseconds) const
nanoseconds = nanoseconds >> 10;
// Right shift is implemented for non native 64-bit ints
// operator/ only for a 32 bit result !
+#else
+ // This a higher-precision version, specific for Windows systems
+ nanoseconds =
+ (ACE_High_Res_Timer::elapsed_hrtime (this->end_, this->start_) * ACE_HR_SCALE_CONVERSION * 1000u) /
+ ACE_High_Res_Timer::global_scale_factor ();
+#endif
}
void
ACE_High_Res_Timer::elapsed_time_incr (ACE_hrtime_t &nanoseconds) const
{
+#if !defined (ACE_WIN32)
// Same as above.
nanoseconds = this->total_
- * (1024000u / ACE_High_Res_Timer::global_scale_factor ());
+ * (1024000u / ACE_High_Res_Timer::global_scale_factor ());
// Caution - Borland has a problem with >>=, so resist the temptation.
nanoseconds = nanoseconds >> 10;
+#else
+ // This a higher-precision version, specific for Windows systems
+ nanoseconds =
+ this->total_ * 1000000000u /
+ ACE_High_Res_Timer::global_scale_factor ();
+#endif
}
void