Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends

ACE_Time_Value Class Reference

Operations on "timeval" structures, which express time in seconds (secs) and microseconds (usecs). More...

#include <Time_Value.h>

Collaboration diagram for ACE_Time_Value:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ACE_Time_Value (void)
 Default Constructor.
 ACE_Time_Value (time_t sec, suseconds_t usec=0)
 Constructor.
 ACE_Time_Value (const struct timeval &t)
 Construct the ACE_Time_Value from a timeval.
 ACE_Time_Value (const timespec_t &t)
 Construct the ACE_Time_Value object from a timespec_t.
void set (time_t sec, suseconds_t usec)
 Initializes the ACE_Time_Value from seconds and useconds.
void set (double d)
void set (const timeval &t)
 Initializes the ACE_Time_Value from a timeval.
void set (const timespec_t &t)
 Initializes the ACE_Time_Value object from a timespec_t.
unsigned long msec (void) const
 Converts from ACE_Time_Value format into milliseconds format.
ACE_UINT64 get_msec () const
 Converts from ACE_Time_Value format into milliseconds format.
void msec (ACE_UINT64 &ms) const
 Converts from ACE_Time_Value format into milliseconds format.
void msec (ACE_UINT64 &ms)
 Converts from ACE_Time_Value format into milliseconds format.
void set_msec (const ACE_UINT64 &ms)
 Converts from milli-seconds format into ACE_Time_Value format.
void msec (long)
 Converts from milli-seconds format into ACE_Time_Value format.
void msec (int)
 Converts from milli-seconds format into ACE_Time_Value format.
 operator timespec_t () const
 Returns the value of the object as a timespec_t.
 operator timeval () const
 Returns the value of the object as a timeval.
 operator const timeval * () const
 Returns a pointer to the object as a timeval.
time_t sec (void) const
 Get seconds.
void sec (time_t sec)
 Set seconds.
suseconds_t usec (void) const
 Get microseconds.
void usec (suseconds_t usec)
 Set microseconds.
void to_usec (ACE_UINT64 &usec) const
ACE_Time_Valueoperator+= (const ACE_Time_Value &tv)
 Add tv to this.
ACE_Time_Valueoperator+= (time_t tv)
 Add tv to this.
ACE_Time_Valueoperator= (const ACE_Time_Value &tv)
 Assign @ tv to this.
ACE_Time_Valueoperator= (time_t tv)
 Assign @ tv to this.
ACE_Time_Valueoperator-= (const ACE_Time_Value &tv)
 Subtract tv to this.
ACE_Time_Valueoperator-= (time_t tv)
 Substract tv to this.
ACE_Time_Valueoperator*= (double d)
 Multiply the time value by the d factor.
ACE_Time_Value operator++ (int)
 Increment microseconds as postfix.
ACE_Time_Valueoperator++ (void)
 Increment microseconds as prefix.
ACE_Time_Value operator-- (int)
 Decrement microseconds as postfix.
ACE_Time_Valueoperator-- (void)
 Decrement microseconds as prefix.
void dump (void) const
 Dump is a no-op.

Static Public Attributes

static const ACE_Time_Value zero
 Constant "0".
static const ACE_Time_Value max_time

Private Member Functions

void normalize (bool saturate=false)
 Put the timevalue into a canonical form.

Private Attributes

timeval tv_
 Store the values as a timeval.

Friends

ACE_Export ACE_Time_Value operator+ (const ACE_Time_Value &tv1, const ACE_Time_Value &tv2)
 Adds two ACE_Time_Value objects together, returns the sum.
ACE_Export ACE_Time_Value operator- (const ACE_Time_Value &tv1, const ACE_Time_Value &tv2)
 Subtracts two ACE_Time_Value objects, returns the difference.
ACE_Export bool operator< (const ACE_Time_Value &tv1, const ACE_Time_Value &tv2)
 True if tv1 < tv2.
ACE_Export bool operator> (const ACE_Time_Value &tv1, const ACE_Time_Value &tv2)
 True if tv1 > tv2.
ACE_Export bool operator<= (const ACE_Time_Value &tv1, const ACE_Time_Value &tv2)
 True if tv1 <= tv2.
