core: use a Monitor in BoxCollection

This commit is contained in:
Mitchell Hashimoto 2014-01-22 11:10:20 -08:00
parent a03bc763f9
commit 5253da79cd
1 changed files with 3 additions and 13 deletions

View File

@ -1,5 +1,5 @@
require "digest/sha1" require "digest/sha1"
require "thread" require "monitor"
require "tmpdir" require "tmpdir"
require "log4r" require "log4r"
@ -44,7 +44,7 @@ module Vagrant
options ||= {} options ||= {}
@directory = directory @directory = directory
@lock = Mutex.new @lock = Monitor.new
@temp_root = options[:temp_dir_root] @temp_root = options[:temp_dir_root]
@logger = Log4r::Logger.new("vagrant::box_collection") @logger = Log4r::Logger.new("vagrant::box_collection")
end end
@ -361,17 +361,7 @@ module Vagrant
# This locks the region given by the block with a lock on this # This locks the region given by the block with a lock on this
# collection. # collection.
def with_collection_lock def with_collection_lock
lock = @lock @lock.synchronize do
begin
lock.synchronize {}
rescue ThreadError
# If we already hold the lock, just create a new lock so
# we definitely don't block and don't get an error.
lock = Mutex.new
end
lock.synchronize do
return yield return yield
end end
end end