threadpool 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/threadpool.rb +23 -30
- data/threadpool.gemspec +1 -1
- metadata +2 -2
data/lib/threadpool.rb
CHANGED
@@ -162,13 +162,17 @@ class ThreadPool
|
|
162
162
|
trim true
|
163
163
|
end
|
164
164
|
|
165
|
-
def shutdown
|
165
|
+
def shutdown!
|
166
166
|
@mutex.synchronize {
|
167
167
|
@shutdown = true
|
168
168
|
@cond.broadcast
|
169
169
|
}
|
170
170
|
|
171
171
|
wake_up_timeout
|
172
|
+
end
|
173
|
+
|
174
|
+
def shutdown
|
175
|
+
shutdown!
|
172
176
|
|
173
177
|
join
|
174
178
|
end
|
@@ -215,42 +219,32 @@ private
|
|
215
219
|
|
216
220
|
thread = Thread.new {
|
217
221
|
loop do
|
218
|
-
task
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
if @trim_requests > 0
|
224
|
-
@trim_requests -= 1
|
225
|
-
continue = false
|
226
|
-
|
227
|
-
break
|
228
|
-
end
|
222
|
+
task = @mutex.synchronize {
|
223
|
+
if @todo.empty?
|
224
|
+
while @todo.empty?
|
225
|
+
if @trim_requests > 0
|
226
|
+
@trim_requests -= 1
|
229
227
|
|
230
|
-
|
231
|
-
|
228
|
+
break
|
229
|
+
end
|
232
230
|
|
233
|
-
break
|
234
|
-
end
|
231
|
+
break if shutdown?
|
235
232
|
|
236
|
-
|
237
|
-
|
238
|
-
|
233
|
+
@waiting += 1
|
234
|
+
@cond.wait @mutex
|
235
|
+
@waiting -= 1
|
239
236
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
break
|
244
|
-
end
|
237
|
+
break !shutdown?
|
238
|
+
end or break
|
245
239
|
end
|
246
240
|
|
247
|
-
|
248
|
-
}
|
249
|
-
|
250
|
-
break if !continue || shutdown?
|
241
|
+
@todo.shift
|
242
|
+
} or break
|
251
243
|
|
252
244
|
task.execute(thread)
|
253
245
|
|
246
|
+
break if shutdown?
|
247
|
+
|
254
248
|
trim if auto_trim? && @spawned > @min
|
255
249
|
end
|
256
250
|
|
@@ -266,8 +260,7 @@ private
|
|
266
260
|
end
|
267
261
|
|
268
262
|
def spawn_timeout_thread
|
269
|
-
@pipes
|
270
|
-
|
263
|
+
@pipes = IO.pipe
|
271
264
|
@timeout = Thread.new {
|
272
265
|
loop do
|
273
266
|
now = Time.now
|
data/threadpool.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: threadpool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-23 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: meh@paranoici.org
|