ACE_Export bool operator>= (const ACE_Time_Value &tv1, const ACE_Time_Value &tv2)
 True if tv1 >= tv2.
ACE_Export bool operator== (const ACE_Time_Value &tv1, const ACE_Time_Value &tv2)
 True if tv1 == tv2.
ACE_Export bool operator!= (const ACE_Time_Value &tv1, const ACE_Time_Value &tv2)
 True if tv1 != tv2.

ACE_Export ACE_Time_Value operator* (double d, const ACE_Time_Value &tv)
 Multiplies the time value by d.
ACE_Export ACE_Time_Value operator* (const ACE_Time_Value &tv, double d)
 Multiplies the time value by d.

Detailed Description

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 <select>, <poll>, or <cond_timedwait>.

Definition at line 60 of file Time_Value.h.


Constructor & Destructor Documentation

ACE_Time_Value::ACE_Time_Value ( void   ) 

Default Constructor.

Definition at line 107 of file Time_Value.inl.

     : tv_ ()
{
  // ACE_OS_TRACE ("ACE_Time_Value::ACE_Time_Value");
  this->set (0, 0);
}

ACE_Time_Value::ACE_Time_Value ( time_t  sec,
suseconds_t  usec = 0 
) [explicit]

Constructor.

Definition at line 115 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::ACE_Time_Value");
  this->set (sec, usec);
}

ACE_Time_Value::ACE_Time_Value ( const struct timeval &  t  )  [explicit]

Construct the ACE_Time_Value from a timeval.

Definition at line 36 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::ACE_Time_Value");
  this->set (tv);
}

ACE_Time_Value::ACE_Time_Value ( const timespec_t t  )  [explicit]

Construct the ACE_Time_Value object from a timespec_t.

Initializes the ACE_Time_Value object from a timespec_t.

Definition at line 294 of file Time_Value.inl.

     : tv_ ()
{
  // ACE_OS_TRACE ("ACE_Time_Value::ACE_Time_Value");
  this->set (tv);
}


Member Function Documentation

void ACE_Time_Value::dump ( void   )  const

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 ACE_Log_Msg is at a higher level.

Definition at line 157 of file Time_Value.cpp.

{
#if defined (ACE_HAS_DUMP)
  // ACE_OS_TRACE ("ACE_Time_Value::dump");
#if 0
  ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ntv_sec_ = %d"), this->tv_.tv_sec));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ntv_usec_ = %d\n"), this->tv_.tv_usec));
  ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
#endif /* 0 */
#endif /* ACE_HAS_DUMP */
}

ACE_UINT64 ACE_Time_Value::get_msec (  )  const

Converts from ACE_Time_Value format into milliseconds format.

Returns:
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.

Definition at line 151 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::get_msec");
  ACE_UINT64 ms = ACE_Utils::truncate_cast<ACE_UINT64> (this->tv_.tv_sec);
  ms *= 1000;
  ms += (this->tv_.tv_usec / 1000);
  return ms;
}

void ACE_Time_Value::msec ( ACE_UINT64 ms  ) 

Converts from ACE_Time_Value format into milliseconds format.

Returns:
Sum of second field (in milliseconds) and microsecond field (in milliseconds) and return them via the
Parameters:
ms parameter.
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.

Definition at line 168 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::msec");
  const ACE_Time_Value *tv = this;
  tv->msec (ms);
}

void ACE_Time_Value::msec ( long  milliseconds  ) 

Converts from milli-seconds format into ACE_Time_Value format.

Converts from milli-seconds format into 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.

Definition at line 188 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::msec");
  // Convert millisecond units to seconds;
  long secs = milliseconds / 1000;
  this->tv_.tv_sec = secs;
  // Convert remainder to microseconds;
  this->tv_.tv_usec = (milliseconds - (secs * 1000)) * 1000;
}

void ACE_Time_Value::msec ( int  milliseconds  ) 

Converts from milli-seconds format into ACE_Time_Value format.

Converts from milli-seconds format into 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.

Definition at line 200 of file Time_Value.inl.

{
  ACE_Time_Value::msec (static_cast<long> (milliseconds));
}

unsigned long ACE_Time_Value::msec ( void   )  const

Converts from ACE_Time_Value format into milliseconds format.

Converts from Time_Value format into milli-seconds format.

