[Box Backup-commit] COMMIT r3385 - box/trunk/lib/common
subversion at boxbackup.org
subversion at boxbackup.org
Thu Sep 4 02:36:30 BST 2014
Author: chris
Date: 2014-09-04 02:36:30 +0100 (Thu, 04 Sep 2014)
New Revision: 3385
Modified:
box/trunk/lib/common/Timer.cpp
Log:
Refactor Timer reschedule to avoid second scan over timer list.
Merged back changes from the test refactor branch to reduce diffs.
Modified: box/trunk/lib/common/Timer.cpp
===================================================================
--- box/trunk/lib/common/Timer.cpp 2014-09-04 01:36:28 UTC (rev 3384)
+++ box/trunk/lib/common/Timer.cpp 2014-09-04 01:36:30 UTC (rev 3385)
@@ -256,6 +256,8 @@
// 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 @@
while (restart)
{
restart = false;
+ timeToNextEvent = 0;
for (std::vector<Timer*>::iterator i = spTimers->begin();
i != spTimers->end(); i++)
@@ -290,35 +293,14 @@
" 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)
{
More information about the Boxbackup-commit
mailing list