aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
diff options
context:
space:
mode:
authorNick <nick@nicksieger.com>2008-04-19 14:42:56 -0500
committerNick Sieger <nick@nicksieger.com>2008-08-29 14:12:09 -0500
commitcab76ce6ac2983f59451e2d53b23746a2873aea0 (patch)
tree9aeb8c88ac13d353660d147fb82e6b865700f45a /activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
parent50cd4bdc99ebaf3ac879e4e7fea43c5b55ca5f68 (diff)
downloadrails-cab76ce6ac2983f59451e2d53b23746a2873aea0.tar.gz
rails-cab76ce6ac2983f59451e2d53b23746a2873aea0.tar.bz2
rails-cab76ce6ac2983f59451e2d53b23746a2873aea0.zip
Add synchronization to connection pool also
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index 8f241a39ca..2d13d02fad 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -12,6 +12,9 @@ module ActiveRecord
# The ConnectionSpecification for this pool
@spec = spec
+
+ # The mutex used to synchronize pool access
+ @connection_mutex = Monitor.new
end
def active_connection_name #:nodoc:
@@ -70,7 +73,7 @@ module ActiveRecord
# Verify the connection.
conn.verify!(verification_timeout)
else
- self.connection = spec
+ self.set_connection spec
conn = active_connections[name]
end
@@ -82,6 +85,7 @@ module ActiveRecord
active_connections[active_connection_name] ? true : false
end
+ # Disconnect all connections in the pool.
def disconnect!
clear_cache!(@active_connections) do |name, conn|
conn.disconnect!
@@ -89,16 +93,20 @@ module ActiveRecord
end
# Set the connection for the class.
- def connection=(spec) #:nodoc:
+ def set_connection(spec) #:nodoc:
if spec.kind_of?(ActiveRecord::ConnectionAdapters::AbstractAdapter)
active_connections[active_connection_name] = spec
elsif spec.kind_of?(ActiveRecord::Base::ConnectionSpecification)
- self.connection = ActiveRecord::Base.send(spec.adapter_method, spec.config)
+ self.set_connection ActiveRecord::Base.send(spec.adapter_method, spec.config)
else
raise ConnectionNotEstablished
end
end
+ synchronize :active_connection, :connection, :clear_active_connections!,
+ :clear_reloadable_connections!, :verify_active_connections!, :retrieve_connection,
+ :connected?, :disconnect!, :set_connection, :with => :@connection_mutex
+
private
def clear_cache!(cache, &block)
cache.each(&block) if block_given?