From 229673fc49bb56c3f1207cb82c01f8914850c287 Mon Sep 17 00:00:00 2001 From: Ossama Othman Date: Wed, 10 Apr 2002 17:44:16 +0000 Subject: ChangeLogTag:Wed Apr 10 10:40:36 2002 Ossama Othman --- ace/Time_Value.h | 241 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 235 insertions(+), 6 deletions(-) (limited to 'ace/Time_Value.h') diff --git a/ace/Time_Value.h b/ace/Time_Value.h index 913b180c2a0..5a54f6220aa 100644 --- a/ace/Time_Value.h +++ b/ace/Time_Value.h @@ -1,4 +1,4 @@ -/* -*- C++ -*- */ +// -*- C++ -*- //============================================================================= /** @@ -13,16 +13,245 @@ #ifndef ACE_TIME_VALUE_H #define ACE_TIME_VALUE_H -#include "ace/pre.h" -// This file is no longer used and is only here due to backwards -// compatibility. All the functionality has been merged into OS.h. +#include "ace/pre.h" -#include "ace/OS.h" +#include "ace/OS_Export.h" +#include "ace/ACE_export.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ + +// Define some helpful constants. +// Not type-safe, and signed. For backward compatibility. +#define ACE_ONE_SECOND_IN_MSECS 1000L +#define ACE_ONE_SECOND_IN_USECS 1000000L +#define ACE_ONE_SECOND_IN_NSECS 1000000000L + + +// ------------------------------------------------------------------- +// These forward declarations are only used to circumvent a bug in +// MSVC 6.0 compiler. They shouldn't cause any problem for other +// compilers and they can be removed once MS release a SP that contains +// the fix. +class ACE_Time_Value; +ACE_OS_Export ACE_Time_Value operator + (const ACE_Time_Value &tv1, + const ACE_Time_Value &tv2); + +ACE_OS_Export ACE_Time_Value operator - (const ACE_Time_Value &tv1, + const ACE_Time_Value &tv2); + +// This forward declaration is needed by the set() and FILETIME() functions +#if defined (ACE_LACKS_LONGLONG_T) +class ACE_Export ACE_U_LongLong; +#endif /* ACE_LACKS_LONGLONG_T */ +// ------------------------------------------------------------------- + +# if !defined (ACE_HAS_POSIX_TIME) && !defined (ACE_PSOS) +// Definition per POSIX. +typedef struct timespec +{ + time_t tv_sec; // Seconds + long tv_nsec; // Nanoseconds +} timespec_t; +# elif defined (ACE_HAS_BROKEN_POSIX_TIME) +// OSF/1 defines struct timespec in - Tom Marrs +# include /**/ +# endif /* !ACE_HAS_POSIX_TIME */ + +# if defined(ACE_LACKS_TIMESPEC_T) +typedef struct timespec timespec_t; +# endif /* ACE_LACKS_TIMESPEC_T * + +// ------------------------------------------------------------------- + +/** + * @class ACE_Time_Value + * + * @brief Operations on "timeval" structures, which express time in + * seconds (secs) and microseconds (usecs). + * + * This class centralizes all the time related processing in + * ACE. These time values are typically used in conjunction with OS + * mechanisms like or other calls that may have + * *their own* implementation-specific maximum time representations. + * Its primary use is in time computations such as those used by the + * dynamic subpriority strategies in the + * class. + */ + static const ACE_Time_Value max_time; + + // = Initialization methods. + + /// Default Constructor. + ACE_Time_Value (void); + + /// Constructor. + ACE_Time_Value (long sec, long usec = 0); + + // = Methods for converting to/from various time formats. + /// Construct the from a . + ACE_Time_Value (const struct timeval &t); + + /// Initializes the object from a . + ACE_Time_Value (const timespec_t &t); + + /// Copy constructor. + ACE_Time_Value (const ACE_Time_Value &tv); + +# if defined (ACE_WIN32) + /// Initializes the ACE_Time_Value object from a Win32 FILETIME + ACE_Time_Value (const FILETIME &ft); +# endif /* ACE_WIN32 */ + + /// Construct a from two s. + void set (long sec, long usec); + + /// Construct a from a , which is assumed to be + /// in second format, with any remainder treated as microseconds. + void set (double d); + + /// Construct a from a . + void set (const timeval &t); + + /// Initializes the object from a . + void set (const timespec_t &t); + +# if defined (ACE_WIN32) + /// Initializes the object from a . + void set (const FILETIME &ft); +# endif /* ACE_WIN32 */ + + /// Converts from format into milli-seconds format. + long msec (void) const; + + /// Converts from milli-seconds format into format. + void msec (long); + + /// Returns the value of the object as a . + operator timespec_t () const; + + /// Returns the value of the object as a . + operator timeval () const; + + /// Returns a pointer to the object as a . + operator const timeval *() const; + +# if defined (ACE_WIN32) + /// Returns the value of the object as a Win32 FILETIME. + operator FILETIME () const; +# endif /* ACE_WIN32 */ + + // = The following are accessor/mutator methods. + + /// Get seconds. + long sec (void) const; + + /// Set seconds. + void sec (long sec); + + /// Get microseconds. + long usec (void) const; + + /// Set microseconds. + void usec (long usec); + + // = The following arithmetic methods operate on s. + + /// Add to this. + ACE_Time_Value &operator += (const ACE_Time_Value &tv); + + /// Subtract to this. + ACE_Time_Value &operator -= (const ACE_Time_Value &tv); + + /// Multiply the time value by the factor, which must be >= 0. + ACE_Time_Value &operator *= (double d); + + /// Increment microseconds (the only reason this is here is + /// to allow the use of ACE_Atomic_Op with ACE_Time_Value). + ACE_Time_Value operator++ (int); // Postfix advance + ACE_Time_Value &operator++ (void); // Prefix advance + + /// Decrement microseconds (the only reason this is here is + /// to allow the use of ACE_Atomic_Op with ACE_Time_Value). + ACE_Time_Value operator-- (int); // Postfix dec + ACE_Time_Value &operator-- (void); // Prefix dec + + /// Adds two ACE_Time_Value objects together, returns the sum. + friend ACE_OS_Export ACE_Time_Value operator + (const ACE_Time_Value &tv1, + const ACE_Time_Value &tv2); + + /// Subtracts two ACE_Time_Value objects, returns the difference. + friend ACE_OS_Export ACE_Time_Value operator - (const ACE_Time_Value &tv1, + const ACE_Time_Value &tv2); + + /// True if tv1 < tv2. + friend ACE_OS_Export int operator < (const ACE_Time_Value &tv1, + const ACE_Time_Value &tv2); + + /// True if tv1 > tv2. + friend ACE_OS_Export int operator > (const ACE_Time_Value &tv1, + const ACE_Time_Value &tv2); + + /// True if tv1 <= tv2. + friend ACE_OS_Export int operator <= (const ACE_Time_Value &tv1, + const ACE_Time_Value &tv2); + + /// True if tv1 >= tv2. + friend ACE_OS_Export int operator >= (const ACE_Time_Value &tv1, + const ACE_Time_Value &tv2); + + /// True if tv1 == tv2. + friend ACE_OS_Export int operator == (const ACE_Time_Value &tv1, + const ACE_Time_Value &tv2); + + /// True if tv1 != tv2. + friend ACE_OS_Export int operator != (const ACE_Time_Value &tv1, + const ACE_Time_Value &tv2); + + /// Dump is a no-op. + /** + * The dump() method is a no-op. It's here for backwards compatibility + * only, but does not dump anything. Invoking logging methods here + * violates layering restrictions in ACE because this class is part + * of the OS layer and @c ACE_Log_Msg is at a higher level. + */ + void dump (void) const; + +# if defined (ACE_WIN32) + /// Const time difference between FILETIME and POSIX time. +# if defined (ACE_LACKS_LONGLONG_T) + static const ACE_U_LongLong FILETIME_to_timval_skew; +# else + static const DWORDLONG FILETIME_to_timval_skew; +# endif // ACE_LACKS_LONGLONG_T +# endif /* ACE_WIN32 */ + +private: + /// Put the timevalue into a canonical form. + void normalize (void); + + /// Store the values as a . + timeval tv_; +}; + +#if defined (__ACE_INLINE__) +#include "ace/Time_Value.inl" +#endif /* __ACE_INLINE__ */ + #include "ace/post.h" -#endif /* ACE_TIME_VALUE */ + +#endif /* ACE_TIME_VALUE_H */ -- cgit v1.2.1