chiark / gitweb /
check parallel
[version-charset-test.git] / check
diff --git a/check b/check
index df4b83f411f64bbbfb296834fb86fda1deab805d..72933711c3ad9a4a96e69b6722f89e212600c771 100755 (executable)
--- a/check
+++ b/check
@@ -9,8 +9,8 @@ cd stunt
 #exec 3<&0 </dev/null
 
 git init
-git commit --allow-empty -m 'Test object'
-head=`git rev-parse HEAD`
+#git commit --allow-empty -m 'Test object'
+#head=`git rev-parse HEAD`
 
 #exec <&3 3<&-
 
@@ -19,26 +19,59 @@ perl -we '
 
     our $file;
     our $count;
+    our $batch=0;
+    our @tasks;
+
+    my $ncpus = eval {
+        require Sys::CPU;
+       Sys::CPU::cpu_count();
+    } // 3;
+
+$ncpus=1;
+    print STDERR "check using $ncpus cpus\n";
+
+    sub await_task () {
+       my ($pid, $oldbatch) = @{ shift @tasks };
+       waitpid $pid, 0 == $pid or die $!;
+       die "$oldbatch $?" if $?;
+       unlink $oldbatch or die "$oldbatch $!";
+        print STDERR "check completed $oldbatch [$pid]\n";
+    }
 
     sub complete_batch () {
-        if ($file) {
-            print STDERR "completing batch ($_)\n";
-            close $file or die $!;
-            system "git update-ref --stdin <batch"
-                and die "$? $!";
-        }
+        return unless $file;
+
+       close $file or die $!;
+
+        print STDERR "check closing $batch ($count)\n";
+
+       await_task if @tasks >= $ncpus;
+
+       my $pid = fork // die $!;
+       if (!$pid) {
+           close STDIN;
+#            seek STDIN,0,1;
+#            flush STDIN;
+           open STDIN, "<", $batch or die $batch;
+           exec qw(git update-ref --stdin);
+           die $!;
+       }
+        print STDERR "check spawned $batch ($count) [$pid]\n";
+       push @tasks, [ $pid, $batch ];
+       $batch++;
        $file = undef;
        $count = 0;
     }
 
     while (<>) {
-print STDERR ">$_<\n";
-        $file ||= new IO::File "batch", ">" or die $!;
+#print STDERR ">$_<\n";
+        $file ||= new IO::File $batch, ">" or die $!;
         chomp;
-       print $file "create refs/tags/$_ '$head'\n" or die $!;
-       $count++ < 1000 or complete_batch;
+       print $file "delete refs/tags/$_\n" or die $!;
+       $count++ < 100000 or complete_batch;
     }
-print STDERR "FOO\n";
+#print STDERR "FOO\n";
     STDIN->error and die $!;
     complete_batch();
+    await_task while @tasks;
 '