Returns:
Sum of second field (in milliseconds) and microsecond field (in milliseconds). Note that this method can overflow if the second and microsecond field values are large, so use the msec (ACE_UINT64 &ms) method instead.
Note:
The semantics of this method differs from the sec() and usec() methods. There is no analogous "millisecond" component in an ACE_Time_Value.

Definition at line 139 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::msec");

  // Note - we're truncating a value here, which can lose data. This is
  // called out in the user documentation for this with a recommendation to
  // use msec(ACE_UINT64&) instead, so just go ahead and truncate.
  time_t secs = this->tv_.tv_sec * 1000 + this->tv_.tv_usec / 1000;
  return ACE_Utils::truncate_cast<unsigned long> (secs);
}

void ACE_Time_Value::msec ( ACE_UINT64 ms  )  const

Converts from ACE_Time_Value format into milliseconds format.

Returns:
Sum of second field (in milliseconds) and microsecond field (in milliseconds) and return them via the
Parameters:
ms parameter.
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.

Definition at line 161 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::msec");
  ms = this->get_msec ();
}

void ACE_Time_Value::normalize ( bool  saturate = false  )  [private]

Put the timevalue into a canonical form.

Todo:
This loop needs some optimization.
Todo:
This loop needs some optimization.

Definition at line 171 of file Time_Value.cpp.

{
  // // ACE_OS_TRACE ("ACE_Time_Value::normalize");
  // From Hans Rohnert...

  if (this->tv_.tv_usec >= ACE_ONE_SECOND_IN_USECS)
    {
      /*! \todo This loop needs some optimization.
       */
      if (!saturate) // keep the conditionnal expression outside the while loop to minimize performance cost
        do
          {
            ++this->tv_.tv_sec;
            this->tv_.tv_usec -= ACE_ONE_SECOND_IN_USECS;
          }
        while (this->tv_.tv_usec >= ACE_ONE_SECOND_IN_USECS);
      else
        do
          if (this->tv_.tv_sec < ACE_Numeric_Limits<time_t>::max())
            {
              ++this->tv_.tv_sec;
              this->tv_.tv_usec -= ACE_ONE_SECOND_IN_USECS;
            }
          else
            this->tv_.tv_usec = ACE_ONE_SECOND_IN_USECS - 1;
        while (this->tv_.tv_usec >= ACE_ONE_SECOND_IN_USECS);
    }
  else if (this->tv_.tv_usec <= -ACE_ONE_SECOND_IN_USECS)
    {
      /*! \todo This loop needs some optimization.
       */
      if (!saturate)
        do
          {
            --this->tv_.tv_sec;
            this->tv_.tv_usec += ACE_ONE_SECOND_IN_USECS;
          }
        while (this->tv_.tv_usec <= -ACE_ONE_SECOND_IN_USECS);
      else
        do
          if (this->tv_.tv_sec > ACE_Numeric_Limits<time_t>::min())
            {
              --this->tv_.tv_sec;
              this->tv_.tv_usec += ACE_ONE_SECOND_IN_USECS;
            }
          else
            this->tv_.tv_usec = -ACE_ONE_SECOND_IN_USECS + 1;
        while (this->tv_.tv_usec <= -ACE_ONE_SECOND_IN_USECS);
    }

  if (this->tv_.tv_sec >= 1 && this->tv_.tv_usec < 0)
    {
      --this->tv_.tv_sec;
      this->tv_.tv_usec += ACE_ONE_SECOND_IN_USECS;
    }
  // tv_sec in qnxnto is unsigned
#if !defined ( __QNXNTO__)
  else if (this->tv_.tv_sec < 0 && this->tv_.tv_usec > 0)
    {
      ++this->tv_.tv_sec;
      this->tv_.tv_usec -= ACE_ONE_SECOND_IN_USECS;
    }
#endif /* __QNXNTO__  */
}

ACE_Time_Value::operator const timeval * (  )  const

Returns a pointer to the object as a timeval.

