providers/virtualbox: wrap version set in mutex

This commit is contained in:
Mitchell Hashimoto 2015-11-19 11:19:56 -08:00
parent fb511a43d9
commit a75b14b769
1 changed files with 14 additions and 10 deletions

View File

@ -1,4 +1,5 @@
require "forwardable" require "forwardable"
require "thread"
require "log4r" require "log4r"
@ -20,6 +21,7 @@ module VagrantPlugins
# We cache the read VirtualBox version here once we have one, # We cache the read VirtualBox version here once we have one,
# since during the execution of Vagrant, it likely doesn't change. # since during the execution of Vagrant, it likely doesn't change.
@@version = nil @@version = nil
@@version_lock = Mutex.new
# The UUID of the virtual machine we represent # The UUID of the virtual machine we represent
attr_reader :uuid attr_reader :uuid
@ -36,6 +38,7 @@ module VagrantPlugins
@logger = Log4r::Logger.new("vagrant::provider::virtualbox::meta") @logger = Log4r::Logger.new("vagrant::provider::virtualbox::meta")
@uuid = uuid @uuid = uuid
@@version_lock.synchronize do
if !@@version if !@@version
# Read and assign the version of VirtualBox we know which # Read and assign the version of VirtualBox we know which
# specific driver to instantiate. # specific driver to instantiate.
@ -48,6 +51,7 @@ module VagrantPlugins
raise Vagrant::Errors::VirtualBoxNotDetected raise Vagrant::Errors::VirtualBoxNotDetected
end end
end end
end
# Instantiate the proper version driver for VirtualBox # Instantiate the proper version driver for VirtualBox
@logger.debug("Finding driver for VirtualBox version: #{@@version}") @logger.debug("Finding driver for VirtualBox version: #{@@version}")