more efficient white balance: parallelize more
authorgc <gc>
Mon, 13 Jun 2005 19:36:34 +0000 (19:36 +0000)
committergc <gc>
Mon, 13 Jun 2005 19:36:34 +0000 (19:36 +0000)
bin/booh-backend
lib/booh/booh-lib.rb

index 4b15471038f685a65f71459afbc24fcbad89c0c5..aeaa77768f2d9ea6597a2d7a1e188f21a2b8a98a 100755 (executable)
@@ -608,6 +608,7 @@ def walk_source_dir
                 thumbnail_dest_img = base_dest_img + "-#{$default_size['thumbnails']}.jpg"
                 gen_thumbnails_element("#{dir}/#{img}", xmldir, true, [ { 'filename' => thumbnail_dest_img, 'size' => $default_size['thumbnails'] } ])
             else
+                todo = []
                 for sizeobj in $images_size
                     size_fullscreen = sizeobj['fullscreen']
                     size_thumbnails = sizeobj['thumbnails']
@@ -615,9 +616,10 @@ def walk_source_dir
                     thumbnail_dest_img  = base_dest_img + "-#{size_thumbnails}.jpg"
                     fullscreen_images[sizeobj['name']] << File.basename(fullscreen_dest_img)
                     thumbnail_images[sizeobj['name']]  << File.basename(thumbnail_dest_img)
-                    gen_thumbnails_element("#{dir}/#{img}", xmldir, true, [ { 'filename' => fullscreen_dest_img, 'size' => size_fullscreen },
-                                                                            { 'filename' => thumbnail_dest_img, 'size' => size_thumbnails } ])
+                    todo << { 'filename' => fullscreen_dest_img, 'size' => size_fullscreen }
+                    todo << { 'filename' => thumbnail_dest_img,  'size' => size_thumbnails }
                 end
+                gen_thumbnails_element("#{dir}/#{img}", xmldir, true, todo)
                 if $limit_sizes =~ /original/
                     fullscreen_images['original'] << img
                 end
index df2d7d2fccdf8233e1263cb19ccfcc6bb0e6e734..4c55bfebb3129ce092a7a437636e94ffcff76438 100644 (file)
@@ -130,6 +130,18 @@ module Booh
         system(cmd)
     end
 
+    def waitjob
+        finished = Process.wait2
+        $pids.delete(finished[0])
+        $pids = $pids.find_all { |pid| Process.waitpid(pid, Process::WNOHANG) == nil }
+    end
+
+    def waitjobs
+        while $pids.length > 0
+            waitjob
+        end
+    end
+
     #- parallelizable sys
     def psys(cmd)
         if $mproc
@@ -141,9 +153,7 @@ module Booh
                 exit 0
             end
             if $pids.length == $mproc
-                finished = Process.wait2
-                $pids.delete(finished[0])
-                $pids = $pids.find_all { |pid| Process.waitpid(pid, Process::WNOHANG) == nil }
+                waitjob
             end
         else
             sys(cmd)
@@ -233,7 +243,6 @@ module Booh
                     sys(cmd)
                     if File.exists?(neworig)
                         orig = neworig
-                        allow_background = false
                     end
                 end
                 rotate = felem.attributes["#{attributes_prefix}rotate"]
@@ -264,6 +273,9 @@ module Booh
                 end
             end
             if neworig
+                if allow_background
+                    waitjobs
+                end
                 system("rm -f '#{neworig}'")
             end
             return true