2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-09 20:57:11 +00:00

fhem.pl: optimize HandleTimeout

git-svn-id: https://svn.fhem.de/fhem/trunk@15657 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2017-12-20 23:05:37 +00:00
parent ca4c96cdd0
commit 970b14d4e6

View File

@ -3061,12 +3061,13 @@ HandleTimeout()
return ($nextat-$now);
}
$now += 0.01;# need to cover min delay at least
$nextat = 0;
#############
# Check the internal list.
foreach my $i (sort { $intAt{$a}{TRIGGERTIME} <=>
$intAt{$b}{TRIGGERTIME} } keys %intAt) {
$intAt{$b}{TRIGGERTIME} }
grep { $intAt{$_}{TRIGGERTIME} <= $now } # sort is slow
keys %intAt) {
$i = "" if(!defined($i)); # Forum #40598
next if(!$intAt{$i}); # deleted in the loop
my $tim = $intAt{$i}{TRIGGERTIME};
@ -3074,14 +3075,16 @@ HandleTimeout()
if(!defined($tim) || !defined($fn)) {
delete($intAt{$i});
next;
} elsif($tim <= $now) {
no strict "refs";
&{$fn}($intAt{$i}{ARG});
use strict "refs";
delete($intAt{$i});
} else {
$nextat = $tim if(!$nextat || $nextat > $tim);
}
no strict "refs";
&{$fn}($intAt{$i}{ARG});
use strict "refs";
delete($intAt{$i});
}
foreach my $i (keys %intAt) {
my $tim = $intAt{$i}{TRIGGERTIME};
$nextat = $tim if(defined($tim) && (!$nextat || $nextat > $tim));
}
if(%prioQueues) {
@ -3100,7 +3103,7 @@ HandleTimeout()
$now = gettimeofday(); # if some callbacks took longer
$selectTimestamp = $now;
return ($now+ 0.01 < $nextat) ? ($nextat-$now) : 0.01;
return ($now < $nextat) ? ($nextat-$now) : 0;
}