Definition at line 43 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::operator const timeval *");
#if defined (ACE_HAS_TIME_T_LONG_MISMATCH)
  // Recall that on some Windows we substitute another type for timeval in tv_
  ACE_Time_Value *me = const_cast<ACE_Time_Value*> (this);
  me->ext_tv_.tv_sec = ACE_Utils::truncate_cast<long> (this->tv_.tv_sec);
  me->ext_tv_.tv_usec = ACE_Utils::truncate_cast<long> (this->tv_.tv_usec);
  return (const timeval *) &this->ext_tv_;
#else
  return (const timeval *) &this->tv_;
#endif /* ACE_HAS_TIME_T_LONG_MISMATCH */
}

ACE_Time_Value::operator timespec_t (  )  const

Returns the value of the object as a timespec_t.

Definition at line 282 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::operator timespec_t");
  timespec_t tv;
  tv.tv_sec = this->sec ();
  // Convert microseconds into nanoseconds.
  tv.tv_nsec = this->tv_.tv_usec * 1000;
  return tv;
}

ACE_Time_Value::operator timeval (  )  const

Returns the value of the object as a timeval.

Definition at line 11 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::operator timeval");
#if defined (ACE_HAS_TIME_T_LONG_MISMATCH)
  // Recall that on some Windows we substitute another type for timeval in tv_
  ACE_Time_Value *me = const_cast<ACE_Time_Value*> (this);
  me->ext_tv_.tv_sec = ACE_Utils::truncate_cast<long> (this->tv_.tv_sec);
  me->ext_tv_.tv_usec = ACE_Utils::truncate_cast<long> (this->tv_.tv_usec);
  return this->ext_tv_;
#else
  return this->tv_;
#endif /* ACE_HAS_TIME_T_LONG_MISMATCH */
}

ACE_Time_Value & ACE_Time_Value::operator*= ( double  d  ) 

Multiply the time value by the d factor.

Note:
The result of the operator is valid for results from range < (ACE_INT32_MIN, -999999), (ACE_INT32_MAX, 999999) >. Result outside this range are saturated to a limit.

Definition at line 238 of file Time_Value.cpp.

{
  // To work around the lack of precision of a long double to contain
  // a 64-bits time_t + 6 digits after the decimal point for the usec part,
  // we perform the multiplication of the 2 timeval parts separately.
  //
  // This extra precision step is adding a cost when transfering the
  // seconds resulting from the usec multiplication.  This operation
  // correspond to the normalization process performed in normalize()
  // but we must absolutly do it here because the usec multiplication
  // result value could exceed what can be stored in a suseconds_t
  // type variable.
  //
  // Since this is a costly operation, we try to detect as soon as
  // possible if we are having a saturation in order to abort the rest
  // of the computation.
  typedef ACE::If_Then_Else<(sizeof (double) > sizeof (time_t)),
    double,
    long double>::result_type float_type;

  float_type sec_total = static_cast<float_type> (this->sec());
  sec_total *= d;

  // shall we saturate the result?
  static const float_type max_int =
    ACE_Numeric_Limits<time_t>::max() + 0.999999;
  static const float_type min_int =
    ACE_Numeric_Limits<time_t>::min() - 0.999999;

  if (sec_total > max_int)
    {
      this->set(ACE_Numeric_Limits<time_t>::max(), ACE_ONE_SECOND_IN_USECS-1);
    }
  else if (sec_total < min_int)
    {
      this->set(ACE_Numeric_Limits<time_t>::min(), -ACE_ONE_SECOND_IN_USECS+1);
    }
  else
    {
      time_t time_sec = static_cast<time_t> (sec_total);

      float_type usec_total = this->usec();
      usec_total *= d;

      // adding usec resulting from tv_sec mult
      usec_total += (sec_total-time_sec) * ACE_ONE_SECOND_IN_USECS;

      // extract seconds component of the usec mult
      sec_total = usec_total / ACE_ONE_SECOND_IN_USECS;
      // keep remaining usec
      if (sec_total > 0)
        {
          usec_total = (sec_total - ACE_OS::floor(sec_total));
        }
      else
        {
          usec_total = (sec_total - ACE_OS::ceil(sec_total));
        }

      sec_total -= usec_total;
      usec_total *= ACE_ONE_SECOND_IN_USECS;

      // add the seconds component of the usec mult with the tv_sec mult prod.
      sec_total += time_sec;

      // recheck for saturation
      if (sec_total > max_int)
        {
          this->set (ACE_Numeric_Limits<time_t>::max(), ACE_ONE_SECOND_IN_USECS - 1);
        }
      else if (sec_total < min_int)
        {
          this->set (ACE_Numeric_Limits<time_t>::min(), -ACE_ONE_SECOND_IN_USECS + 1);
        }
      else
        {
          time_sec = static_cast<time_t> (sec_total);
          suseconds_t time_usec = static_cast<suseconds_t> (usec_total);

          // round up the result to save the last usec
          if (time_usec > 0 && (usec_total - time_usec) >= 0.5)
            {
              ++time_usec;
            }
          else if (time_usec < 0 && (usec_total - time_usec) <= -0.5)
            {
              --time_usec;
            }

          this->set (time_sec, time_usec);
        }
    }
  return *this;
}

