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:
parent
71de275182
commit
d0b8e8b25d
2 changed files with 24 additions and 12 deletions
|
@ -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]
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'thread'
|
||||
|
||||
module Capistrano
|
||||
class Configuration
|
||||
module Variables
|
||||
|
@ -37,8 +39,10 @@ module Capistrano
|
|||
# Removes any trace of the given variable.
|
||||
def unset(variable)
|
||||
sym = variable.to_sym
|
||||
@original_procs.delete(sym)
|
||||
@variables.delete(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.
|
||||
|
@ -51,11 +55,13 @@ module Capistrano
|
|||
# true if the variable was actually reset.
|
||||
def reset!(variable)
|
||||
sym = variable.to_sym
|
||||
if @original_procs.key?(sym)
|
||||
@variables[sym] = @original_procs.delete(sym)
|
||||
true
|
||||
else
|
||||
false
|
||||
@variable_lock.synchronize do
|
||||
if @original_procs.key?(sym)
|
||||
@variables[sym] = @original_procs.delete(sym)
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -74,11 +80,14 @@ module Capistrano
|
|||
raise IndexError, "`#{variable}' not found"
|
||||
end
|
||||
|
||||
if @variables[sym].respond_to?(:call)
|
||||
@original_procs[sym] = @variables[sym]
|
||||
@variables[sym] = @variables[sym].call
|
||||
@variable_lock.synchronize do
|
||||
if @variables[sym].respond_to?(:call)
|
||||
@original_procs[sym] = @variables[sym]
|
||||
@variables[sym] = @variables[sym].call
|
||||
end
|
||||
|
||||
@variables[sym]
|
||||
end
|
||||
@variables[sym]
|
||||
end
|
||||
|
||||
def [](variable)
|
||||
|
@ -89,6 +98,7 @@ module Capistrano
|
|||
initialize_without_variables(*args)
|
||||
@variables = {}
|
||||
@original_procs = {}
|
||||
@variable_lock = Mutex.new
|
||||
|
||||
set :ssh_options, {}
|
||||
set :logger, logger
|
||||
|
|
Loading…
Reference in a new issue