mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-28 02:44:53 +00:00
fhem.pl: change InternalTimer from hash to array (Forum #81365)
git-svn-id: https://svn.fhem.de/fhem/trunk@16214 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
c6b5798613
commit
c13dede001
75
fhem/fhem.pl
75
fhem/fhem.pl
@ -237,7 +237,8 @@ use vars qw(%data); # Hash for user data
|
|||||||
use vars qw(%defaultattr); # Default attributes, used by FHEM2FHEM
|
use vars qw(%defaultattr); # Default attributes, used by FHEM2FHEM
|
||||||
use vars qw(%defs); # FHEM device/button definitions
|
use vars qw(%defs); # FHEM device/button definitions
|
||||||
use vars qw(%inform); # Used by telnet_ActivateInform
|
use vars qw(%inform); # Used by telnet_ActivateInform
|
||||||
use vars qw(%intAt); # Internal at timer hash, global for benchmark
|
use vars qw(%intAt); # Internal timer hash, used by apptime
|
||||||
|
use vars qw(@intAtA); # Internal timer array
|
||||||
use vars qw(%logInform); # Used by FHEMWEB/Event-Monitor
|
use vars qw(%logInform); # Used by FHEMWEB/Event-Monitor
|
||||||
use vars qw(%modules); # List of loaded modules (device/log/etc)
|
use vars qw(%modules); # List of loaded modules (device/log/etc)
|
||||||
use vars qw(%ntfyHash); # hash of devices needed to be notified.
|
use vars qw(%ntfyHash); # hash of devices needed to be notified.
|
||||||
@ -3069,29 +3070,21 @@ HandleTimeout()
|
|||||||
}
|
}
|
||||||
|
|
||||||
$nextat = 0;
|
$nextat = 0;
|
||||||
#############
|
while(@intAtA) {
|
||||||
# Check the internal list.
|
my $at = $intAtA[0];
|
||||||
foreach my $i (sort { $intAt{$a}{TRIGGERTIME} <=>
|
my $tim = $at->{TRIGGERTIME};
|
||||||
$intAt{$b}{TRIGGERTIME} }
|
if($tim && $tim > $now) {
|
||||||
grep { $intAt{$_}{TRIGGERTIME} <= $now } # sort is slow
|
$nextat = $tim;
|
||||||
keys %intAt) {
|
last;
|
||||||
$i = "" if(!defined($i)); # Forum #40598
|
|
||||||
next if(!$intAt{$i}); # deleted in the loop
|
|
||||||
my $tim = $intAt{$i}{TRIGGERTIME};
|
|
||||||
my $fn = $intAt{$i}{FN};
|
|
||||||
if(!defined($tim) || !defined($fn)) {
|
|
||||||
delete($intAt{$i});
|
|
||||||
next;
|
|
||||||
}
|
}
|
||||||
no strict "refs";
|
delete $intAt{$at->{atNr}} if($at->{atNr});
|
||||||
&{$fn}($intAt{$i}{ARG});
|
shift(@intAtA);
|
||||||
use strict "refs";
|
|
||||||
delete($intAt{$i});
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach my $i (keys %intAt) {
|
if($tim && $at->{FN}) {
|
||||||
my $tim = $intAt{$i}{TRIGGERTIME};
|
no strict "refs";
|
||||||
$nextat = $tim if(defined($tim) && (!$nextat || $nextat > $tim));
|
&{$at->{FN}}($at->{ARG});
|
||||||
|
use strict "refs";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(%prioQueues) {
|
if(%prioQueues) {
|
||||||
@ -3128,11 +3121,27 @@ InternalTimer($$$;$)
|
|||||||
use strict "refs";
|
use strict "refs";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$intAt{$intAtCnt}{TRIGGERTIME} = $tim;
|
|
||||||
$intAt{$intAtCnt}{FN} = $fn;
|
|
||||||
$intAt{$intAtCnt}{ARG} = $arg;
|
|
||||||
$intAtCnt++;
|
|
||||||
$nextat = $tim if(!$nextat || $nextat > $tim);
|
$nextat = $tim if(!$nextat || $nextat > $tim);
|
||||||
|
my %h = (TRIGGERTIME=>$tim, FN=>$fn, ARG=>$arg, atNr=>++$intAtCnt);
|
||||||
|
$intAt{$h{atNr}} = \%h;
|
||||||
|
|
||||||
|
if(!@intAtA) {
|
||||||
|
push @intAtA, \%h;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $idx = $#intAtA; # binary insert
|
||||||
|
my ($lowerIdx,$upperIdx) = (0, $idx);
|
||||||
|
while($lowerIdx <= $upperIdx) {
|
||||||
|
$idx = int(($upperIdx-$lowerIdx)/2)+$lowerIdx;
|
||||||
|
if($tim >= $intAtA[$idx]->{TRIGGERTIME}) {
|
||||||
|
$lowerIdx = ++$idx;
|
||||||
|
} else {
|
||||||
|
$upperIdx = $idx-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
splice(@intAtA, $idx, 0, \%h);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
@ -3140,10 +3149,16 @@ RemoveInternalTimer($;$)
|
|||||||
{
|
{
|
||||||
my ($arg, $fn) = @_;
|
my ($arg, $fn) = @_;
|
||||||
return if(!$arg && !$fn);
|
return if(!$arg && !$fn);
|
||||||
foreach my $a (keys %intAt) {
|
|
||||||
my ($ia, $if) = ($intAt{$a}{ARG}, $intAt{$a}{FN});
|
for(my $i=0; $i<@intAtA; $i++) {
|
||||||
delete($intAt{$a}) if((!$arg || ($ia && $ia eq $arg)) &&
|
my ($ia, $if) = ($intAtA[$i]->{ARG}, $intAtA[$i]->{FN});
|
||||||
(!$fn || ($if && $if eq $fn)));
|
if((!$arg || ($ia && $ia eq $arg)) &&
|
||||||
|
(!$fn || ($if && $if eq $fn))) {
|
||||||
|
my $t = $intAtA[$i]->{atNr};
|
||||||
|
delete $intAt{$t} if($intAt{$t});
|
||||||
|
splice @intAtA, $i, 1;
|
||||||
|
$i--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user