From 00b7611eafff824dbc6c89c0f750bfd4d3356649 Mon Sep 17 00:00:00 2001 From: Steve Huston Date: Thu, 17 Jun 2010 22:07:42 +0000 Subject: ChangeLogTag:Thu Jun 17 21:59:34 UTC 2010 Steve Huston --- ACE/ChangeLog | 13 +++++++++++++ ACE/NEWS | 12 ++++++++++++ ACE/ace/Time_Value.h | 23 +++++++++++++++++++++++ ACE/ace/Time_Value.inl | 25 ++++++++++++++++++++++--- ACE/tests/Time_Value_Test.cpp | 19 +++++++++++++++++++ 5 files changed, 89 insertions(+), 3 deletions(-) diff --git a/ACE/ChangeLog b/ACE/ChangeLog index 058948efb5b..261d4c80657 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,3 +1,16 @@ +Thu Jun 17 21:59:34 UTC 2010 Steve Huston + + * ace/Time_Value.{h inl}: Added explicit set_ and get_ methods for + ACE_UINT64 msec values. Also marked the existing "getter" + msec(ACE_UINT64&) methods deprecated because they look like + setter methods and are confusing. Users should change to get_msec(). + Resolves Bugzilla #3336. + + * NEWS: Described the new methods and rationale. + + * tests/Time_Value_Test.cpp: Added test cases for the new + set_msec() and get_msec() methods. + Thu Jun 17 19:47:58 UTC 2010 Steve Huston * ace/DLL_Manager.cpp: Add _get_dll_unload_policy() function that diff --git a/ACE/NEWS b/ACE/NEWS index 924dac88252..a948d19d647 100644 --- a/ACE/NEWS +++ b/ACE/NEWS @@ -1,6 +1,18 @@ USER VISIBLE CHANGES BETWEEN ACE-5.7.9 and ACE-5.8.0 ==================================================== +. There are two new ACE_Time_Value methods for getting and setting millisecond + values to/from ACE_UINT64 values: + + ACE_UINT64 ACE_Time_Value::get_msec () const + void ACE_Time_Value::set_msec (const ACE_UINT64 &ms) + + The former is a replacement for the existing msec(ACE_UINT64&) methods that + are "getter" methods whose signatures look confusingly like "setters". See + Bugzilla #3336 for the history behind this change. + + The latter is for consistency and clarity. + USER VISIBLE CHANGES BETWEEN ACE-5.7.8 and ACE-5.7.9 ==================================================== diff --git a/ACE/ace/Time_Value.h b/ACE/ace/Time_Value.h index 5943094ef75..75bb998f598 100644 --- a/ACE/ace/Time_Value.h +++ b/ACE/ace/Time_Value.h @@ -126,6 +126,17 @@ public: */ unsigned long msec (void) const; + /// Converts from ACE_Time_Value format into milliseconds format. + /** + * @return Sum of second field (in milliseconds) and microsecond field + * (in milliseconds). + * + * @note The semantics of this method differs from the sec() and + * usec() methods. There is no analogous "millisecond" + * component in an ACE_Time_Value. + */ + ACE_UINT64 get_msec () const; + /// Converts from ACE_Time_Value format into milliseconds format. /** * @return Sum of second field (in milliseconds) and microsecond field @@ -134,6 +145,8 @@ public: * @note The semantics of this method differs from the sec() and * usec() methods. There is no analogous "millisecond" * component in an ACE_Time_Value. + * + * @deprecated Use get_msec() instead. */ void msec (ACE_UINT64 &ms) const; @@ -145,9 +158,19 @@ public: * @note The semantics of this method differs from the sec() and * usec() methods. There is no analogous "millisecond" * component in an ACE_Time_Value. + * + * @deprecated Use get_msec() instead. */ void msec (ACE_UINT64 &ms) /* const */; + /// Converts from milli-seconds format into ACE_Time_Value format. + /** + * @note The semantics of this method differs from the sec() and + * usec() methods. There is no analogous "millisecond" + * component in an ACE_Time_Value. + */ + void set_msec (const ACE_UINT64 &ms); + /// Converts from milli-seconds format into ACE_Time_Value format. /** * @note The semantics of this method differs from the sec() and diff --git a/ACE/ace/Time_Value.inl b/ACE/ace/Time_Value.inl index 73f9285ff2d..40ab4476290 100644 --- a/ACE/ace/Time_Value.inl +++ b/ACE/ace/Time_Value.inl @@ -147,13 +147,21 @@ ACE_Time_Value::msec (void) const return ACE_Utils::truncate_cast (secs); } -ACE_INLINE void -ACE_Time_Value::msec (ACE_UINT64 &ms) const +ACE_INLINE ACE_UINT64 +ACE_Time_Value::get_msec () const { // ACE_OS_TRACE ("ACE_Time_Value::msec"); - ms = ACE_Utils::truncate_cast (this->tv_.tv_sec); + ACE_UINT64 ms = ACE_Utils::truncate_cast (this->tv_.tv_sec); ms *= 1000; ms += (this->tv_.tv_usec / 1000); + return ms; +} + +ACE_INLINE void +ACE_Time_Value::msec (ACE_UINT64 &ms) const +{ + // ACE_OS_TRACE ("ACE_Time_Value::msec"); + ms = this->get_msec (); } ACE_INLINE void @@ -164,6 +172,17 @@ ACE_Time_Value::msec (ACE_UINT64 &ms) /*const*/ tv->msec (ms); } +ACE_INLINE void +ACE_Time_Value::set_msec (const ACE_UINT64 &ms) +{ + // ACE_OS_TRACE ("ACE_Time_Value::msec"); + // Convert millisecond units to seconds; + ACE_UINT64 secs = ms / 1000; + this->tv_.tv_sec = static_cast (secs); + // Convert remainder to microseconds; + this->tv_.tv_usec = static_cast((ms - (secs * 1000)) * 1000); +} + /// Converts from milli-seconds format into Time_Value format. ACE_INLINE void ACE_Time_Value::msec (long milliseconds) diff --git a/ACE/tests/Time_Value_Test.cpp b/ACE/tests/Time_Value_Test.cpp index 1f136ead1bc..3e2e75b7841 100644 --- a/ACE/tests/Time_Value_Test.cpp +++ b/ACE/tests/Time_Value_Test.cpp @@ -133,6 +133,12 @@ run_main (int, ACE_TCHAR *[]) ACE_ERROR ((LM_ERROR, ACE_TEXT ("msec test failed: %Q should be 42555\n"), ms)); + ms = 0; + ms = msec_test.get_msec (); + if (ms != 42555) + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("get_msec test failed: %Q should be 42555\n"), + ms)); ACE_Time_Value const msec_test2 (42, 555000); ms = 0; msec_test2.msec (ms); @@ -141,6 +147,19 @@ run_main (int, ACE_TCHAR *[]) ACE_TEXT ("msec const test failed: %Q should be 42555\n"), ms)); + // Test setting from ACE_UINT64 + ms = 42555; + ACE_Time_Value msec_test3; + msec_test3.set_msec (ms); + if (msec_test3.sec () != 42) + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("set_msec test failed: %d secs should be 42\n"), + msec_test3.sec ())); + if (msec_test3.usec () != 555000) + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("set_msec test failed: %d usecs should be 555000\n"), + msec_test3.usec ())); + #ifdef ACE_HAS_CPP98_IOSTREAMS std::ostringstream ost; ost << ACE_Time_Value(1); -- cgit v1.2.1