blob: cd775d882b09b07e9a1b7eb2232aff3ee2babb06 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// $Id$
#ifndef ACE_COUNTDOWN_TIME_T_CPP
#define ACE_COUNTDOWN_TIME_T_CPP
#include "ace/Countdown_Time_T.h"
#if !defined (__ACE_INLINE__)
#include "ace/Countdown_Time_T.inl"
#endif /* __ACE_INLINE__ */
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
template <typename TIME_POLICY> ACE_INLINE
ACE_Countdown_Time_T<TIME_POLICY>::ACE_Countdown_Time_T (ACE_Time_Value *max_wait_time,
TIME_POLICY const & time_policy)
: time_policy_ (time_policy),
max_wait_time_ (max_wait_time),
max_wait_value_ (ACE_Time_Value::zero),
stopped_ (false)
{
this->start ();
}
template <typename TIME_POLICY> ACE_INLINE
ACE_Countdown_Time_T<TIME_POLICY>::~ACE_Countdown_Time_T (void)
{
this->stop ();
}
template <typename TIME_POLICY> ACE_INLINE void
ACE_Countdown_Time_T<TIME_POLICY>::start (void)
{
if (this->max_wait_time_ != 0)
{
this->max_wait_value_ = *this->max_wait_time_;
this->start_time_ = this->time_policy_ ();
this->stopped_ = false;
}
}
template <typename TIME_POLICY> ACE_INLINE void
ACE_Countdown_Time_T<TIME_POLICY>::stop (void)
{
if (this->max_wait_time_ != 0 && !this->stopped_)
{
ACE_Time_Value const elapsed_time =
this->time_policy_ () - this->start_time_;
if (elapsed_time >= ACE_Time_Value::zero &&
this->max_wait_value_ > elapsed_time)
{
*this->max_wait_time_ = this->max_wait_value_ - elapsed_time;
}
else
{
// Used all of timeout.
*this->max_wait_time_ = ACE_Time_Value::zero;
// errno = ETIME;
}
this->stopped_ = true;
}
}
ACE_END_VERSIONED_NAMESPACE_DECL
#endif /* ACE_COUNTDOWN_TIME_T_CPP */
|