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*
* Make variable accesses thread safe [via Adrian Danieli]
* 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]

View file

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