summaryrefslogtreecommitdiff
path: root/ace
diff options
context:
space:
mode:
authorharrison <harrison@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-03-20 07:16:33 +0000
committerharrison <harrison@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-03-20 07:16:33 +0000
commit6e74382a58ccc38b1cab8abf4d10716ad3e13248 (patch)
tree5a776e18167716ed558965f146deb73bc2e3e22f /ace
parent3c3bdde446856904eca163ed964ea77db0c0cd7d (diff)
downloadATCD-6e74382a58ccc38b1cab8abf4d10716ad3e13248.tar.gz
Removed scale_factor > 0 checks.
Should work on NT even if global_scale_factor_ is not set.
Diffstat (limited to 'ace')
-rw-r--r--ace/High_Res_Timer.cpp46
-rw-r--r--ace/High_Res_Timer.h24
-rw-r--r--ace/High_Res_Timer.i39
3 files changed, 52 insertions, 57 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];
diff --git a/ace/High_Res_Timer.h b/ace/High_Res_Timer.h
index 42fbcd40dae..b1b2f4f07c1 100644
--- a/ace/High_Res_Timer.h
+++ b/ace/High_Res_Timer.h
@@ -33,12 +33,13 @@ class ACE_Export ACE_High_Res_Timer
// added. It returns 1 if high-resolution time (ACE_OS::gethrtime ())
// is supported on the platform, and 0 if not.
//
- // The optional scale factor is required for platforms that have
- // high-resolution timers that return units other than nanoseconds,
- // such as clock ticks. The member functions that return or print
- // times use this scale factor. They divide the "time" that they
- // get from ACE_OS::gethrtime () by it to obtain the time in nanoseconds.
- // Its units are 1/second, possibly ticks/second.
+ // The scale factor is required for platforms that have
+ // high-resolution timers that return units other than
+ // nanoseconds, such as clock ticks. The member functions that
+ // return or print times use this scale factor. They divide the
+ // "time" that they get from ACE_OS::gethrtime () by it to
+ // obtain the time in nanoseconds. Its units are 1/second,
+ // possibly ticks/second.
//
// NOTE: the elapsed time calculations in the print methods use
// ACE_hrtime_t values. If ACE_hrtime_t is not a 64-bit type
@@ -66,11 +67,16 @@ public:
static ACE_Time_Value gettimeofday (void);
// Calls ACE_High_Res_Timer::hrtime_to_tv passing ACE_OS::gethrtime
// and global_scale_factor_. This function can be used to
- // parameterize objects such as ACE_Timer_Queue::gettimeofday.
+ // parameterize objects such as ACE_Timer_Queue::gettimeofday. If
+ // global_scale_factor_ is not set, and we're on a platform that
+ // requires global_scale_factor_ (e.g., Win32), ACE_OS::gettimeofday
+ // will be used instead of ACE_OS::gethrtime. This allows the
+ // scale_factor of 1 to still result in correct values.
- ACE_High_Res_Timer (double scale_factor = 0);
+ ACE_High_Res_Timer (double scale_factor = 1);
// Initialize the timer. The <scale_factor> takes precedence to
- // global_scale_factor_.
+ // global_scale_factor_. A scale_factor of 1 is a noop. A scale
+ // factor of 0 will cause division by zero exceptions.
void reset (void);
// Reinitialize the timer.
diff --git a/ace/High_Res_Timer.i b/ace/High_Res_Timer.i
index 4295277e1ce..2a259bef1fb 100644
--- a/ace/High_Res_Timer.i
+++ b/ace/High_Res_Timer.i
@@ -16,7 +16,10 @@ ACE_High_Res_Timer::ACE_High_Res_Timer (double scale_factor)
ACE_TRACE ("ACE_High_Res_Timer::ACE_High_Res_Timer");
// <scale_factor> takes precendence over the global_scale_factor_.
- if (scale_factor_ == 0)
+ // If scale_factor_ is not set (== 1) and a global_scale_factor is
+ // set (!= 0), use the global_scale_factor_.
+ if (scale_factor_ == 1 &&
+ ACE_High_Res_Timer::global_scale_factor_ != 0)
scale_factor_ = ACE_High_Res_Timer::global_scale_factor_;
this->reset ();
@@ -53,11 +56,7 @@ ACE_High_Res_Timer::stop_incr (void)
ACE_INLINE void
ACE_High_Res_Timer::elapsed_microseconds (ACE_hrtime_t &usecs) const
{
- if (scale_factor_ > 0) {
- usecs = (ACE_hrtime_t) ((this->end_ - this->start_) / scale_factor_) / 1000;
- } else {
- usecs = (this->end_ - this->start_) / 1000;
- }
+ usecs = (ACE_hrtime_t) ((this->end_ - this->start_) / scale_factor_) / 1000;
}
ACE_INLINE void
@@ -71,22 +70,24 @@ ACE_High_Res_Timer::hrtime_to_tv (ACE_Time_Value &tv,
ACE_hrtime_t hrt,
double scale_factor)
{
- if (scale_factor > 0) {
- tv.sec ((long) (hrt / scale_factor / 1000) / 1000000);
- tv.usec ((long) (hrt / scale_factor / 1000) % 1000000);
- } else {
- tv.sec ((long) (hrt / 1000) / 1000000);
- tv.usec ((long) (hrt / 1000) % 1000000);
- }
+ tv.sec ((long) (hrt / scale_factor / 1000) / 1000000);
+ tv.usec ((long) (hrt / scale_factor / 1000) % 1000000);
}
ACE_INLINE ACE_Time_Value
ACE_High_Res_Timer::gettimeofday (void)
{
- ACE_Time_Value tv;
- ACE_High_Res_Timer::hrtime_to_tv (tv,
- ACE_OS::gethrtime (),
- ACE_High_Res_Timer::global_scale_factor_);
- return tv;
+ // If the global_scale_factor_ == 0, then a scale factor is needed
+ // by the platform gethrtime, but a scale factor has not been set.
+ // Hence, just return ACE_OS::gettimeofday.
+ if (ACE_High_Res_Timer::global_scale_factor_ == 0)
+ return ACE_OS::gettimeofday ();
+ else
+ {
+ ACE_Time_Value tv;
+ ACE_High_Res_Timer::hrtime_to_tv (tv,
+ ACE_OS::gethrtime (),
+ ACE_High_Res_Timer::global_scale_factor_);
+ return tv;
+ }
}
-