public
Description: Remote multi-server automation tool
Homepage: http://www.capify.org
Clone URL: git://github.com/jamis/capistrano.git
use a mutex per-variable, rather than for all variables, to avoid a 
deadlock when a gateway needs to be established


git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@7141 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
jamis (author)
Wed Jun 27 07:59:07 -0700 2007
commit  783f32717a030f08e9eed79673c24bc59b301964
tree    a3241da97900f211bc66e0a56e2bf46dc7b2fd03
parent  1f345a6fe8e5b94239f688b1d1399935084a61d1
...
1
 
2
3
4
...
31
32
33
34
 
 
35
36
37
...
39
40
41
42
 
43
44
45
...
55
56
57
58
 
59
60
61
...
74
75
76
77
78
79
80
81
 
 
 
 
 
 
82
83
84
85
86
87
88
89
90
 
 
91
92
93
...
98
99
100
101
 
102
103
104
...
 
1
2
3
4
...
31
32
33
 
34
35
36
37
38
...
40
41
42
 
43
44
45
46
...
56
57
58
 
59
60
61
62
...
75
76
77
 
 
 
 
 
78
79
80
81
82
83
84
 
85
86
87
88
 
 
89
90
91
92
93
94
...
99
100
101
 
102
103
104
105
0
@@ -1,4 +1,4 @@
0
-require 'monitor'
0
+require 'thread'
0
 
0
 module Capistrano
0
   class Configuration
0
@@ -31,7 +31,8 @@ module Capistrano
0
         end
0
 
0
         value = args.empty? ? block : args.first
0
- @variables[variable.to_sym] = value
0
+ sym = variable.to_sym
0
+ @variable_locks[sym].synchronize { @variables[sym] = value }
0
       end
0
 
0
       alias :[]= :set
0
@@ -39,7 +40,7 @@ module Capistrano
0
       # Removes any trace of the given variable.
0
       def unset(variable)
0
         sym = variable.to_sym
0
- @variable_lock.synchronize do
0
+ @variable_locks[sym].synchronize do
0
           @original_procs.delete(sym)
0
           @variables.delete(sym)
0
         end
0
@@ -55,7 +56,7 @@ module Capistrano
0
       # true if the variable was actually reset.
0
       def reset!(variable)
0
         sym = variable.to_sym
0
- @variable_lock.synchronize do
0
+ @variable_locks[sym].synchronize do
0
           if @original_procs.key?(sym)
0
             @variables[sym] = @original_procs.delete(sym)
0
             true
0
@@ -74,20 +75,20 @@ module Capistrano
0
         end
0
 
0
         sym = variable.to_sym
0
- if !@variables.key?(sym)
0
- return args.first unless args.empty?
0
- return yield(variable) if block_given?
0
- raise IndexError, "`#{variable}' not found"
0
- end
0
+ @variable_locks[sym].synchronize do
0
+ if !@variables.key?(sym)
0
+ return args.first unless args.empty?
0
+ return yield(variable) if block_given?
0
+ raise IndexError, "`#{variable}' not found"
0
+ end
0
 
0
- @variable_lock.synchronize do
0
           if @variables[sym].respond_to?(:call)
0
             @original_procs[sym] = @variables[sym]
0
             @variables[sym] = @variables[sym].call
0
           end
0
-
0
- @variables[sym]
0
         end
0
+
0
+ @variables[sym]
0
       end
0
 
0
       def [](variable)
0
@@ -98,7 +99,7 @@ module Capistrano
0
         initialize_without_variables(*args)
0
         @variables = {}
0
         @original_procs = {}
0
- @variable_lock = Monitor.new
0
+ @variable_locks = Hash.new { |h,k| h[k] = Mutex.new }
0
 
0
         set :ssh_options, {}
0
         set :logger, logger

Comments

    No one has commented yet.