summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2014-09-04 01:36:30 +0000
committerChris Wilson <chris+github@qwirx.com>2014-09-04 01:36:30 +0000
commit3fef08a2f462e33e3b0a7c344cf507a4277cc604 (patch)
tree291d410bc61825e29198cb5801bd1d875fce8bad /lib
parent812e01faaa17a675a1f473969211fec33c95d4b9 (diff)
Refactor Timer reschedule to avoid second scan over timer list.
Merged back changes from the test refactor branch to reduce diffs.
Diffstat (limited to 'lib')
-rw-r--r--lib/common/Timer.cpp34
1 files changed, 8 insertions, 26 deletions
diff --git a/lib/common/Timer.cpp b/lib/common/Timer.cpp
index e0a4b7f7..b7d7a673 100644
--- a/lib/common/Timer.cpp
+++ b/lib/common/Timer.cpp
@@ -256,6 +256,8 @@ void Timers::Reschedule()
// win32 timers need no management
#else
box_time_t timeNow = GetCurrentBoxTime();
+ int64_t timeToNextEvent;
+ std::string nameOfNextEvent;
// scan for, trigger and remove expired timers. Removal requires
// us to restart the scan each time, due to std::vector semantics.
@@ -263,6 +265,7 @@ void Timers::Reschedule()
while (restart)
{
restart = false;
+ timeToNextEvent = 0;
for (std::vector<Timer*>::iterator i = spTimers->begin();
i != spTimers->end(); i++)
@@ -290,35 +293,14 @@ void Timers::Reschedule()
" seconds");
*/
}
- }
- }
-
- // Now the only remaining timers should all be in the future.
- // Scan to find the next one to fire (earliest deadline).
-
- int64_t timeToNextEvent = 0;
- std::string nameOfNextEvent;
-
- for (std::vector<Timer*>::iterator i = spTimers->begin();
- i != spTimers->end(); i++)
- {
- Timer& rTimer = **i;
- int64_t timeToExpiry = rTimer.GetExpiryTime() - timeNow;
- ASSERT(timeToExpiry > 0)
- if (timeToExpiry <= 0)
- {
- timeToExpiry = 1;
- }
-
- if (timeToNextEvent == 0 || timeToNextEvent > timeToExpiry)
- {
- timeToNextEvent = timeToExpiry;
- nameOfNextEvent = rTimer.GetName();
+ if (timeToNextEvent == 0 || timeToNextEvent > timeToExpiry)
+ {
+ timeToNextEvent = timeToExpiry;
+ nameOfNextEvent = rTimer.GetName();
+ }
}
}
-
- ASSERT(timeToNextEvent >= 0);
if (timeToNextEvent == 0)
{