@@ -700,6 +700,20 @@ sub plan_search ($$$$) {
# this period is entirely after the proposed slot;
# so no need to check this or any later periods
+ my $share_compat_ok = sub {
+ my ($eshare) = @_;
+ return 0 unless defined $req->{Shared};
+ return 0 unless $req->{Shared} eq $eshare->{Type};
+ if (defined $share_wear) {
+ $share_wear++ if $startevt->{Type} eq 'Start';
+ } else {
+ $share_wear= $eshare->{Wear}+1;
+ }
+ return 0 if $share_wear > $req->{SharedMaxWear};
+ return 0 if $eshare->{Shares} != $req->{SharedMaxTasks};
+ return 1;
+ };
+
next PERIOD if $endevt->{Time} <= $try_time;
# this period is entirely before the proposed slot;
# it doesn't overlap, but must check subsequent periods
@@ -711,15 +725,7 @@ sub plan_search ($$$$) {
my $eshare= $startevt->{Share};
if ($eshare) {
$dbgprint->("PLAN LOOP OVERLAP ESHARE");
- last CHECK unless defined $req->{Shared};
- last CHECK unless $req->{Shared} eq $eshare->{Type};
- if (defined $share_wear) {
- $share_wear++ if $startevt->{Type} eq 'Start';
- } else {
- $share_wear= $eshare->{Wear}+1;
- }
- last CHECK if $share_wear > $req->{SharedMaxWear};
- last CHECK if $eshare->{Shares} != $req->{SharedMaxTasks};
+ last CHECK unless $share_compat_ok->($eshare);
}
# We have suitable availability for this period
$dbgprint->("PLAN LOOP OVERLAP AVAIL OK");