Use one mutex per thread on pooled connections (cremes)
This commit is contained in:
parent
f9cd266214
commit
a14d02e98d
|
@ -97,7 +97,11 @@ module Mongo
|
||||||
|
|
||||||
# Mutex for synchronizing pool access
|
# Mutex for synchronizing pool access
|
||||||
@connection_mutex = Mutex.new
|
@connection_mutex = Mutex.new
|
||||||
@safe_mutex = Mutex.new
|
|
||||||
|
|
||||||
|
# Create a mutex when a new key, in this case a socket,
|
||||||
|
# is added to the hash.
|
||||||
|
@safe_mutexes = Hash.new { |h, k| h[k] = Mutex.new }
|
||||||
|
|
||||||
# Condition variable for signal and wait
|
# Condition variable for signal and wait
|
||||||
@queue = ConditionVariable.new
|
@queue = ConditionVariable.new
|
||||||
|
@ -368,7 +372,7 @@ module Mongo
|
||||||
sock = checkout
|
sock = checkout
|
||||||
packed_message = message_with_headers.append!(message_with_check).to_s
|
packed_message = message_with_headers.append!(message_with_check).to_s
|
||||||
docs = num_received = cursor_id = ''
|
docs = num_received = cursor_id = ''
|
||||||
@safe_mutex.synchronize do
|
@safe_mutexes[sock].synchronize do
|
||||||
send_message_on_socket(packed_message, sock)
|
send_message_on_socket(packed_message, sock)
|
||||||
docs, num_received, cursor_id = receive(sock)
|
docs, num_received, cursor_id = receive(sock)
|
||||||
end
|
end
|
||||||
|
@ -398,7 +402,7 @@ module Mongo
|
||||||
sock = socket || checkout
|
sock = socket || checkout
|
||||||
|
|
||||||
result = ''
|
result = ''
|
||||||
@safe_mutex.synchronize do
|
@safe_mutexes[sock].synchronize do
|
||||||
send_message_on_socket(packed_message, sock)
|
send_message_on_socket(packed_message, sock)
|
||||||
result = receive(sock)
|
result = receive(sock)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue