rbgo 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rbgo/select_chan.rb +61 -24
- data/lib/rbgo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce5380534583083998d908ac2ecb726a941bdc1e697cc8b1a6e6e10477e1bec6
|
4
|
+
data.tar.gz: 5eb7fd7557bef0a324a3a9b099e0c53bb2f71110107421d9b017bb42c99c9738
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 194e1bbd2eee668bf3221db0c2b7dc888dbdf54b1ef2274c06ec51b031250e8858a134d37cf9b9c81c31c8d054723f6ffa3483409c5e642778e6391b7fdd823e
|
7
|
+
data.tar.gz: 7ba0c5eace41ad7d673d536dd6c80e0af03fcc53cdca945a2d2041f699bbcf13dc4ea075770e1302184566b8af80e51dab2fbf3a44f577918aef01db7f6f27a6
|
data/lib/rbgo/select_chan.rb
CHANGED
@@ -14,12 +14,22 @@ module Rbgo
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
attr_accessor :
|
17
|
+
attr_accessor :ios
|
18
|
+
attr_accessor :register_mutex
|
19
|
+
|
20
|
+
def register(io)
|
21
|
+
register_mutex.synchronize do
|
22
|
+
ios << io
|
23
|
+
end
|
24
|
+
end
|
18
25
|
|
19
26
|
def notify
|
20
|
-
|
21
|
-
|
22
|
-
|
27
|
+
register_mutex.synchronize do
|
28
|
+
ios.each do |io|
|
29
|
+
io.close rescue nil
|
30
|
+
end
|
31
|
+
ios.clear
|
32
|
+
end
|
23
33
|
nil
|
24
34
|
end
|
25
35
|
end
|
@@ -43,7 +53,8 @@ module Rbgo
|
|
43
53
|
self.have_enq_waiting_flag = false
|
44
54
|
self.have_deq_waiting_flag = false
|
45
55
|
|
46
|
-
self.
|
56
|
+
self.ios = []
|
57
|
+
self.register_mutex = Mutex.new
|
47
58
|
end
|
48
59
|
|
49
60
|
def push(obj, nonblock = false)
|
@@ -189,8 +200,10 @@ module Rbgo
|
|
189
200
|
|
190
201
|
def initialize(max)
|
191
202
|
super(max)
|
192
|
-
|
193
|
-
|
203
|
+
@mutex = Mutex.new
|
204
|
+
|
205
|
+
self.ios = []
|
206
|
+
self.register_mutex = Mutex.new
|
194
207
|
end
|
195
208
|
|
196
209
|
def push(obj, nonblock = false)
|
@@ -250,24 +263,49 @@ module Rbgo
|
|
250
263
|
def select_chan(*ops)
|
251
264
|
ops.shuffle!
|
252
265
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
266
|
+
io_hash = {}
|
267
|
+
close_io_blk = proc do
|
268
|
+
io_hash.each_pair.flat_map do |k, v|
|
269
|
+
[k, v[1]]
|
270
|
+
end.each do |io|
|
271
|
+
io.close rescue nil
|
257
272
|
end
|
273
|
+
end
|
258
274
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
275
|
+
begin
|
276
|
+
while true do
|
277
|
+
|
278
|
+
close_io_blk.call
|
279
|
+
io_hash.clear
|
280
|
+
|
281
|
+
ops.each do |op|
|
282
|
+
io_r, io_w = IO.pipe
|
283
|
+
op.register(io_w)
|
284
|
+
io_hash[io_r] = [op, io_w]
|
263
285
|
end
|
264
|
-
end
|
265
286
|
|
266
|
-
|
287
|
+
ops.each do |op|
|
288
|
+
begin
|
289
|
+
return op.call
|
290
|
+
rescue ThreadError
|
291
|
+
end
|
292
|
+
end
|
267
293
|
|
268
|
-
|
269
|
-
|
294
|
+
return yield if block_given?
|
295
|
+
|
296
|
+
read_ios = IO.select(io_hash.keys).first rescue []
|
270
297
|
|
298
|
+
read_ios.each do |io_r|
|
299
|
+
op = io_hash[io_r].first
|
300
|
+
begin
|
301
|
+
return op.call
|
302
|
+
rescue ThreadError
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
306
|
+
ensure
|
307
|
+
close_io_blk.call
|
308
|
+
end
|
271
309
|
end
|
272
310
|
|
273
311
|
# on_read
|
@@ -285,8 +323,8 @@ module Rbgo
|
|
285
323
|
blk.call(res, ok)
|
286
324
|
end
|
287
325
|
end
|
288
|
-
op.define_singleton_method(:
|
289
|
-
chan.send :
|
326
|
+
op.define_singleton_method(:register) do |io_w|
|
327
|
+
chan.send :register, io_w
|
290
328
|
end
|
291
329
|
op
|
292
330
|
end
|
@@ -304,9 +342,8 @@ module Rbgo
|
|
304
342
|
res = blk.call unless blk.nil?
|
305
343
|
res
|
306
344
|
end
|
307
|
-
|
308
|
-
|
309
|
-
chan.send :io_r
|
345
|
+
op.define_singleton_method(:register) do |io_w|
|
346
|
+
chan.send :register, io_w
|
310
347
|
end
|
311
348
|
op
|
312
349
|
end
|
data/lib/rbgo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbgo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wang Yin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: system
|