mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-19 00:26:03 +00:00
fhem.pl: add prioQueues, by Torsten, modified (Forum #77890)
git-svn-id: https://svn.fhem.de/fhem/trunk@15289 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
b9fde8ed3b
commit
dcbd85eb18
31
fhem/fhem.pl
31
fhem/fhem.pl
@ -241,6 +241,7 @@ use vars qw(@authenticate); # List of authentication devices
|
|||||||
use vars qw(@authorize); # List of authorization devices
|
use vars qw(@authorize); # List of authorization devices
|
||||||
use vars qw(@structChangeHist); # Contains the last 10 structural changes
|
use vars qw(@structChangeHist); # Contains the last 10 structural changes
|
||||||
use vars qw($haveInet6); # Using INET6
|
use vars qw($haveInet6); # Using INET6
|
||||||
|
use vars qw(%prioQueues); #
|
||||||
|
|
||||||
$selectTimestamp = gettimeofday();
|
$selectTimestamp = gettimeofday();
|
||||||
$cvsid = '$Id$';
|
$cvsid = '$Id$';
|
||||||
@ -3004,6 +3005,28 @@ CommandSleep($$)
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#####################################
|
||||||
|
# Add a function to be executed after select returns. Only one function is
|
||||||
|
# executed after select returns.
|
||||||
|
# fn: a function reference
|
||||||
|
# arg: function argument
|
||||||
|
# nice: a number like in unix "nice". Smaller numbers mean higher priority.
|
||||||
|
# limited to [-20,19], default 0
|
||||||
|
# returns the number of elements in the corrsponding queue
|
||||||
|
sub
|
||||||
|
PrioQueue_add($$;$)
|
||||||
|
{
|
||||||
|
my ($fn, $arg, $nice) = @_;
|
||||||
|
|
||||||
|
$nice = 0 if(not defined($nice) || !looks_like_number($nice));
|
||||||
|
$nice = -20 if($nice <-20);
|
||||||
|
$nice = 19 if($nice > 19);
|
||||||
|
$nextat = 1;
|
||||||
|
$prioQueues{$nice} = [] if(!defined $prioQueues{$nice});
|
||||||
|
push(@{$prioQueues{$nice}},{fn=>$fn, arg=>$arg});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
# Return the time to the next event (or undef if there is none)
|
# Return the time to the next event (or undef if there is none)
|
||||||
# and call each function which was scheduled for this time
|
# and call each function which was scheduled for this time
|
||||||
@ -3041,6 +3064,14 @@ HandleTimeout()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(%prioQueues) {
|
||||||
|
my $nice = minNum(keys %prioQueues);
|
||||||
|
my $entry = shift(@{$prioQueues{$nice}});
|
||||||
|
delete $prioQueues{$nice} if(!@{$prioQueues{$nice}});
|
||||||
|
&{$entry->{fn}}($entry->{arg});
|
||||||
|
$nextat = 1 if(%prioQueues);
|
||||||
|
}
|
||||||
|
|
||||||
if(!$nextat) {
|
if(!$nextat) {
|
||||||
$selectTimestamp = $now;
|
$selectTimestamp = $now;
|
||||||
return undef;
|
return undef;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user