pools 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pools/connection_pool.rb +16 -10
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d912c05a123c98e6d766cdf24ad2e11c3bf71e5c
4
- data.tar.gz: 1e9b4cf802a477fc9dceadc1bb6de4606db68d97
3
+ metadata.gz: 70a334b882b61ca1b32aec8d628d2374caf93c45
4
+ data.tar.gz: b857dfbedbeaea85e88eae1199a4a5c586c4bc5f
5
5
  SHA512:
6
- metadata.gz: 7934474abed31f23d125e08745199736af73f7433e4e10cba7b5ca921783278728795e7fa30f0223b204ed9551e018840d48093326bc077452a84e367175f79d
7
- data.tar.gz: 91caa2af12554950c1b24de820ecd3e7b1a4d62ece249f9439fde44e24c94a291f47c177235e0917445d9b02cddb6ee81da454c34676f582a7c67465b72d228a
6
+ metadata.gz: 1a71428a4b1e7a76d35b02ddd1d4ed951776e6a7d8cc32e92dbe8d6b7d918aff3f543a8358cdc247b78104ebe5be967bbbdc39ad1217b3784b52d612c118b8c9
7
+ data.tar.gz: f0a6155dae531c56a789dc36d2719018bf608dc76218d6d4470874c983b43ca81295979608ff6c557095e9383638c4828fd487706fb592d4ff1c00abc4740ffb
@@ -95,15 +95,19 @@ module Pools
95
95
  # #connection can be called any number of times; the connection is
96
96
  # held in a hash keyed by the thread id.
97
97
  def connection
98
- @reserved_connections[current_connection_id] ||= checkout
98
+ @reserved_connections[current_connection_id] || synchronize do
99
+ @reserved_connections[current_connection_id] ||= checkout
100
+ end
99
101
  end
100
102
 
101
103
  # Signal that the thread is finished with the current connection.
102
104
  # #release_connection releases the connection-thread association
103
105
  # and returns the connection to the pool.
104
106
  def release_connection(with_id = current_connection_id)
105
- conn = @reserved_connections.delete(with_id)
106
- checkin conn if conn
107
+ synchronize do
108
+ conn = @reserved_connections.delete(with_id)
109
+ checkin conn if conn
110
+ end
107
111
  end
108
112
 
109
113
  # If a connection already exists yield it to the block. If no connection
@@ -111,7 +115,7 @@ module Pools
111
115
  # connection when finished.
112
116
  def with_connection
113
117
  connection_id = current_connection_id
114
- fresh_connection = true unless @reserved_connections[connection_id]
118
+ fresh_connection = synchronize { !@reserved_connections[connection_id] }
115
119
  yield connection
116
120
  ensure
117
121
  release_connection(connection_id) if fresh_connection
@@ -148,12 +152,14 @@ module Pools
148
152
  # Return any checked-out connections back to the pool by threads that
149
153
  # are no longer alive.
150
154
  def clear_stale_cached_connections!
151
- keys = @reserved_connections.keys - Thread.list.find_all { |t|
152
- t.alive?
153
- }.map { |thread| thread.object_id }
154
- keys.each do |key|
155
- checkin @reserved_connections[key]
156
- @reserved_connections.delete(key)
155
+ synchronize do
156
+ keys = @reserved_connections.keys - Thread.list.find_all { |t|
157
+ t.alive?
158
+ }.map { |thread| thread.object_id }
159
+ keys.each do |key|
160
+ checkin @reserved_connections[key]
161
+ @reserved_connections.delete(key)
162
+ end
157
163
  end
158
164
  end
159
165
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Rykov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-13 00:00:00.000000000 Z
11
+ date: 2015-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport