blob: 9d88167b1c09d99506b7aa0220275daefa37917d (
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
/* -*- C++ -*- */
// $Id$
// Time_Value.i
#include "ace/Trace.h"
// Don't put this in the class since it will expand the size! Also,
// can't make this an enum due to compiler bugs on some platforms...
static const long ONE_SECOND = 1000000L;
// Initializes the ACE_Time_Value object.
// Initializes a timestruc_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
// anyway?!
ACE_INLINE void
ACE_Time_Value::set (const timestruc_t &tv)
{
ACE_TRACE ("ACE_Time_Value::set");
this->tv_sec_ = tv.tv_sec;
this->tv_usec_ = tv.tv_nsec / 1000;
this->normalize ();
}
// Returns the value of the object as a timestruc_t.
ACE_INLINE
ACE_Time_Value::operator timestruc_t () const
{
ACE_TRACE ("ACE_Time_Value::operator timestruc_t");
timestruc_t tv;
tv.tv_sec = this->tv_sec_;
tv.tv_nsec = this->tv_usec_ * 1000;
return tv;
}
// Initializes the ACE_Time_Value object from a timestruc_t.
ACE_INLINE
ACE_Time_Value::ACE_Time_Value (const timestruc_t &tv)
{
ACE_TRACE ("ACE_Time_Value::ACE_Time_Value");
this->set (tv);
}
ACE_INLINE void
ACE_Time_Value::set (const timeval &tv)
{
ACE_TRACE ("ACE_Time_Value::set");
this->tv_sec_ = tv.tv_sec;
this->tv_usec_ = tv.tv_usec;
this->normalize ();
}
// Initializes the ACE_Time_Value object from another ACE_Time_Value
ACE_INLINE
ACE_Time_Value::ACE_Time_Value (const ACE_Time_Value &tv)
: tv_sec_ (tv.tv_sec_),
tv_usec_ (tv.tv_usec_)
{
ACE_TRACE ("ACE_Time_Value::ACE_Time_Value");
}
// Returns number of seconds.
ACE_INLINE long
ACE_Time_Value::sec (void) const
{
ACE_TRACE ("ACE_Time_Value::sec");
return this->tv_sec_;
}
// Sets the number of seconds.
ACE_INLINE void
ACE_Time_Value::sec (long sec)
{
ACE_TRACE ("ACE_Time_Value::sec");
this->tv_sec_ = sec;
}
// Converts from Time_Value format into milli-seconds format.
ACE_INLINE long
ACE_Time_Value::msec (void) const
{
ACE_TRACE ("ACE_Time_Value::msec");
return this->tv_sec_ * 1000 + this->tv_usec_ / 1000;
}
// Converts from milli-seconds format into Time_Value format.
ACE_INLINE void
ACE_Time_Value::msec (long milliseconds)
{
ACE_TRACE ("ACE_Time_Value::msec");
// Convert millisecond units to seconds;
this->tv_sec_ = milliseconds / 1000;
// Convert remainder to microseconds;
this->tv_usec_ = (milliseconds - (this->tv_sec_ * 1000)) * 1000;
}
// Returns number of micro-seconds.
ACE_INLINE long
ACE_Time_Value::usec (void) const
{
ACE_TRACE ("ACE_Time_Value::usec");
return this->tv_usec_;
}
// Sets the number of micro-seconds.
ACE_INLINE void
ACE_Time_Value::usec (long usec)
{
ACE_TRACE ("ACE_Time_Value::usec");
this->tv_usec_ = usec;
}
// True if tv1 < tv2.
ACE_INLINE int
operator < (const ACE_Time_Value &tv1,
const ACE_Time_Value &tv2)
{
ACE_TRACE ("operator <");
return tv2 > tv1;
}
// True if tv1 >= tv2.
ACE_INLINE int
operator <= (const ACE_Time_Value &tv1,
const ACE_Time_Value &tv2)
{
ACE_TRACE ("operator <=");
return tv2 >= tv1;
}
// True if tv1 == tv2.
ACE_INLINE int
operator == (const ACE_Time_Value &tv1,
const ACE_Time_Value &tv2)
{
ACE_TRACE ("operator ==");
return tv1.tv_sec_ == tv2.tv_sec_
&& tv1.tv_usec_ == tv2.tv_usec_;
}
// True if tv1 != tv2.
ACE_INLINE int
operator != (const ACE_Time_Value &tv1,
const ACE_Time_Value &tv2)
{
ACE_TRACE ("operator !=");
return !(tv1 == tv2);
}
|