Commit d55c255c authored by Russ Fish's avatar Russ Fish
Browse files

Fix the event queue times when Windows jumps the clock back 6 or 7 hours.

parent 04e0e4d6
......@@ -283,10 +283,14 @@ qinsert($curtime + $speakupiv, \&saysomething)
#
# Loop, sleeping and then processing events
#
my $lasttime = 0;
while (1) {
my ($nexttime, $event);
$curtime = time();
if ($curtime < $lasttime) {
qfix($lasttime - $curtime);
}
qhead($nexttime, $event) == 0 or
die("All timeouts disabled at $date!");
......@@ -298,6 +302,7 @@ while (1) {
die("All timeouts disabled at $date!");
$curtime = time();
}
$lasttime = $curtime;
sleep($nexttime - $curtime);
}
......@@ -980,3 +985,20 @@ sub qbinsearch {
else { return qbinsearch($timeout,$mid+1,$max,$first); }
}
}
#
# qfix($delta)
# The clock was set back on us, most likely on Windows as NTP changed the
# clock from UTC time to local time. Set all of the queue item and index
# timestamps back by the same amount to compensate.
#
sub qfix {
my ($delta) = @_;
logmsg("qfix: The clock was set back by $delta seconds.\n");
foreach my $ikey (keys %i) {
$i{$ikey} -= $delta;
}
for (my $qitem = 0; $qitem <= $#q; $qitem++) {
${$q[$qitem]}[0] -= $delta;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment