polyphony 0.34 → 0.36
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +1 -1
- data/TODO.md +7 -7
- data/docs/api-reference.md +1 -1
- data/docs/api-reference/fiber.md +18 -0
- data/docs/api-reference/gyro-async.md +57 -0
- data/docs/api-reference/gyro-child.md +29 -0
- data/docs/api-reference/gyro-queue.md +44 -0
- data/docs/api-reference/gyro-timer.md +51 -0
- data/docs/api-reference/gyro.md +25 -0
- data/docs/index.md +8 -6
- data/docs/main-concepts/fiber-scheduling.md +55 -72
- data/examples/core/xx-timer-gc.rb +17 -0
- data/ext/gyro/async.c +48 -58
- data/ext/gyro/child.c +48 -38
- data/ext/gyro/fiber.c +113 -0
- data/ext/gyro/gyro.c +12 -106
- data/ext/gyro/gyro.h +54 -50
- data/ext/gyro/gyro_ext.c +2 -0
- data/ext/gyro/io.c +70 -43
- data/ext/gyro/queue.c +5 -5
- data/ext/gyro/selector.c +33 -11
- data/ext/gyro/signal.c +44 -34
- data/ext/gyro/socket.c +6 -7
- data/ext/gyro/thread.c +1 -1
- data/ext/gyro/timer.c +42 -62
- data/lib/polyphony/adapters/irb.rb +1 -1
- data/lib/polyphony/core/thread_pool.rb +3 -3
- data/lib/polyphony/extensions/fiber.rb +1 -1
- data/lib/polyphony/extensions/thread.rb +2 -2
- data/lib/polyphony/version.rb +1 -1
- data/test/test_async.rb +2 -2
- data/test/test_fiber.rb +4 -4
- data/test/test_global_api.rb +1 -1
- data/test/test_thread_pool.rb +1 -1
- metadata +9 -2
@@ -22,7 +22,7 @@ class ThreadPool
|
|
22
22
|
def process(&block)
|
23
23
|
setup unless @task_queue
|
24
24
|
|
25
|
-
async =
|
25
|
+
async = Fiber.current.auto_async
|
26
26
|
@task_queue << [block, async]
|
27
27
|
async.await
|
28
28
|
end
|
@@ -45,8 +45,8 @@ class ThreadPool
|
|
45
45
|
def run_queued_task
|
46
46
|
(block, watcher) = @task_queue.pop
|
47
47
|
result = block.()
|
48
|
-
watcher&.signal
|
48
|
+
watcher&.signal(result)
|
49
49
|
rescue Exception => e
|
50
|
-
watcher ? watcher.signal
|
50
|
+
watcher ? watcher.signal(e) : raise(e)
|
51
51
|
end
|
52
52
|
end
|
@@ -48,12 +48,12 @@ class ::Thread
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def signal_waiters(result)
|
51
|
-
@join_wait_queue.shift_each { |w| w.signal
|
51
|
+
@join_wait_queue.shift_each { |w| w.signal(result) }
|
52
52
|
end
|
53
53
|
|
54
54
|
alias_method :orig_join, :join
|
55
55
|
def join(timeout = nil)
|
56
|
-
async =
|
56
|
+
async = Fiber.current.auto_async
|
57
57
|
@finalization_mutex.synchronize do
|
58
58
|
if @terminated
|
59
59
|
@result.is_a?(Exception) ? (raise @result) : (return @result)
|
data/lib/polyphony/version.rb
CHANGED
data/test/test_async.rb
CHANGED
@@ -13,7 +13,7 @@ class AsyncTest < MiniTest::Test
|
|
13
13
|
snooze
|
14
14
|
Thread.new do
|
15
15
|
orig_sleep 0.001
|
16
|
-
a.signal
|
16
|
+
a.signal
|
17
17
|
end
|
18
18
|
suspend
|
19
19
|
assert_equal 1, count
|
@@ -32,7 +32,7 @@ class AsyncTest < MiniTest::Test
|
|
32
32
|
snooze
|
33
33
|
Thread.new do
|
34
34
|
orig_sleep 0.001
|
35
|
-
3.times { a.signal
|
35
|
+
3.times { a.signal }
|
36
36
|
end
|
37
37
|
coproc.await
|
38
38
|
assert_equal 1, count
|
data/test/test_fiber.rb
CHANGED
@@ -113,7 +113,7 @@ class FiberTest < MiniTest::Test
|
|
113
113
|
async = Gyro::Async.new
|
114
114
|
worker = Thread.new do
|
115
115
|
worker_fiber = Fiber.current
|
116
|
-
async.signal
|
116
|
+
async.signal
|
117
117
|
suspend
|
118
118
|
buffer << :foo
|
119
119
|
end
|
@@ -132,7 +132,7 @@ class FiberTest < MiniTest::Test
|
|
132
132
|
t = Thread.new do
|
133
133
|
f = spin_loop { snooze }
|
134
134
|
sleep 0.001
|
135
|
-
async.signal
|
135
|
+
async.signal(:foo)
|
136
136
|
end
|
137
137
|
|
138
138
|
result = move_on_after(1) { async.await }
|
@@ -299,7 +299,7 @@ class FiberTest < MiniTest::Test
|
|
299
299
|
2.times { snooze }
|
300
300
|
result << 2
|
301
301
|
end
|
302
|
-
spin { f.cancel
|
302
|
+
spin { f.cancel }
|
303
303
|
assert_equal 0, result.size
|
304
304
|
begin
|
305
305
|
f.await
|
@@ -645,7 +645,7 @@ class FiberTest < MiniTest::Test
|
|
645
645
|
o.close
|
646
646
|
end
|
647
647
|
end
|
648
|
-
sleep 0.
|
648
|
+
sleep 0.2
|
649
649
|
f = spin { Gyro::Child.new(pid).await }
|
650
650
|
o.close
|
651
651
|
Process.kill('TERM', pid)
|
data/test/test_global_api.rb
CHANGED
data/test/test_thread_pool.rb
CHANGED
@@ -68,7 +68,7 @@ class ThreadPoolTest < MiniTest::Test
|
|
68
68
|
assert elapsed < 0.007
|
69
69
|
assert buffer.size < 2
|
70
70
|
|
71
|
-
sleep 0.
|
71
|
+
sleep 0.1 # allow time for threads to spawn
|
72
72
|
assert_equal @pool.size, threads.uniq.size
|
73
73
|
assert_equal (0..9).to_a, buffer.sort
|
74
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyphony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.36'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: modulation
|
@@ -264,6 +264,11 @@ files:
|
|
264
264
|
- docs/api-reference.md
|
265
265
|
- docs/api-reference/exception.md
|
266
266
|
- docs/api-reference/fiber.md
|
267
|
+
- docs/api-reference/gyro-async.md
|
268
|
+
- docs/api-reference/gyro-child.md
|
269
|
+
- docs/api-reference/gyro-queue.md
|
270
|
+
- docs/api-reference/gyro-timer.md
|
271
|
+
- docs/api-reference/gyro.md
|
267
272
|
- docs/api-reference/io.md
|
268
273
|
- docs/api-reference/object.md
|
269
274
|
- docs/api-reference/polyphony-baseexception.md
|
@@ -339,6 +344,7 @@ files:
|
|
339
344
|
- examples/core/xx-thread_pool.rb
|
340
345
|
- examples/core/xx-throttling.rb
|
341
346
|
- examples/core/xx-timeout.rb
|
347
|
+
- examples/core/xx-timer-gc.rb
|
342
348
|
- examples/core/xx-trace.rb
|
343
349
|
- examples/core/xx-using-a-mutex.rb
|
344
350
|
- examples/core/xx-worker-thread.rb
|
@@ -372,6 +378,7 @@ files:
|
|
372
378
|
- ext/gyro/async.c
|
373
379
|
- ext/gyro/child.c
|
374
380
|
- ext/gyro/extconf.rb
|
381
|
+
- ext/gyro/fiber.c
|
375
382
|
- ext/gyro/gyro.c
|
376
383
|
- ext/gyro/gyro.h
|
377
384
|
- ext/gyro/gyro_ext.c
|