ACE_Time_Value ACE_Time_Value::operator++ ( int   ) 

Increment microseconds as postfix.

Note:
The only reason this is here is to allow the use of ACE_Atomic_Op with ACE_Time_Value.

Increment microseconds (the only reason this is here is to allow the use of ACE_Atomic_Op with ACE_Time_Value).

Definition at line 41 of file Time_Value.cpp.

{
  // ACE_OS_TRACE ("ACE_Time_Value::operator ++ (int)");
  ACE_Time_Value tv (*this);
  ++*this;
  return tv;
}

ACE_Time_Value & ACE_Time_Value::operator++ ( void   ) 

Increment microseconds as prefix.

Note:
The only reason this is here is to allow the use of ACE_Atomic_Op with ACE_Time_Value.

Definition at line 50 of file Time_Value.cpp.

{
  // ACE_OS_TRACE ("ACE_Time_Value::operator ++ (void)");
  this->usec (this->usec () + 1);
  this->normalize ();
  return *this;
}

ACE_Time_Value & ACE_Time_Value::operator+= ( const ACE_Time_Value tv  ) 

Add tv to this.

Add TV to this.

Definition at line 340 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::operator+=");
  this->sec (this->sec () + tv.sec ());
  this->usec (this->usec () + tv.usec ());
  this->normalize ();
  return *this;
}

ACE_Time_Value & ACE_Time_Value::operator+= ( time_t  tv  ) 

Add tv to this.

Definition at line 350 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::operator+=");
  this->sec (this->sec () + tv);
  return *this;
}

ACE_Time_Value ACE_Time_Value::operator-- ( int   ) 

Decrement microseconds as postfix.

Note:
The only reason this is here is to allow the use of ACE_Atomic_Op with ACE_Time_Value.

Decrement microseconds (the only reason this is here is / to allow the use of ACE_Atomic_Op with ACE_Time_Value).

Definition at line 61 of file Time_Value.cpp.

{
  // ACE_OS_TRACE ("ACE_Time_Value::operator -- (int)");
  ACE_Time_Value tv (*this);
  --*this;
  return tv;
}

ACE_Time_Value & ACE_Time_Value::operator-- ( void   ) 

Decrement microseconds as prefix.

Note:
The only reason this is here is to allow the use of ACE_Atomic_Op with ACE_Time_Value.

Definition at line 70 of file Time_Value.cpp.

{
  // ACE_OS_TRACE ("ACE_Time_Value::operator -- (void)");
  this->usec (this->usec () - 1);
  this->normalize ();
  return *this;
}

ACE_Time_Value & ACE_Time_Value::operator-= ( const ACE_Time_Value tv  ) 

Subtract tv to this.

Subtract TV to this.

Definition at line 377 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::operator-=");
  this->sec (this->sec () - tv.sec ());
  this->usec (this->usec () - tv.usec ());
  this->normalize ();
  return *this;
}

ACE_Time_Value & ACE_Time_Value::operator-= ( time_t  tv  ) 

Substract tv to this.

Definition at line 387 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::operator-=");
  this->sec (this->sec () - tv);
  return *this;
}

ACE_Time_Value & ACE_Time_Value::operator= ( const ACE_Time_Value tv  ) 

Assign @ tv to this.

Definition at line 358 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::operator=");
  this->sec (tv.sec ());
  this->usec (tv.usec ());
  return *this;
}

