Thread.critical does not exist in ruby 1.9 anymore
[booh] / lib / booh / booh-lib.rb
index d44e8650d5044160762146cac42a7ad8d245a92d..0f034cdc6dffc486d5c6620d341da2cc90c715e7 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")