0
@@ -9,6 +9,15 @@ module ActiveRecord
0
+ cattr_accessor :connection_pools_lock, :instance_writer => false
0
+ @@connection_pools_lock = NullMonitor.new
0
# Check for activity after at least +verification_timeout+ seconds.
0
# Defaults to 0 (always check.)
0
cattr_accessor :verification_timeout, :instance_writer => false
0
@@ -18,8 +27,18 @@ module ActiveRecord
0
@@connection_pools = {}
0
+ def allow_concurrency=(flag)
0
+ if @@allow_concurrency != flag
0
+ self.connection_pools_lock = Monitor.new
0
+ self.connection_pools_lock = NullMonitor.new
0
# for internal use only
0
- def active_connections
0
+ def active_connections
#:nodoc:0
@@connection_pools.inject({}) do |hash,kv|
0
hash[kv.first] = kv.last.active_connection
0
hash.delete(kv.first) unless hash[kv.first]
0
@@ -36,22 +55,16 @@ module ActiveRecord
0
# Clears the cache which maps classes to connections.
0
def clear_active_connections!
0
- clear_cache!(@@connection_pools) do |name, pool|
0
- pool.clear_active_connections!
0
+ @@connection_pools.each_value {|pool| pool.clear_active_connections! }
0
- # Clears the cache which maps classes
0
+ # Clears the cache which maps classes
0
def clear_reloadable_connections!
0
- clear_cache!(@@connection_pools) do |name, pool|
0
- pool.clear_reloadable_connections!
0
+ @@connection_pools.each_value {|pool| pool.clear_reloadable_connections! }
0
def clear_all_connections!
0
- clear_cache!(@@connection_pools) do |name, pool|
0
+ clear_cache!(@@connection_pools) {|name, pool| pool.disconnect! }
0
# Verify active connections.
0
@@ -59,6 +72,9 @@ module ActiveRecord
0
@@connection_pools.each_value {|pool| pool.verify_active_connections!}
0
+ synchronize :active_connections, :clear_active_connections!, :clear_reloadable_connections!,
0
+ :clear_all_connections!, :verify_active_connections!, :with => :connection_pools_lock
0
def clear_cache!(cache, &block)
0
cache.each(&block) if block_given?
0
@@ -107,7 +123,9 @@ module ActiveRecord
0
raise AdapterNotSpecified unless defined? RAILS_ENV
0
establish_connection(RAILS_ENV)
0
when ConnectionSpecification
0
- @@connection_pools[name] = ConnectionAdapters::ConnectionPool.new(spec)
0
+ connection_pools_lock.synchronize do
0
+ @@connection_pools[name] = ConnectionAdapters::ConnectionPool.new(spec)
0
if configuration = configurations[spec.to_s]
0
establish_connection(configuration)
0
@@ -171,5 +189,10 @@ module ActiveRecord
0
pool.disconnect! if pool
0
pool.spec.config if pool
0
+ synchronize :retrieve_connection, :retrieve_connection_pool, :connected?,
0
+ :remove_connection, :with => :connection_pools_lock