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,8 +39,10 @@ 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
@original_procs.delete(sym) @variable_lock.synchronize do
@variables.delete(sym) @original_procs.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.
@ -51,11 +55,13 @@ 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
if @original_procs.key?(sym) @variable_lock.synchronize do
@variables[sym] = @original_procs.delete(sym) if @original_procs.key?(sym)
true @variables[sym] = @original_procs.delete(sym)
else true
false else
false
end
end end
end end
@ -73,12 +79,15 @@ module Capistrano
return yield(variable) if block_given? return yield(variable) if block_given?
raise IndexError, "`#{variable}' not found" raise IndexError, "`#{variable}' not found"
end end
if @variables[sym].respond_to?(:call) @variable_lock.synchronize do
@original_procs[sym] = @variables[sym] if @variables[sym].respond_to?(:call)
@variables[sym] = @variables[sym].call @original_procs[sym] = @variables[sym]
@variables[sym] = @variables[sym].call
end
@variables[sym]
end end
@variables[sym]
end end
def [](variable) def [](variable)
@ -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