00001
00002
00003
00004
00005 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00006
00007 #if defined (ACE_WIN32) && defined (_WIN32_WCE)
00008
00009
00010
00011
00012
00013
00014 extern "C++" {
00015 #endif
00016
00017
00018
00019 ACE_INLINE
00020 ACE_Time_Value::operator timeval () const
00021 {
00022
00023 return this->tv_;
00024 }
00025
00026 ACE_INLINE void
00027 ACE_Time_Value::set (const timeval &tv)
00028 {
00029
00030 this->tv_.tv_sec = tv.tv_sec;
00031 this->tv_.tv_usec = tv.tv_usec;
00032
00033 this->normalize ();
00034 }
00035
00036 ACE_INLINE
00037 ACE_Time_Value::ACE_Time_Value (const struct timeval &tv)
00038
00039 {
00040
00041 this->set (tv);
00042 }
00043
00044 ACE_INLINE
00045 ACE_Time_Value::operator const timeval * () const
00046 {
00047
00048 return (const timeval *) &this->tv_;
00049 }
00050
00051 ACE_INLINE void
00052 ACE_Time_Value::set (time_t sec, suseconds_t usec)
00053 {
00054
00055 #if defined (ACE_WIN64) \
00056 || (defined (ACE_WIN32) && !defined (_USE_32BIT_TIME_T))
00057
00058
00059 if (sec > LONG_MAX)
00060 this->tv_.tv_sec = LONG_MAX;
00061 else if (sec < LONG_MIN)
00062 this->tv_.tv_sec = LONG_MIN;
00063 else
00064 this->tv_.tv_sec = static_cast<long> (sec);
00065 #else
00066 this->tv_.tv_sec = sec;
00067 #endif
00068 this->tv_.tv_usec = usec;
00069 #if __GNUC__
00070 if (__builtin_constant_p(sec) &&
00071 __builtin_constant_p(usec) &&
00072 (sec >= 0 && usec >= 0 && usec < ACE_ONE_SECOND_IN_USECS))
00073 return;
00074 #endif
00075 this->normalize ();
00076 }
00077
00078 ACE_INLINE void
00079 ACE_Time_Value::set (double d)
00080 {
00081
00082 long l = (long) d;
00083 this->tv_.tv_sec = l;
00084 this->tv_.tv_usec = (suseconds_t) ((d - (double) l) * ACE_ONE_SECOND_IN_USECS + .5);
00085 this->normalize ();
00086 }
00087
00088
00089
00090
00091
00092 ACE_INLINE void
00093 ACE_Time_Value::set (const timespec_t &tv)
00094 {
00095
00096
00097 this->set (tv.tv_sec,
00098 tv.tv_nsec / 1000);
00099 }
00100
00101 ACE_INLINE
00102 ACE_Time_Value::ACE_Time_Value (void)
00103
00104 {
00105
00106 this->set (0, 0);
00107 }
00108
00109 ACE_INLINE
00110 ACE_Time_Value::ACE_Time_Value (time_t sec, suseconds_t usec)
00111 {
00112
00113 this->set (sec, usec);
00114 }
00115
00116
00117
00118 ACE_INLINE time_t
00119 ACE_Time_Value::sec (void) const
00120 {
00121
00122 return this->tv_.tv_sec;
00123 }
00124
00125
00126
00127 ACE_INLINE void
00128 ACE_Time_Value::sec (time_t sec)
00129 {
00130
00131 #if defined (ACE_WIN64) \
00132 || (defined (ACE_WIN32) && !defined (_USE_32BIT_TIME_T))
00133
00134
00135 if (sec > LONG_MAX)
00136 this->tv_.tv_sec = LONG_MAX;
00137 else if (sec < LONG_MIN)
00138 this->tv_.tv_sec = LONG_MIN;
00139 else
00140 this->tv_.tv_sec = static_cast<long> (sec);
00141 #else
00142 this->tv_.tv_sec = sec;
00143 #endif
00144 }
00145
00146
00147
00148 ACE_INLINE unsigned long
00149 ACE_Time_Value::msec (void) const
00150 {
00151
00152 return this->tv_.tv_sec * 1000 + this->tv_.tv_usec / 1000;
00153 }
00154
00155 #if !defined (ACE_LACKS_LONGLONG_T)
00156 ACE_INLINE void
00157 ACE_Time_Value::msec (ACE_UINT64 &ms) const
00158 {
00159
00160 ms = static_cast<ACE_UINT64> (this->tv_.tv_sec);
00161 ms *= 1000;
00162 ms += (this->tv_.tv_usec / 1000);
00163 }
00164 #endif
00165
00166
00167
00168 ACE_INLINE void
00169 ACE_Time_Value::msec (long milliseconds)
00170 {
00171
00172
00173 this->tv_.tv_sec = milliseconds / 1000;
00174
00175 this->tv_.tv_usec = (milliseconds - (this->tv_.tv_sec * 1000)) * 1000;
00176 }
00177
00178
00179
00180 ACE_INLINE suseconds_t
00181 ACE_Time_Value::usec (void) const
00182 {
00183
00184 return this->tv_.tv_usec;
00185 }
00186
00187
00188
00189 ACE_INLINE void
00190 ACE_Time_Value::usec (suseconds_t usec)
00191 {
00192
00193 this->tv_.tv_usec = usec;
00194 }
00195
00196 #if !defined (ACE_LACKS_LONGLONG_T)
00197 ACE_INLINE void
00198 ACE_Time_Value::to_usec (ACE_UINT64 &usec) const
00199 {
00200
00201 usec = static_cast<ACE_UINT64> (this->tv_.tv_sec);
00202 usec *= 1000000;
00203 usec += this->tv_.tv_usec;
00204 }
00205 #endif
00206
00207 ACE_INLINE ACE_Time_Value
00208 operator * (double d, const ACE_Time_Value &tv)
00209 {
00210 return ACE_Time_Value (tv) *= d;
00211 }
00212
00213 ACE_INLINE ACE_Time_Value
00214 operator * (const ACE_Time_Value &tv, double d)
00215 {
00216 return ACE_Time_Value (tv) *= d;
00217 }
00218
00219
00220
00221 ACE_INLINE bool
00222 operator > (const ACE_Time_Value &tv1,
00223 const ACE_Time_Value &tv2)
00224 {
00225
00226 if (tv1.sec () > tv2.sec ())
00227 return 1;
00228 else if (tv1.sec () == tv2.sec ()
00229 && tv1.usec () > tv2.usec ())
00230 return 1;
00231 else
00232 return 0;
00233 }
00234
00235
00236
00237 ACE_INLINE bool
00238 operator >= (const ACE_Time_Value &tv1,
00239 const ACE_Time_Value &tv2)
00240 {
00241
00242 if (tv1.sec () > tv2.sec ())
00243 return 1;
00244 else if (tv1.sec () == tv2.sec ()
00245 && tv1.usec () >= tv2.usec ())
00246 return 1;
00247 else
00248 return 0;
00249 }
00250
00251
00252
00253 ACE_INLINE
00254 ACE_Time_Value::operator timespec_t () const
00255 {
00256
00257 timespec_t tv;
00258 tv.tv_sec = this->sec ();
00259
00260 tv.tv_nsec = this->tv_.tv_usec * 1000;
00261 return tv;
00262 }
00263
00264
00265
00266 ACE_INLINE
00267 ACE_Time_Value::ACE_Time_Value (const timespec_t &tv)
00268
00269 {
00270
00271 this->set (tv);
00272 }
00273
00274
00275
00276 ACE_INLINE bool
00277 operator < (const ACE_Time_Value &tv1,
00278 const ACE_Time_Value &tv2)
00279 {
00280
00281 return tv2 > tv1;
00282 }
00283
00284
00285
00286 ACE_INLINE bool
00287 operator <= (const ACE_Time_Value &tv1,
00288 const ACE_Time_Value &tv2)
00289 {
00290
00291 return tv2 >= tv1;
00292 }
00293
00294
00295
00296 ACE_INLINE bool
00297 operator == (const ACE_Time_Value &tv1,
00298 const ACE_Time_Value &tv2)
00299 {
00300
00301 return tv1.sec () == tv2.sec ()
00302 && tv1.usec () == tv2.usec ();
00303 }
00304
00305
00306
00307 ACE_INLINE bool
00308 operator != (const ACE_Time_Value &tv1,
00309 const ACE_Time_Value &tv2)
00310 {
00311
00312 return !(tv1 == tv2);
00313 }
00314
00315
00316
00317 ACE_INLINE ACE_Time_Value &
00318 ACE_Time_Value::operator+= (const ACE_Time_Value &tv)
00319 {
00320
00321 this->sec (this->sec () + tv.sec ());
00322 this->usec (this->usec () + tv.usec ());
00323 this->normalize ();
00324 return *this;
00325 }
00326
00327 ACE_INLINE ACE_Time_Value &
00328 ACE_Time_Value::operator+= (time_t tv)
00329 {
00330
00331 this->sec (this->sec () + tv);
00332 return *this;
00333 }
00334
00335 ACE_INLINE ACE_Time_Value &
00336 ACE_Time_Value::operator= (const ACE_Time_Value &tv)
00337 {
00338
00339 this->sec (tv.sec ());
00340 this->usec (tv.usec ());
00341 return *this;
00342 }
00343
00344 ACE_INLINE ACE_Time_Value &
00345 ACE_Time_Value::operator= (time_t tv)
00346 {
00347
00348 this->sec (tv);
00349 this->usec (0);
00350 return *this;
00351 }
00352
00353
00354
00355 ACE_INLINE ACE_Time_Value &
00356 ACE_Time_Value::operator-= (const ACE_Time_Value &tv)
00357 {
00358
00359 this->sec (this->sec () - tv.sec ());
00360 this->usec (this->usec () - tv.usec ());
00361 this->normalize ();
00362 return *this;
00363 }
00364
00365 ACE_INLINE ACE_Time_Value &
00366 ACE_Time_Value::operator-= (time_t tv)
00367 {
00368
00369 this->sec (this->sec () - tv);
00370 return *this;
00371 }
00372
00373
00374
00375 ACE_INLINE ACE_Time_Value
00376 operator + (const ACE_Time_Value &tv1,
00377 const ACE_Time_Value &tv2)
00378 {
00379
00380 ACE_Time_Value sum (tv1);
00381 sum += tv2;
00382
00383 return sum;
00384 }
00385
00386
00387
00388 ACE_INLINE ACE_Time_Value
00389 operator - (const ACE_Time_Value &tv1,
00390 const ACE_Time_Value &tv2)
00391 {
00392
00393 ACE_Time_Value delta (tv1);
00394 delta -= tv2;
00395
00396 return delta;
00397 }
00398
00399 #if defined (ACE_WIN32) && defined (_WIN32_WCE)
00400 }
00401 #endif
00402
00403 ACE_END_VERSIONED_NAMESPACE_DECL