diff options
author | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-03-24 20:56:32 +0000 |
---|---|---|
committer | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-03-24 20:56:32 +0000 |
commit | e9d3567210d9ad6374ea2b3ea1a49e3dd30ec6ce (patch) | |
tree | 058182cf37395c3537ab424bc3df67383aba05a5 /ace/High_Res_Timer.cpp | |
parent | ec3c7cb50e81bfced20a1927bbd083e46201d579 (diff) | |
download | ATCD-e9d3567210d9ad6374ea2b3ea1a49e3dd30ec6ce.tar.gz |
(elapsed_time (struct timespec &): fixed, using same approach as in elapsed_nanoseconds (), to get nanosecond resolution
Diffstat (limited to 'ace/High_Res_Timer.cpp')
-rw-r--r-- | ace/High_Res_Timer.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/ace/High_Res_Timer.cpp b/ace/High_Res_Timer.cpp index bf70e30774d..fdf31aacc60 100644 --- a/ace/High_Res_Timer.cpp +++ b/ace/High_Res_Timer.cpp @@ -52,8 +52,19 @@ ACE_High_Res_Timer::elapsed_time (ACE_Time_Value &tv) void ACE_High_Res_Timer::elapsed_time (struct timespec &elapsed_time) { - elapsed_time.tv_sec = (time_t) ((this->end_ - this->start_) / global_scale_factor_) / 1000000; - elapsed_time.tv_nsec = (long) ((this->end_ - this->start_) / global_scale_factor_) % 1000000; + // See elapsed_time (ACE_hrtime_t &nanoseconds) implementation below; + // this implementation is based on that. + + // Just grab the nanoseconds. That is, leave off all values above + // microsecond. This equation is right! Don't mess with me! + int nseconds = (this->end_ - this->start_) % global_scale_factor_ * 1000 / global_scale_factor_; + + // Get just the microseconds (dropping any left over nanoseconds). + ACE_hrtime_t useconds; + useconds = (this->end_ - this->start_) / global_scale_factor_; + + elapsed_time.tv_sec = (time_t) (useconds / 1000000); + elapsed_time.tv_nsec = (time_t) (useconds % 1000000 * 1000 + nseconds); } #endif /* ACE_HAS_POSIX_TIME */ |