ACE_Time_Value & ACE_Time_Value::operator= ( time_t  tv  ) 

Assign @ tv to this.

Definition at line 367 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::operator=");
  this->sec (tv);
  this->usec (0);
  return *this;
}

void ACE_Time_Value::sec ( time_t  sec  ) 

Set seconds.

Sets the number of seconds.

Definition at line 131 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::sec");
  this->tv_.tv_sec = ACE_Utils::truncate_cast<long> (sec);
}

time_t ACE_Time_Value::sec ( void   )  const

Get seconds.

Returns number of seconds.

Returns:
The second field/component of this ACE_Time_Value.
Note:
The semantics of this method differs from the msec() method.

Definition at line 123 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::sec");
  return this->tv_.tv_sec;
}

void ACE_Time_Value::set ( time_t  sec,
suseconds_t  usec 
)

Initializes the ACE_Time_Value from seconds and useconds.

Definition at line 58 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::set");
# if defined (_WIN32_WCE) && (_WIN32_WCE == 0x600) && !defined (_USE_32BIT_TIME_T) && defined (_MSC_VER)
    // The WinCE 6.0 SDK ships with a timeval tv_sec member that uses long as type
    // not time_t. This resolves in compilation warnings because time_t
    // can be 64bit. Disable at this momemt the warning for just this method
    // else we get a compile warnings each time this inline file is included
    // this file.
#   pragma warning (push)
#   pragma warning (disable: 4244)
# endif
  this->tv_.tv_sec = sec;
# if defined (_WIN32_WCE) && (_WIN32_WCE == 0x600) && !defined (_USE_32BIT_TIME_T) && defined (_MSC_VER)
#   pragma warning (pop)
# endif
  this->tv_.tv_usec = usec;
#if __GNUC__
  if (__builtin_constant_p(sec) &&
      __builtin_constant_p(usec) &&
      (sec >= 0 && usec >= 0 && usec < ACE_ONE_SECOND_IN_USECS))
    return;
#endif
  this->normalize ();
}

void ACE_Time_Value::set ( const timeval &  t  ) 

Initializes the ACE_Time_Value from a timeval.

Definition at line 26 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::set");
  this->tv_.tv_sec = tv.tv_sec;
  this->tv_.tv_usec = tv.tv_usec;

  this->normalize ();
}

void ACE_Time_Value::set ( double  d  ) 

Initializes the ACE_Time_Value from a double, which is assumed to be in second format, with any remainder treated as microseconds.

Definition at line 85 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::set");
  long l = (long) d;
  this->tv_.tv_sec = l;
  this->tv_.tv_usec = (suseconds_t) ((d - (double) l) * ACE_ONE_SECOND_IN_USECS + .5);
  this->normalize ();
}

void ACE_Time_Value::set ( const timespec_t tv  ) 

Initializes the ACE_Time_Value object from a timespec_t.

Initializes a timespec_t. Note that this approach loses precision since it converts the nano-seconds into micro-seconds. But then again, do any real systems have nano-second timer precision?!

Definition at line 98 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::set");

  this->set (tv.tv_sec,
             tv.tv_nsec / 1000); // Convert nanoseconds into microseconds.
}

void ACE_Time_Value::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 usec() methods. There is no analogous "millisecond" component in an ACE_Time_Value.

Definition at line 176 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::set_msec");
  // Convert millisecond units to seconds;
  ACE_UINT64 secs = ms / 1000;
  this->tv_.tv_sec = static_cast<long> (secs);
  // Convert remainder to microseconds;
  this->tv_.tv_usec = static_cast<long>((ms - (secs * 1000)) * 1000);
}

void ACE_Time_Value::to_usec ( ACE_UINT64 usec  )  const
Returns:
Sum of second field (in microseconds) and microsecond field and return them via the
Parameters:
usec parameter.

Definition at line 222 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::to_usec");

#if defined (ACE_LACKS_UNSIGNEDLONGLONG_T)
  usec = ACE_U_LongLong (static_cast<long long> (this->tv_.tv_sec));
#elif defined (ACE_LACKS_LONGLONG_T)
  // No native 64-bit type, meaning time_t is most likely 32 bits.
  usec = ACE_U_LongLong (this->tv_.tv_sec);
