summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2006-11-26 19:54:00 +0000
committerChris Wilson <chris+github@qwirx.com>2006-11-26 19:54:00 +0000
commit065e0b531fe827c3a153a76493d11e3e2a73b9ea (patch)
tree06d7d962dc02c766b4a9c8dc73427581d65eb3b9 /lib
parent85b96251de8ecb23cac85e11ea5b9f57329f9270 (diff)
* Fix timer expiry calculation when timers expire in the past
* Fix handling of timers which never expire (zero deadline) (refs #9)
Diffstat (limited to 'lib')
-rw-r--r--lib/common/Timer.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/common/Timer.cpp b/lib/common/Timer.cpp
index cfeca3c5..5ebfc133 100644
--- a/lib/common/Timer.cpp
+++ b/lib/common/Timer.cpp
@@ -143,7 +143,7 @@ void Timers::Reschedule()
ASSERT(spTimers);
box_time_t timeNow = GetCurrentBoxTime();
- box_time_t timeToNextEvent = 0;
+ int64_t timeToNextEvent = 0;
for (std::vector<Timer*>::iterator i = spTimers->begin();
i != spTimers->end(); i++)
@@ -151,7 +151,8 @@ void Timers::Reschedule()
Timer& rTimer = **i;
ASSERT(!rTimer.HasExpired());
- box_time_t timeToExpiry = rTimer.GetExpiryTime() - timeNow;
+ int64_t timeToExpiry = rTimer.GetExpiryTime() - timeNow;
+ if (timeToExpiry <= 0) timeToExpiry = 1;
if (timeToNextEvent == 0 || timeToNextEvent > timeToExpiry)
{
@@ -203,7 +204,7 @@ void Timers::Signal()
Timer& rTimer = **i;
ASSERT(!rTimer.HasExpired());
- box_time_t timeToExpiry = rTimer.GetExpiryTime() - timeNow;
+ int64_t timeToExpiry = rTimer.GetExpiryTime() - timeNow;
if (timeToExpiry <= 0)
{
@@ -218,7 +219,14 @@ Timer::Timer(size_t timeoutSecs)
: mExpires(GetCurrentBoxTime() + SecondsToBoxTime(timeoutSecs)),
mExpired(false)
{
- Timers::Add(*this);
+ if (timeoutSecs == 0)
+ {
+ mExpires = 0;
+ }
+ else
+ {
+ Timers::Add(*this);
+ }
}
Timer::~Timer()
@@ -230,7 +238,10 @@ Timer::Timer(const Timer& rToCopy)
: mExpires(rToCopy.mExpires),
mExpired(rToCopy.mExpired)
{
- Timers::Add(*this);
+ if (mExpires != 0)
+ {
+ Timers::Add(*this);
+ }
}
Timer& Timer::operator=(const Timer& rToCopy)
@@ -238,10 +249,11 @@ Timer& Timer::operator=(const Timer& rToCopy)
Timers::Remove(*this);
mExpires = rToCopy.mExpires;
mExpired = rToCopy.mExpired;
- if (!mExpired)
+ if (!mExpired && mExpires != 0)
{
Timers::Add(*this);
}
+ return *this;
}
void Timer::OnExpire()