00001 #include "ace/Countdown_Time.h" 00002 #include "ace/OS_NS_sys_time.h" 00003 00004 ACE_RCSID (ace, 00005 Countdown_Time, 00006 "$Id: Countdown_Time.cpp 85382 2009-05-19 06:52:56Z johnnyw $") 00007 00008 #if !defined (__ACE_INLINE__) 00009 #include "ace/Countdown_Time.inl" 00010 #endif /* __ACE_INLINE__ */ 00011 00012 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00013 00014 ACE_Countdown_Time::ACE_Countdown_Time (ACE_Time_Value *max_wait_time) 00015 : max_wait_time_ (max_wait_time), 00016 stopped_ (false) 00017 { 00018 this->start (); 00019 } 00020 00021 ACE_Countdown_Time::~ACE_Countdown_Time (void) 00022 { 00023 this->stop (); 00024 } 00025 00026 void 00027 ACE_Countdown_Time::start (void) 00028 { 00029 if (this->max_wait_time_ != 0) 00030 { 00031 this->start_time_ = ACE_OS::gettimeofday (); 00032 this->stopped_ = false; 00033 } 00034 } 00035 00036 void 00037 ACE_Countdown_Time::stop (void) 00038 { 00039 if (this->max_wait_time_ != 0 && !this->stopped_) 00040 { 00041 ACE_Time_Value const elapsed_time = 00042 ACE_OS::gettimeofday () - this->start_time_; 00043 00044 if (elapsed_time >= ACE_Time_Value::zero && 00045 *this->max_wait_time_ > elapsed_time) 00046 { 00047 *this->max_wait_time_ -= elapsed_time; 00048 } 00049 else 00050 { 00051 // Used all of timeout. 00052 *this->max_wait_time_ = ACE_Time_Value::zero; 00053 // errno = ETIME; 00054 } 00055 this->stopped_ = true; 00056 } 00057 } 00058 00059 ACE_END_VERSIONED_NAMESPACE_DECL