1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Make variable accesses thread safe

git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@7127 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jamis Buck 2007-06-26 05:11:34 +00:00
parent 71de275182
commit d0b8e8b25d
2 changed files with 24 additions and 12 deletions

View file

@ -1,5 +1,7 @@
*SVN* *SVN*
* Make variable accesses thread safe [via Adrian Danieli]
* Make user input for yes/no prompts work correctly in the Mercurial module [Matthew Elder] * Make user input for yes/no prompts work correctly in the Mercurial module [Matthew Elder]
* Use single quotes to escape semicolon in find command, instead of a backslash [via michael.italia@gmail.com] * Use single quotes to escape semicolon in find command, instead of a backslash [via michael.italia@gmail.com]

View file

@ -1,3 +1,5 @@
require 'thread'
module Capistrano module Capistrano
class Configuration class Configuration
module Variables module Variables
@ -37,9 +39,11 @@ module Capistrano
# Removes any trace of the given variable. # Removes any trace of the given variable.
def unset(variable) def unset(variable)
sym = variable.to_sym sym = variable.to_sym
@variable_lock.synchronize do
@original_procs.delete(sym) @original_procs.delete(sym)
@variables.delete(sym) @variables.delete(sym)
end end
end
# Returns true if the variable has been defined, and false otherwise. # Returns true if the variable has been defined, and false otherwise.
def exists?(variable) def exists?(variable)
@ -51,6 +55,7 @@ module Capistrano
# true if the variable was actually reset. # true if the variable was actually reset.
def reset!(variable) def reset!(variable)
sym = variable.to_sym sym = variable.to_sym
@variable_lock.synchronize do
if @original_procs.key?(sym) if @original_procs.key?(sym)
@variables[sym] = @original_procs.delete(sym) @variables[sym] = @original_procs.delete(sym)
true true
@ -58,6 +63,7 @@ module Capistrano
false false
end end
end end
end
# Access a named variable. If the value of the variable responds_to? :call, # Access a named variable. If the value of the variable responds_to? :call,
# #call will be invoked (without parameters) and the return value cached # #call will be invoked (without parameters) and the return value cached
@ -74,12 +80,15 @@ module Capistrano
raise IndexError, "`#{variable}' not found" raise IndexError, "`#{variable}' not found"
end end
@variable_lock.synchronize do
if @variables[sym].respond_to?(:call) if @variables[sym].respond_to?(:call)
@original_procs[sym] = @variables[sym] @original_procs[sym] = @variables[sym]
@variables[sym] = @variables[sym].call @variables[sym] = @variables[sym].call
end end
@variables[sym] @variables[sym]
end end
end
def [](variable) def [](variable)
fetch(variable, nil) fetch(variable, nil)
@ -89,6 +98,7 @@ module Capistrano
initialize_without_variables(*args) initialize_without_variables(*args)
@variables = {} @variables = {}
@original_procs = {} @original_procs = {}
@variable_lock = Mutex.new
set :ssh_options, {} set :ssh_options, {}
set :logger, logger set :logger, logger