summaryrefslogtreecommitdiff
path: root/lib/common/Timer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common/Timer.cpp')
-rw-r--r--lib/common/Timer.cpp66
1 files changed, 32 insertions, 34 deletions
diff --git a/lib/common/Timer.cpp b/lib/common/Timer.cpp
index a032f330..9ab45b92 100644
--- a/lib/common/Timer.cpp
+++ b/lib/common/Timer.cpp
@@ -129,6 +129,14 @@ void Timers::Remove(Timer& rTimer)
Reschedule();
}
+#define FORMAT_BOX_TIME(t) \
+ (BoxTimeToSeconds(t)) << "." << \
+ (BoxTimeToMicroSeconds(t) % MICRO_SEC_IN_SEC)
+
+#define FORMAT_MICROSECONDS(t) \
+ (int)(t / 1000000) << "." << \
+ (int)(t % 1000000)
+
// --------------------------------------------------------------------------
//
// Function
@@ -178,8 +186,7 @@ void Timers::Reschedule()
if (timeToExpiry <= 0)
{
- BOX_TRACE((int)(timeNow / 1000000) << "." <<
- (int)(timeNow % 1000000) <<
+ BOX_TRACE(FORMAT_MICROSECONDS(timeNow) <<
": timer " << *i << " has expired, "
"triggering it");
rTimer.OnExpire();
@@ -189,12 +196,10 @@ void Timers::Reschedule()
}
else
{
- BOX_TRACE((int)(timeNow / 1000000) << "." <<
- (int)(timeNow % 1000000) <<
+ BOX_TRACE(FORMAT_MICROSECONDS(timeNow) <<
": timer " << *i << " has not "
"expired, triggering in " <<
- (int)(timeToExpiry / 1000000) << "." <<
- (int)(timeToExpiry % 1000000) <<
+ FORMAT_MICROSECONDS(timeToExpiry) <<
" seconds");
}
}
@@ -260,22 +265,20 @@ Timer::Timer(size_t timeoutSecs)
: mExpires(GetCurrentBoxTime() + SecondsToBoxTime(timeoutSecs)),
mExpired(false)
{
- #if !defined NDEBUG && !defined WIN32
- struct timeval tv;
- gettimeofday(&tv, NULL);
+ #ifndef NDEBUG
+ box_time_t timeNow = GetCurrentBoxTime();
if (timeoutSecs == 0)
{
- BOX_TRACE(tv.tv_sec << "." << tv.tv_usec <<
+ BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
": timer " << this << " initialised for " <<
timeoutSecs << " secs, will not fire");
}
else
{
- BOX_TRACE(tv.tv_sec << "." << tv.tv_usec <<
+ BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
": timer " << this << " initialised for " <<
timeoutSecs << " secs, to fire at " <<
- (int)(mExpires / 1000000) << "." <<
- (int)(mExpires % 1000000));
+ FORMAT_MICROSECONDS(mExpires));
}
#endif
@@ -291,10 +294,9 @@ Timer::Timer(size_t timeoutSecs)
Timer::~Timer()
{
- #if !defined NDEBUG && !defined WIN32
- struct timeval tv;
- gettimeofday(&tv, NULL);
- BOX_TRACE(tv.tv_sec << "." << tv.tv_usec <<
+ #ifndef NDEBUG
+ box_time_t timeNow = GetCurrentBoxTime();
+ BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
": timer " << this << " destroyed");
#endif
@@ -305,24 +307,23 @@ Timer::Timer(const Timer& rToCopy)
: mExpires(rToCopy.mExpires),
mExpired(rToCopy.mExpired)
{
- #if !defined NDEBUG && !defined WIN32
- struct timeval tv;
- gettimeofday(&tv, NULL);
+ #ifndef NDEBUG
+ box_time_t timeNow = GetCurrentBoxTime();
if (mExpired)
{
- BOX_TRACE(tv.tv_sec << "." << tv.tv_usec <<
+ BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
": timer " << this << " initialised from timer " <<
&rToCopy << ", already expired, will not fire");
}
else if (mExpires == 0)
{
- BOX_TRACE(tv.tv_sec << "." << tv.tv_usec <<
+ BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
": timer " << this << " initialised from timer " <<
&rToCopy << ", no expiry, will not fire");
}
else
{
- BOX_TRACE(tv.tv_sec << "." << tv.tv_usec <<
+ BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
": timer " << this << " initialised from timer " <<
&rToCopy << " to fire at " <<
(int)(mExpires / 1000000) << "." <<
@@ -338,24 +339,23 @@ Timer::Timer(const Timer& rToCopy)
Timer& Timer::operator=(const Timer& rToCopy)
{
- #if !defined NDEBUG && !defined WIN32
- struct timeval tv;
- gettimeofday(&tv, NULL);
+ #ifndef NDEBUG
+ box_time_t timeNow = GetCurrentBoxTime();
if (rToCopy.mExpired)
{
- BOX_TRACE(tv.tv_sec << "." << tv.tv_usec <<
+ BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
": timer " << this << " initialised from timer " <<
&rToCopy << ", already expired, will not fire");
}
else if (rToCopy.mExpires == 0)
{
- BOX_TRACE(tv.tv_sec << "." << tv.tv_usec <<
+ BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
": timer " << this << " initialised from timer " <<
&rToCopy << ", no expiry, will not fire");
}
else
{
- BOX_TRACE(tv.tv_sec << "." << tv.tv_usec <<
+ BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
": timer " << this << " initialised from timer " <<
&rToCopy << " to fire at " <<
(int)(rToCopy.mExpires / 1000000) << "." <<
@@ -375,11 +375,9 @@ Timer& Timer::operator=(const Timer& rToCopy)
void Timer::OnExpire()
{
- #if !defined NDEBUG && !defined WIN32
- struct timeval tv;
- gettimeofday(&tv, NULL);
- BOX_TRACE(tv.tv_sec << "." << tv.tv_usec <<
- ": timer " << this << " fired");
+ #ifndef NDEBUG
+ box_time_t timeNow = GetCurrentBoxTime();
+ BOX_TRACE(FORMAT_BOX_TIME(timeNow) << ": timer " << this << " fired");
#endif
mExpired = true;