提交 23fad29c 编写于 作者: A Aaron Patterson

Merge pull request #6398 from pmahoney/threadsafe-connection-pool

Synchronize read and modification of @reserved_connections 
...@@ -139,14 +139,18 @@ def initialize(spec) ...@@ -139,14 +139,18 @@ def initialize(spec)
# #connection can be called any number of times; the connection is # #connection can be called any number of times; the connection is
# held in a hash keyed by the thread id. # held in a hash keyed by the thread id.
def connection def connection
@reserved_connections[current_connection_id] ||= checkout synchronize do
@reserved_connections[current_connection_id] ||= checkout
end
end end
# Is there an open connection that is being used for the current thread? # Is there an open connection that is being used for the current thread?
def active_connection? def active_connection?
@reserved_connections.fetch(current_connection_id) { synchronize do
return false @reserved_connections.fetch(current_connection_id) {
}.in_use? return false
}.in_use?
end
end end
# Signal that the thread is finished with the current connection. # Signal that the thread is finished with the current connection.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册