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 #if !defined (ACE_LACKS_LONGLONG_T)
00155 ACE_INLINE void
00156 ACE_Time_Value::msec (ACE_UINT64 &ms) const
00157 {
00158
00159 ms = static_cast<ACE_UINT64> (this->tv_.tv_sec);
00160 ms *= 1000;
00161 ms += (this->tv_.tv_usec / 1000);
00162 }
00163 #endif
00164
00165
00166
00167 ACE_INLINE void
00168 ACE_Time_Value::msec (long milliseconds)
00169 {
00170
00171
00172 long secs = milliseconds / 1000;
00173 this->tv_.tv_sec = secs;
00174
00175 this->tv_.tv_usec = (milliseconds - (secs * 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 ACE_INLINE void
00197 ACE_Time_Value::to_usec (ACE_UINT64 & usec) const
00198 {
00199
00200
00201 #if defined (ACE_LACKS_UNSIGNEDLONGLONG_T)
00202 usec = ACE_U_LongLong (static_cast<long long> (this->tv_.tv_sec));
00203 #elif defined (ACE_LACKS_LONGLONG_T)
00204
00205 usec = ACE_U_LongLong (this->tv_.tv_sec);
00206 #else
00207 usec = static_cast<ACE_UINT64> (this->tv_.tv_sec);
00208 #endif
00209 usec *= 1000000;
00210 usec += this->tv_.tv_usec;
00211 }
00212
00213 ACE_INLINE ACE_Time_Value
00214 operator * (double d, const ACE_Time_Value &tv)
00215 {
00216 return ACE_Time_Value (tv) *= d;
00217 }
00218
00219 ACE_INLINE ACE_Time_Value
00220 operator * (const ACE_Time_Value &tv, double d)
00221 {
00222 return ACE_Time_Value (tv) *= d;
00223 }
00224
00225
00226
00227 ACE_INLINE bool
00228 operator > (const ACE_Time_Value &tv1,
00229 const ACE_Time_Value &tv2)
00230 {
00231
00232 if (tv1.sec () > tv2.sec ())
00233 return 1;
00234 else if (tv1.sec () == tv2.sec ()
00235 && tv1.usec () > tv2.usec ())
00236 return 1;
00237 else
00238 return 0;
00239 }
00240
00241
00242
00243 ACE_INLINE bool
00244 operator >= (const ACE_Time_Value &tv1,
00245 const ACE_Time_Value &tv2)
00246 {
00247
00248 if (tv1.sec () > tv2.sec ())
00249 return 1;
00250 else if (tv1.sec () == tv2.sec ()
00251 && tv1.usec () >= tv2.usec ())
00252 return 1;
00253 else
00254 return 0;
00255 }
00256
00257
00258
00259 ACE_INLINE
00260 ACE_Time_Value::operator timespec_t () const
00261 {
00262
00263 timespec_t tv;
00264 tv.tv_sec = this->sec ();
00265
00266 tv.tv_nsec = this->tv_.tv_usec * 1000;
00267 return tv;
00268 }
00269
00270
00271
00272 ACE_INLINE
00273 ACE_Time_Value::ACE_Time_Value (const timespec_t &tv)
00274
00275 {
00276
00277 this->set (tv);
00278 }
00279
00280
00281
00282 ACE_INLINE bool
00283 operator < (const ACE_Time_Value &tv1,
00284 const ACE_Time_Value &tv2)
00285 {
00286
00287 return tv2 > tv1;
00288 }
00289
00290
00291
00292 ACE_INLINE bool
00293 operator <= (const ACE_Time_Value &tv1,
00294 const ACE_Time_Value &tv2)
00295 {
00296
00297 return tv2 >= tv1;
00298 }
00299
00300
00301
00302 ACE_INLINE bool
00303 operator == (const ACE_Time_Value &tv1,
00304 const ACE_Time_Value &tv2)
00305 {
00306
00307 return tv1.sec () == tv2.sec ()
00308 && tv1.usec () == tv2.usec ();
00309 }
00310
00311
00312
00313 ACE_INLINE bool
00314 operator != (const ACE_Time_Value &tv1,
00315 const ACE_Time_Value &tv2)
00316 {
00317
00318 return !(tv1 == tv2);
00319 }
00320
00321
00322
00323 ACE_INLINE ACE_Time_Value &
00324 ACE_Time_Value::operator+= (const ACE_Time_Value &tv)
00325 {
00326
00327 this->sec (this->sec () + tv.sec ());
00328 this->usec (this->usec () + tv.usec ());
00329 this->normalize ();
00330 return *this;
00331 }
00332
00333 ACE_INLINE ACE_Time_Value &
00334 ACE_Time_Value::operator+= (time_t tv)
00335 {
00336
00337 this->sec (this->sec () + tv);
00338 return *this;
00339 }
00340
00341 ACE_INLINE ACE_Time_Value &
00342 ACE_Time_Value::operator= (const ACE_Time_Value &tv)
00343 {
00344
00345 this->sec (tv.sec ());
00346 this->usec (tv.usec ());
00347 return *this;
00348 }
00349
00350 ACE_INLINE ACE_Time_Value &
00351 ACE_Time_Value::operator= (time_t tv)
00352 {
00353
00354 this->sec (tv);
00355 this->usec (0);
00356 return *this;
00357 }
00358
00359
00360
00361 ACE_INLINE ACE_Time_Value &
00362 ACE_Time_Value::operator-= (const ACE_Time_Value &tv)
00363 {
00364
00365 this->sec (this->sec () - tv.sec ());
00366 this->usec (this->usec () - tv.usec ());
00367 this->normalize ();
00368 return *this;
00369 }
00370
00371 ACE_INLINE ACE_Time_Value &
00372 ACE_Time_Value::operator-= (time_t tv)
00373 {
00374
00375 this->sec (this->sec () - tv);
00376 return *this;
00377 }
00378
00379
00380
00381 ACE_INLINE ACE_Time_Value
00382 operator + (const ACE_Time_Value &tv1,
00383 const ACE_Time_Value &tv2)
00384 {
00385
00386 ACE_Time_Value sum (tv1);
00387 sum += tv2;
00388
00389 return sum;
00390 }
00391
00392
00393
00394 ACE_INLINE ACE_Time_Value
00395 operator - (const ACE_Time_Value &tv1,
00396 const ACE_Time_Value &tv2)
00397 {
00398
00399 ACE_Time_Value delta (tv1);
00400 delta -= tv2;
00401
00402 return delta;
00403 }
00404
00405 #if defined (ACE_WIN32) && defined (_WIN32_WCE)
00406 }
00407 #endif
00408
00409 ACE_END_VERSIONED_NAMESPACE_DECL