Thread.critical does not exist in ruby 1.9 anymore
authorGuillaume Cottenceau <gcottenc@gmail.com>
Fri, 3 Sep 2010 07:24:29 +0000 (09:24 +0200)
committerGuillaume Cottenceau <gcottenc@gmail.com>
Fri, 3 Sep 2010 07:24:29 +0000 (09:24 +0200)
bin/booh
lib/booh/booh-lib.rb

index 7b66e2e..a5db624 100644 (file)
--- a/bin/booh
+++ b/bin/booh
@@ -2181,11 +2181,9 @@ end
 
 def call_backend(cmd, waitmsg, mode, params)
     pipe = Tempfile.new("boohpipe")
-    Thread.critical = true
     path = pipe.path
     pipe.close!
     system("mkfifo #{path}")
-    Thread.critical = false
     cmd += " --info-pipe #{path}"
     button, w8 = backend_wait_message($main_window, waitmsg, path, mode)
     pid = nil
@@ -3039,12 +3037,10 @@ def open_file_user(filename)
         $orig_filename = $filename
         $main_window.title = 'booh - ' + File.basename($orig_filename)
         tmp = Tempfile.new("boohtemp")
-        Thread.critical = true
         $filename = tmp.path
         tmp.close!
         #- for security
         ios = File.open($filename, File::RDWR|File::CREAT|File::EXCL)
-        Thread.critical = false
         ios.close
         $tempfiles << $filename << "#{$filename}.backup"
     else
index d44e865..0f034cd 100644 (file)
@@ -341,6 +341,8 @@ module Booh
         gen_thumbnails(orig, allow_background, dests, xmldirorelem, type + '-')
     end
 
+    $video_thumbnail_directory_lock = Monitor.new
+
     def gen_video_thumbnail(orig, colorswap, seektime)
         if colorswap
             #- ignored for the moment. is mplayer subject to blue faces problem?
@@ -348,16 +350,15 @@ module Booh
         #- it's not possible to specify a basename for the output jpeg file with mplayer (file will be named 00000001.jpg); as this can
         #- be called from multiple threads, we must come up with a unique directory where to put the file
         tmpfile = Tempfile.new("boohvideotmp")
-        Thread.critical = true
-        tmpdirname = tmpfile.path
-        tmpfile.close!
-        begin
-            Dir.mkdir(tmpdirname)
-        rescue Errno::EEXIST
-            raise "Tmp directory #{tmpdirname} already exists"
-        ensure
-            Thread.critical = false
-        end
+        $video_thumbnail_directory_lock.synchronize {
+            tmpdirname = tmpfile.path
+            tmpfile.close!
+            begin
+                Dir.mkdir(tmpdirname)
+            rescue Errno::EEXIST
+                raise "Tmp directory #{tmpdirname} already exists"
+            end
+        }
         cmd = "mplayer '#{orig}' -nosound -vo jpeg:outdir='#{tmpdirname}' -frames 1 -ss #{seektime} -slave >/dev/null 2>/dev/null"
         sys(cmd)
         if ! File.exists?("#{tmpdirname}/00000001.jpg")