Skip to content

Commit

Permalink
Synchronize read and modification of @reserved_connections hash to av…
Browse files Browse the repository at this point in the history
…oid concurrency error.
  • Loading branch information
pmahoney committed May 19, 2012
1 parent 777d539 commit c2d416f
Showing 1 changed file with 8 additions and 4 deletions.
Expand Up @@ -139,14 +139,18 @@ def initialize(spec)
# #connection can be called any number of times; the connection is
# held in a hash keyed by the thread id.
def connection
@reserved_connections[current_connection_id] ||= checkout
synchronize do
@reserved_connections[current_connection_id] ||= checkout
end
end

# Is there an open connection that is being used for the current thread?
def active_connection?
@reserved_connections.fetch(current_connection_id) {
return false
}.in_use?
synchronize do
@reserved_connections.fetch(current_connection_id) {
return false
}.in_use?
end
end

# Signal that the thread is finished with the current connection.
Expand Down

0 comments on commit c2d416f

Please sign in to comment.