diff options
Diffstat (limited to 'ace/High_Res_Timer.cpp')
-rw-r--r-- | ace/High_Res_Timer.cpp | 46 |
1 files changed, 17 insertions, 29 deletions
diff --git a/ace/High_Res_Timer.cpp b/ace/High_Res_Timer.cpp index 97cc0e12526..a6249af0b0e 100644 --- a/ace/High_Res_Timer.cpp +++ b/ace/High_Res_Timer.cpp @@ -10,7 +10,16 @@ ACE_ALLOC_HOOK_DEFINE(ACE_High_Res_Timer) +// For win32, a scale factor is required for ACE_OS::gethrtime. Thus, +// initialize the global_scale_factor to zero. This will prevent use +// unless someone explicitly sets it. +#if defined (ACE_WIN32) double ACE_High_Res_Timer::global_scale_factor_ = 0; +#else +// For platforms that do not require a scale factor, we'll set it to +// one so that the divisions are no ops. +double ACE_High_Res_Timer::global_scale_factor_ = 1; +#endif /* ACE_WIN32 */ void ACE_High_Res_Timer::dump (void) const @@ -35,39 +44,24 @@ ACE_High_Res_Timer::reset (void) void ACE_High_Res_Timer::elapsed_time (ACE_Time_Value &tv) { - if (scale_factor_ > 0) { - tv.sec ((long) ((this->end_ - this->start_) / scale_factor_ / 1000) / 1000000); - tv.usec ((long) ((this->end_ - this->start_) / scale_factor_ / 1000) % 1000000); - } else { - tv.sec ((long) ((this->end_ - this->start_) / 1000) / 1000000); - tv.usec ((long) ((this->end_ - this->start_) / 1000) % 1000000); - } + tv.sec ((long) ((this->end_ - this->start_) / scale_factor_ / 1000) / 1000000); + tv.usec ((long) ((this->end_ - this->start_) / scale_factor_ / 1000) % 1000000); } #if defined (ACE_HAS_POSIX_TIME) void ACE_High_Res_Timer::elapsed_time (struct timespec &elapsed_time) { - if (scale_factor_ > 0) { - elapsed_time.tv_sec = (time_t) ((this->end_ - this->start_) / scale_factor_ / 1000) / 1000000; - elapsed_time.tv_nsec = (long) ((this->end_ - this->start_) / scale_factor_ / 1000) % 1000000; - } else { - elapsed_time.tv_sec = (time_t) ((this->end_ - this->start_) / 1000) / 1000000; - elapsed_time.tv_nsec = (long) ((this->end_ - this->start_) / 1000) % 1000000; - } + elapsed_time.tv_sec = (time_t) ((this->end_ - this->start_) / scale_factor_ / 1000) / 1000000; + elapsed_time.tv_nsec = (long) ((this->end_ - this->start_) / scale_factor_ / 1000) % 1000000; } #endif /* ACE_HAS_POSIX_TIME */ void ACE_High_Res_Timer::elapsed_time_incr (ACE_Time_Value &tv) { - if (scale_factor_ > 0) { - tv.sec ((long) (this->total_ / scale_factor_ / 1000) / 1000000); - tv.usec ((long) (this->total_ / scale_factor_ / 1000) % 1000000); - } else { - tv.sec ((long) (this->total_ / 1000) / 1000000); - tv.usec ((long) (this->total_ / 1000) % 1000000); - } + tv.sec ((long) (this->total_ / scale_factor_ / 1000) / 1000000); + tv.usec ((long) (this->total_ / scale_factor_ / 1000) % 1000000); } void @@ -75,10 +69,7 @@ ACE_High_Res_Timer::print_ave (const char *str, const int count, ACE_HANDLE hand { ACE_TRACE ("ACE_High_Res_Timer::print_ave"); ACE_hrtime_t total; - if (scale_factor_ > 0) - total = (ACE_hrtime_t) ((this->end_ - this->start_) / scale_factor_); - else - total = this->end_ - this->start_; + total = (ACE_hrtime_t) ((this->end_ - this->start_) / scale_factor_); ACE_hrtime_t total_secs = total / 1000000000; u_long extra_nsecs = (u_long) (total % 1000000000); @@ -103,10 +94,7 @@ ACE_High_Res_Timer::print_total (const char *str, const int count, ACE_HANDLE ha { ACE_TRACE ("ACE_High_Res_Timer::print_total"); ACE_hrtime_t total_secs; - if (scale_factor_ > 0) - total_secs = (ACE_hrtime_t) (this->total_ / scale_factor_ / 1000000000); - else - total_secs = this->total_ / 1000000000; + total_secs = (ACE_hrtime_t) (this->total_ / scale_factor_ / 1000000000); u_long extra_nsecs = (u_long) (this->total_ % 1000000000); char buf[100]; |