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