]> mj.ucw.cz Git - bex.git/commitdiff
bprun: Recycle slots
authorMartin Mares <mj@ucw.cz>
Mon, 31 Oct 2011 16:05:10 +0000 (17:05 +0100)
committerMartin Mares <mj@ucw.cz>
Mon, 31 Oct 2011 16:05:10 +0000 (17:05 +0100)
bprun

diff --git a/bprun b/bprun
index b75a7fecee09264a2b9733fce13e43bc84918509..65dd08987866183b01b7bed5b3d85aa2605b1d73 100755 (executable)
--- a/bprun
+++ b/bprun
@@ -123,24 +123,37 @@ sub done($)
 
 sub get_slot($) {
        my ($mach) = @_;
-       if (defined $by_host{$mach}) {
-               return $by_host{$mach};
+       my $s;
+       if (defined ($s = $by_host{$mach})) {
+               delete $s->{'Gone'};
+       } else {
+               my ($best, $besti);
+               for my $i (0..$nrows-1) {
+                       my $r = $by_row[$i];
+                       if (!defined $r) {
+                               $besti = $i;
+                               $best = undef;
+                               last;
+                       } elsif ($r->{'Gone'} && (!$best || $best->{'Gone'} > $r->{'Gone'})) {
+                               $besti = $i;
+                               $best = $r;
+                       }
+               }
+               if ($best) {
+                       delete $by_host{$best->{'Host'}};
+               }
+               $s->{'Host'} = $mach;
+               $s->{'Row'} = $besti;
+               $by_host{$mach} = $s;
+               $by_row[$besti] = $s;
        }
-       my $s = {
-               'Host' => $mach,
-       };
-       my $i = 0;
-       while (defined $by_row[$i]) { $i++; }
-       $s->{'Row'} = $i;
-       $by_row[$i] = $s;
-       $by_host{$mach} = $s;
        return $s;
 }
 
+my $gone_counter = 1;
 sub delete_slot($) {
        my ($s) = @_;
-       delete $by_host{$s->{'Host'}};
-       $by_row[$s->{'Row'}] = undef;
+       $s->{'Gone'} = $gone_counter++;
 }
 
 sub redraw_slot($) {