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