#else
  usec = static_cast<ACE_UINT64> (this->tv_.tv_sec);
#endif  /* ACE_LACKS_LONGLONG_T */
  usec *= 1000000;
  usec += this->tv_.tv_usec;
}

void ACE_Time_Value::usec ( suseconds_t  usec  ) 

Set microseconds.

Sets the number of micro-seconds.

Definition at line 215 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::usec");
  this->tv_.tv_usec = usec;
}

suseconds_t ACE_Time_Value::usec ( void   )  const

Get microseconds.

Returns number of micro-seconds.

Returns:
The microsecond field/component of this ACE_Time_Value.
Note:
The semantics of this method differs from the msec() method.

Definition at line 207 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("ACE_Time_Value::usec");
  return this->tv_.tv_usec;
}


Friends And Related Function Documentation

ACE_Export bool operator!= ( const ACE_Time_Value tv1,
const ACE_Time_Value tv2 
) [friend]

True if tv1 != tv2.

Definition at line 331 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("operator !=");
  return !(tv1 == tv2);
}

ACE_Export ACE_Time_Value operator* ( double  d,
const ACE_Time_Value tv 
) [friend]

Multiplies the time value by d.

Definition at line 239 of file Time_Value.inl.

{
  return ACE_Time_Value (tv) *= d;
}

ACE_Export ACE_Time_Value operator* ( const ACE_Time_Value tv,
double  d 
) [friend]

Multiplies the time value by d.

Definition at line 245 of file Time_Value.inl.

{
  return ACE_Time_Value (tv) *= d;
}

ACE_Export ACE_Time_Value operator+ ( const ACE_Time_Value tv1,
const ACE_Time_Value tv2 
) [friend]

Adds two ACE_Time_Value objects together, returns the sum.

Definition at line 396 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("operator +");
  ACE_Time_Value sum (tv1);
  sum += tv2;

  return sum;
}

ACE_Export ACE_Time_Value operator- ( const ACE_Time_Value tv1,
const ACE_Time_Value tv2 
) [friend]

Subtracts two ACE_Time_Value objects, returns the difference.

Definition at line 408 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("operator -");
  ACE_Time_Value delta (tv1);
  delta -= tv2;

  return delta;
}

ACE_Export bool operator< ( const ACE_Time_Value tv1,
const ACE_Time_Value tv2 
) [friend]

True if tv1 < tv2.

Definition at line 303 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("operator <");
  return tv2 > tv1;
}

ACE_Export bool operator<= ( const ACE_Time_Value tv1,
const ACE_Time_Value tv2 
) [friend]

True if tv1 <= tv2.

Definition at line 312 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("operator <=");
  return tv2 >= tv1;
}

ACE_Export bool operator== ( const ACE_Time_Value tv1,
const ACE_Time_Value tv2 
) [friend]

True if tv1 == tv2.

Definition at line 321 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("operator ==");
  return tv1.sec () == tv2.sec ()
    && tv1.usec () == tv2.usec ();
}

ACE_Export bool operator> ( const ACE_Time_Value tv1,
const ACE_Time_Value tv2 
) [friend]

True if tv1 > tv2.

Definition at line 252 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("operator >");
  if (tv1.sec () > tv2.sec ())
    return 1;
  else if (tv1.sec () == tv2.sec ()
           && tv1.usec () > tv2.usec ())
    return 1;
  else
    return 0;
}

ACE_Export bool operator>= ( const ACE_Time_Value tv1,
const ACE_Time_Value tv2 
) [friend]

True if tv1 >= tv2.

Definition at line 267 of file Time_Value.inl.

{
  // ACE_OS_TRACE ("operator >=");
  if (tv1.sec () > tv2.sec ())
    return 1;
  else if (tv1.sec () == tv2.sec ()
           && tv1.usec () >= tv2.usec ())
    return 1;
  else
    return 0;
}


Member Data Documentation

Constant for maximum time representable. Note that this time is not intended for use with <select> 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 ACE_Dynamic_Message_Queue class.

Definition at line 75 of file Time_Value.h.

timeval ACE_Time_Value::tv_ [private]

Store the values as a timeval.

Definition at line 371 of file Time_Value.h.

Constant "0".

Definition at line 65 of file Time_Value.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines