polyphony 0.40 → 0.41
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +11 -2
- data/.gitignore +2 -2
- data/.rubocop.yml +30 -0
- data/CHANGELOG.md +6 -2
- data/Gemfile.lock +9 -6
- data/Rakefile +2 -2
- data/TODO.md +18 -97
- data/docs/_includes/head.html +40 -0
- data/docs/_includes/nav.html +5 -5
- data/docs/api-reference/fiber.md +2 -2
- data/docs/main-concepts/design-principles.md +67 -9
- data/docs/main-concepts/extending.md +1 -1
- data/examples/core/xx-agent.rb +102 -0
- data/examples/core/xx-sleeping.rb +14 -6
- data/examples/io/xx-irb.rb +1 -1
- data/examples/performance/thread-vs-fiber/polyphony_mt_server.rb +7 -6
- data/examples/performance/thread-vs-fiber/polyphony_server.rb +14 -25
- data/ext/{gyro → polyphony}/extconf.rb +2 -2
- data/ext/{gyro → polyphony}/fiber.c +15 -19
- data/ext/{gyro → polyphony}/libev.c +0 -0
- data/ext/{gyro → polyphony}/libev.h +0 -0
- data/ext/polyphony/libev_agent.c +503 -0
- data/ext/polyphony/libev_queue.c +214 -0
- data/ext/{gyro/gyro.c → polyphony/polyphony.c} +16 -25
- data/ext/polyphony/polyphony.h +90 -0
- data/ext/polyphony/polyphony_ext.c +23 -0
- data/ext/{gyro → polyphony}/socket.c +14 -14
- data/ext/{gyro → polyphony}/thread.c +32 -115
- data/ext/{gyro → polyphony}/tracing.c +1 -1
- data/lib/polyphony.rb +16 -12
- data/lib/polyphony/adapters/irb.rb +1 -1
- data/lib/polyphony/adapters/postgres.rb +6 -5
- data/lib/polyphony/adapters/process.rb +5 -5
- data/lib/polyphony/adapters/trace.rb +28 -28
- data/lib/polyphony/core/channel.rb +3 -3
- data/lib/polyphony/core/exceptions.rb +1 -1
- data/lib/polyphony/core/global_api.rb +11 -9
- data/lib/polyphony/core/resource_pool.rb +3 -3
- data/lib/polyphony/core/sync.rb +2 -2
- data/lib/polyphony/core/thread_pool.rb +6 -6
- data/lib/polyphony/core/throttler.rb +13 -6
- data/lib/polyphony/event.rb +27 -0
- data/lib/polyphony/extensions/core.rb +20 -11
- data/lib/polyphony/extensions/fiber.rb +4 -4
- data/lib/polyphony/extensions/io.rb +56 -26
- data/lib/polyphony/extensions/openssl.rb +4 -8
- data/lib/polyphony/extensions/socket.rb +27 -9
- data/lib/polyphony/extensions/thread.rb +16 -9
- data/lib/polyphony/net.rb +9 -9
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +2 -2
- data/test/helper.rb +12 -1
- data/test/test_agent.rb +77 -0
- data/test/{test_async.rb → test_event.rb} +13 -7
- data/test/test_ext.rb +25 -4
- data/test/test_fiber.rb +19 -10
- data/test/test_global_api.rb +4 -4
- data/test/test_io.rb +46 -24
- data/test/test_queue.rb +74 -0
- data/test/test_signal.rb +3 -40
- data/test/test_socket.rb +33 -0
- data/test/test_thread.rb +37 -16
- data/test/test_trace.rb +6 -5
- metadata +24 -24
- data/ext/gyro/async.c +0 -132
- data/ext/gyro/child.c +0 -108
- data/ext/gyro/gyro.h +0 -158
- data/ext/gyro/gyro_ext.c +0 -33
- data/ext/gyro/io.c +0 -457
- data/ext/gyro/queue.c +0 -146
- data/ext/gyro/selector.c +0 -205
- data/ext/gyro/signal.c +0 -99
- data/ext/gyro/timer.c +0 -115
- data/test/test_timer.rb +0 -56
data/test/test_trace.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'helper'
|
4
|
+
require 'polyphony/adapters/trace'
|
4
5
|
|
5
6
|
class TraceTest < MiniTest::Test
|
6
7
|
def test_tracing_disabled
|
@@ -11,13 +12,13 @@ class TraceTest < MiniTest::Test
|
|
11
12
|
assert_equal 0, records.size
|
12
13
|
ensure
|
13
14
|
t&.disable
|
14
|
-
|
15
|
+
Polyphony.trace(nil)
|
15
16
|
end
|
16
17
|
|
17
18
|
def test_tracing_enabled
|
18
19
|
records = []
|
19
20
|
t = Polyphony::Trace.new(:fiber_all) { |r| records << r if r[:event] =~ /^fiber_/ }
|
20
|
-
|
21
|
+
Polyphony.trace(true)
|
21
22
|
t.enable
|
22
23
|
snooze
|
23
24
|
t.disable
|
@@ -28,14 +29,14 @@ class TraceTest < MiniTest::Test
|
|
28
29
|
assert_equal [Fiber.current], records.map { |r| r[:fiber] }.uniq
|
29
30
|
ensure
|
30
31
|
t&.disable
|
31
|
-
|
32
|
+
Polyphony.trace(nil)
|
32
33
|
end
|
33
34
|
|
34
35
|
def test_2_fiber_trace
|
35
36
|
records = []
|
36
37
|
t = Polyphony::Trace.new(:fiber_all) { |r| records << r if r[:event] =~ /^fiber_/ }
|
37
38
|
t.enable
|
38
|
-
|
39
|
+
Polyphony.trace(true)
|
39
40
|
|
40
41
|
f = spin { sleep 0 }
|
41
42
|
suspend
|
@@ -61,6 +62,6 @@ class TraceTest < MiniTest::Test
|
|
61
62
|
], events
|
62
63
|
ensure
|
63
64
|
t&.disable
|
64
|
-
|
65
|
+
Polyphony.trace(nil)
|
65
66
|
end
|
66
67
|
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.41'
|
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-
|
11
|
+
date: 2020-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - '='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: 0.85.1
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: 0.85.1
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: pg
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -224,7 +224,7 @@ description:
|
|
224
224
|
email: ciconia@gmail.com
|
225
225
|
executables: []
|
226
226
|
extensions:
|
227
|
-
- ext/
|
227
|
+
- ext/polyphony/extconf.rb
|
228
228
|
extra_rdoc_files:
|
229
229
|
- README.md
|
230
230
|
files:
|
@@ -242,6 +242,7 @@ files:
|
|
242
242
|
- TODO.md
|
243
243
|
- bin/polyphony-debug
|
244
244
|
- docs/_config.yml
|
245
|
+
- docs/_includes/head.html
|
245
246
|
- docs/_includes/nav.html
|
246
247
|
- docs/_includes/prevnext.html
|
247
248
|
- docs/_layouts/default.html
|
@@ -297,6 +298,7 @@ files:
|
|
297
298
|
- examples/core/02-awaiting-fibers.rb
|
298
299
|
- examples/core/03-interrupting.rb
|
299
300
|
- examples/core/forever_sleep.rb
|
301
|
+
- examples/core/xx-agent.rb
|
300
302
|
- examples/core/xx-at_exit.rb
|
301
303
|
- examples/core/xx-caller.rb
|
302
304
|
- examples/core/xx-channels.rb
|
@@ -363,23 +365,6 @@ files:
|
|
363
365
|
- examples/performance/thread-vs-fiber/xx-httparty_multi.rb
|
364
366
|
- examples/performance/thread-vs-fiber/xx-httparty_threaded.rb
|
365
367
|
- examples/performance/thread_pool_perf.rb
|
366
|
-
- ext/gyro/async.c
|
367
|
-
- ext/gyro/child.c
|
368
|
-
- ext/gyro/extconf.rb
|
369
|
-
- ext/gyro/fiber.c
|
370
|
-
- ext/gyro/gyro.c
|
371
|
-
- ext/gyro/gyro.h
|
372
|
-
- ext/gyro/gyro_ext.c
|
373
|
-
- ext/gyro/io.c
|
374
|
-
- ext/gyro/libev.c
|
375
|
-
- ext/gyro/libev.h
|
376
|
-
- ext/gyro/queue.c
|
377
|
-
- ext/gyro/selector.c
|
378
|
-
- ext/gyro/signal.c
|
379
|
-
- ext/gyro/socket.c
|
380
|
-
- ext/gyro/thread.c
|
381
|
-
- ext/gyro/timer.c
|
382
|
-
- ext/gyro/tracing.c
|
383
368
|
- ext/libev/Changes
|
384
369
|
- ext/libev/LICENSE
|
385
370
|
- ext/libev/README
|
@@ -396,6 +381,18 @@ files:
|
|
396
381
|
- ext/libev/ev_win32.c
|
397
382
|
- ext/libev/ev_wrap.h
|
398
383
|
- ext/libev/test_libev_win32.c
|
384
|
+
- ext/polyphony/extconf.rb
|
385
|
+
- ext/polyphony/fiber.c
|
386
|
+
- ext/polyphony/libev.c
|
387
|
+
- ext/polyphony/libev.h
|
388
|
+
- ext/polyphony/libev_agent.c
|
389
|
+
- ext/polyphony/libev_queue.c
|
390
|
+
- ext/polyphony/polyphony.c
|
391
|
+
- ext/polyphony/polyphony.h
|
392
|
+
- ext/polyphony/polyphony_ext.c
|
393
|
+
- ext/polyphony/socket.c
|
394
|
+
- ext/polyphony/thread.c
|
395
|
+
- ext/polyphony/tracing.c
|
399
396
|
- lib/polyphony.rb
|
400
397
|
- lib/polyphony/adapters/fs.rb
|
401
398
|
- lib/polyphony/adapters/irb.rb
|
@@ -410,6 +407,7 @@ files:
|
|
410
407
|
- lib/polyphony/core/sync.rb
|
411
408
|
- lib/polyphony/core/thread_pool.rb
|
412
409
|
- lib/polyphony/core/throttler.rb
|
410
|
+
- lib/polyphony/event.rb
|
413
411
|
- lib/polyphony/extensions/core.rb
|
414
412
|
- lib/polyphony/extensions/fiber.rb
|
415
413
|
- lib/polyphony/extensions/io.rb
|
@@ -424,20 +422,22 @@ files:
|
|
424
422
|
- test/helper.rb
|
425
423
|
- test/run.rb
|
426
424
|
- test/stress.rb
|
427
|
-
- test/
|
425
|
+
- test/test_agent.rb
|
426
|
+
- test/test_event.rb
|
428
427
|
- test/test_ext.rb
|
429
428
|
- test/test_fiber.rb
|
430
429
|
- test/test_global_api.rb
|
431
430
|
- test/test_io.rb
|
432
431
|
- test/test_kernel.rb
|
433
432
|
- test/test_process_supervision.rb
|
433
|
+
- test/test_queue.rb
|
434
434
|
- test/test_resource_pool.rb
|
435
435
|
- test/test_signal.rb
|
436
|
+
- test/test_socket.rb
|
436
437
|
- test/test_supervise.rb
|
437
438
|
- test/test_thread.rb
|
438
439
|
- test/test_thread_pool.rb
|
439
440
|
- test/test_throttler.rb
|
440
|
-
- test/test_timer.rb
|
441
441
|
- test/test_trace.rb
|
442
442
|
homepage: https://digital-fabric.github.io/polyphony
|
443
443
|
licenses:
|
data/ext/gyro/async.c
DELETED
@@ -1,132 +0,0 @@
|
|
1
|
-
#include "gyro.h"
|
2
|
-
|
3
|
-
struct Gyro_Async {
|
4
|
-
GYRO_WATCHER_DECL(ev_async);
|
5
|
-
VALUE value;
|
6
|
-
};
|
7
|
-
|
8
|
-
VALUE cGyro_Async = Qnil;
|
9
|
-
|
10
|
-
static void Gyro_Async_mark(void *ptr) {
|
11
|
-
struct Gyro_Async *async = ptr;
|
12
|
-
|
13
|
-
GYRO_WATCHER_MARK(async);
|
14
|
-
if (async->value != Qnil) rb_gc_mark(async->value);
|
15
|
-
}
|
16
|
-
|
17
|
-
static void Gyro_Async_free(void *ptr) {
|
18
|
-
struct Gyro_Async *async = ptr;
|
19
|
-
|
20
|
-
GYRO_WATCHER_FREE(async);
|
21
|
-
}
|
22
|
-
|
23
|
-
static size_t Gyro_Async_size(const void *ptr) {
|
24
|
-
return sizeof(struct Gyro_Async);
|
25
|
-
}
|
26
|
-
|
27
|
-
static const rb_data_type_t Gyro_Async_type = {
|
28
|
-
"Gyro_Async",
|
29
|
-
{Gyro_Async_mark, Gyro_Async_free, Gyro_Async_size,},
|
30
|
-
0, 0, 0
|
31
|
-
};
|
32
|
-
|
33
|
-
static VALUE Gyro_Async_allocate(VALUE klass) {
|
34
|
-
struct Gyro_Async *async = ALLOC(struct Gyro_Async);
|
35
|
-
|
36
|
-
return TypedData_Wrap_Struct(klass, &Gyro_Async_type, async);
|
37
|
-
}
|
38
|
-
|
39
|
-
inline void async_activate(struct Gyro_Async *async) {
|
40
|
-
if (async->active) return;
|
41
|
-
|
42
|
-
async->active = 1;
|
43
|
-
async->fiber = rb_fiber_current();
|
44
|
-
async->selector = Thread_current_event_selector();
|
45
|
-
async->ev_loop = Gyro_Selector_ev_loop(async->selector);
|
46
|
-
Gyro_Selector_add_active_watcher(async->selector, async->self);
|
47
|
-
ev_async_start(async->ev_loop, &async->ev_async);
|
48
|
-
}
|
49
|
-
|
50
|
-
inline void async_deactivate(struct Gyro_Async *async) {
|
51
|
-
if (!async->active) return;
|
52
|
-
|
53
|
-
ev_async_stop(async->ev_loop, &async->ev_async);
|
54
|
-
Gyro_Selector_remove_active_watcher(async->selector, async->self);
|
55
|
-
async->active = 0;
|
56
|
-
async->ev_loop = 0;
|
57
|
-
async->selector = Qnil;
|
58
|
-
async->fiber = Qnil;
|
59
|
-
async->value = Qnil;
|
60
|
-
}
|
61
|
-
|
62
|
-
void Gyro_Async_callback(struct ev_loop *ev_loop, struct ev_async *ev_async, int revents) {
|
63
|
-
struct Gyro_Async *async = (struct Gyro_Async*)ev_async;
|
64
|
-
|
65
|
-
Fiber_make_runnable(async->fiber, async->value);
|
66
|
-
async_deactivate(async);
|
67
|
-
}
|
68
|
-
|
69
|
-
#define GetGyro_Async(obj, async) \
|
70
|
-
TypedData_Get_Struct((obj), struct Gyro_Async, &Gyro_Async_type, (async))
|
71
|
-
|
72
|
-
static VALUE Gyro_Async_initialize(VALUE self) {
|
73
|
-
struct Gyro_Async *async;
|
74
|
-
GetGyro_Async(self, async);
|
75
|
-
|
76
|
-
GYRO_WATCHER_INITIALIZE(async, self);
|
77
|
-
async->value = Qnil;
|
78
|
-
ev_async_init(&async->ev_async, Gyro_Async_callback);
|
79
|
-
|
80
|
-
return Qnil;
|
81
|
-
}
|
82
|
-
|
83
|
-
static VALUE Gyro_Async_signal(int argc, VALUE *argv, VALUE self) {
|
84
|
-
struct Gyro_Async *async;
|
85
|
-
GetGyro_Async(self, async);
|
86
|
-
|
87
|
-
if (!async->active) {
|
88
|
-
// printf("signal called before await\n");
|
89
|
-
return Qnil;
|
90
|
-
}
|
91
|
-
|
92
|
-
async->value = (argc == 1) ? argv[0] : Qnil;
|
93
|
-
ev_async_send(async->ev_loop, &async->ev_async);
|
94
|
-
|
95
|
-
return Qnil;
|
96
|
-
}
|
97
|
-
|
98
|
-
VALUE Gyro_Async_await(VALUE self) {
|
99
|
-
struct Gyro_Async *async;
|
100
|
-
VALUE ret;
|
101
|
-
GetGyro_Async(self, async);
|
102
|
-
|
103
|
-
async_activate(async);
|
104
|
-
ret = Gyro_switchpoint();
|
105
|
-
async_deactivate(async);
|
106
|
-
|
107
|
-
TEST_RESUME_EXCEPTION(ret);
|
108
|
-
RB_GC_GUARD(ret);
|
109
|
-
return ret;
|
110
|
-
}
|
111
|
-
|
112
|
-
VALUE Gyro_Async_await_no_raise(VALUE self) {
|
113
|
-
struct Gyro_Async *async;
|
114
|
-
VALUE ret;
|
115
|
-
GetGyro_Async(self, async);
|
116
|
-
|
117
|
-
async_activate(async);
|
118
|
-
ret = Gyro_switchpoint();
|
119
|
-
async_deactivate(async);
|
120
|
-
|
121
|
-
RB_GC_GUARD(ret);
|
122
|
-
return ret;
|
123
|
-
}
|
124
|
-
|
125
|
-
void Init_Gyro_Async() {
|
126
|
-
cGyro_Async = rb_define_class_under(mGyro, "Async", rb_cData);
|
127
|
-
rb_define_alloc_func(cGyro_Async, Gyro_Async_allocate);
|
128
|
-
|
129
|
-
rb_define_method(cGyro_Async, "initialize", Gyro_Async_initialize, 0);
|
130
|
-
rb_define_method(cGyro_Async, "await", Gyro_Async_await, 0);
|
131
|
-
rb_define_method(cGyro_Async, "signal", Gyro_Async_signal, -1);
|
132
|
-
}
|
data/ext/gyro/child.c
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
#include "gyro.h"
|
2
|
-
|
3
|
-
struct Gyro_Child {
|
4
|
-
GYRO_WATCHER_DECL(ev_child);
|
5
|
-
int pid;
|
6
|
-
};
|
7
|
-
|
8
|
-
static VALUE cGyro_Child = Qnil;
|
9
|
-
|
10
|
-
static void Gyro_Child_mark(void *ptr) {
|
11
|
-
struct Gyro_Child *child = ptr;
|
12
|
-
GYRO_WATCHER_MARK(child);
|
13
|
-
}
|
14
|
-
|
15
|
-
static void Gyro_Child_free(void *ptr) {
|
16
|
-
struct Gyro_Child *child = ptr;
|
17
|
-
GYRO_WATCHER_FREE(child);
|
18
|
-
}
|
19
|
-
|
20
|
-
static size_t Gyro_Child_size(const void *ptr) {
|
21
|
-
return sizeof(struct Gyro_Child);
|
22
|
-
}
|
23
|
-
|
24
|
-
static const rb_data_type_t Gyro_Child_type = {
|
25
|
-
"Gyro_Child",
|
26
|
-
{Gyro_Child_mark, Gyro_Child_free, Gyro_Child_size,},
|
27
|
-
0, 0, 0
|
28
|
-
};
|
29
|
-
|
30
|
-
static VALUE Gyro_Child_allocate(VALUE klass) {
|
31
|
-
struct Gyro_Child *child = ALLOC(struct Gyro_Child);
|
32
|
-
return TypedData_Wrap_Struct(klass, &Gyro_Child_type, child);
|
33
|
-
}
|
34
|
-
|
35
|
-
inline void child_activate(struct Gyro_Child *child) {
|
36
|
-
if (child->active) return;
|
37
|
-
|
38
|
-
child->active = 1;
|
39
|
-
child->fiber = rb_fiber_current();
|
40
|
-
child->selector = Thread_current_event_selector();
|
41
|
-
child->ev_loop = Gyro_Selector_ev_loop(child->selector);
|
42
|
-
Gyro_Selector_add_active_watcher(child->selector, child->self);
|
43
|
-
ev_child_start(child->ev_loop, &child->ev_child);
|
44
|
-
}
|
45
|
-
|
46
|
-
inline void child_deactivate(struct Gyro_Child *child) {
|
47
|
-
if (!child->active) return;
|
48
|
-
|
49
|
-
ev_child_stop(child->ev_loop, &child->ev_child);
|
50
|
-
Gyro_Selector_remove_active_watcher(child->selector, child->self);
|
51
|
-
child->active = 0;
|
52
|
-
child->ev_loop = 0;
|
53
|
-
child->selector = Qnil;
|
54
|
-
child->fiber = Qnil;
|
55
|
-
}
|
56
|
-
|
57
|
-
VALUE Gyro_Child_resume_value(struct ev_child *ev_child) {
|
58
|
-
int exit_status = ev_child->rstatus >> 8; // weird, why should we do this?
|
59
|
-
|
60
|
-
return rb_ary_new_from_args(
|
61
|
-
2, INT2NUM(ev_child->rpid), INT2NUM(exit_status)
|
62
|
-
);
|
63
|
-
}
|
64
|
-
|
65
|
-
void Gyro_Child_callback(struct ev_loop *ev_loop, struct ev_child *ev_child, int revents) {
|
66
|
-
struct Gyro_Child *child = (struct Gyro_Child*)ev_child;
|
67
|
-
|
68
|
-
VALUE resume_value = Gyro_Child_resume_value(ev_child);
|
69
|
-
Fiber_make_runnable(child->fiber, resume_value);
|
70
|
-
|
71
|
-
child_deactivate(child);
|
72
|
-
}
|
73
|
-
|
74
|
-
#define GetGyro_Child(obj, child) \
|
75
|
-
TypedData_Get_Struct((obj), struct Gyro_Child, &Gyro_Child_type, (child))
|
76
|
-
|
77
|
-
static VALUE Gyro_Child_initialize(VALUE self, VALUE pid) {
|
78
|
-
struct Gyro_Child *child;
|
79
|
-
|
80
|
-
GetGyro_Child(self, child);
|
81
|
-
GYRO_WATCHER_INITIALIZE(child, self);
|
82
|
-
child->pid = NUM2INT(pid);
|
83
|
-
ev_child_init(&child->ev_child, Gyro_Child_callback, child->pid, 0);
|
84
|
-
|
85
|
-
return Qnil;
|
86
|
-
}
|
87
|
-
|
88
|
-
static VALUE Gyro_Child_await(VALUE self) {
|
89
|
-
struct Gyro_Child *child;
|
90
|
-
VALUE ret;
|
91
|
-
GetGyro_Child(self, child);
|
92
|
-
|
93
|
-
child_activate(child);
|
94
|
-
ret = Gyro_switchpoint();
|
95
|
-
child_deactivate(child);
|
96
|
-
|
97
|
-
TEST_RESUME_EXCEPTION(ret);
|
98
|
-
RB_GC_GUARD(ret);
|
99
|
-
return ret;
|
100
|
-
}
|
101
|
-
|
102
|
-
void Init_Gyro_Child() {
|
103
|
-
cGyro_Child = rb_define_class_under(mGyro, "Child", rb_cData);
|
104
|
-
rb_define_alloc_func(cGyro_Child, Gyro_Child_allocate);
|
105
|
-
|
106
|
-
rb_define_method(cGyro_Child, "initialize", Gyro_Child_initialize, 1);
|
107
|
-
rb_define_method(cGyro_Child, "await", Gyro_Child_await, 0);
|
108
|
-
}
|
data/ext/gyro/gyro.h
DELETED
@@ -1,158 +0,0 @@
|
|
1
|
-
#ifndef RUBY_EV_H
|
2
|
-
#define RUBY_EV_H
|
3
|
-
|
4
|
-
#include "ruby.h"
|
5
|
-
#include "ruby/io.h"
|
6
|
-
#include "libev.h"
|
7
|
-
|
8
|
-
// debugging
|
9
|
-
#define OBJ_ID(obj) (NUM2LONG(rb_funcall(obj, rb_intern("object_id"), 0)))
|
10
|
-
#define INSPECT(...) (rb_funcall(rb_cObject, rb_intern("p"), __VA_ARGS__))
|
11
|
-
#define FIBER_TRACE(...) if (__tracing_enabled__) { \
|
12
|
-
rb_funcall(rb_cObject, ID_fiber_trace, __VA_ARGS__); \
|
13
|
-
}
|
14
|
-
|
15
|
-
#define TEST_RESUME_EXCEPTION(ret) if (RTEST(rb_obj_is_kind_of(ret, rb_eException))) { \
|
16
|
-
return rb_funcall(rb_mKernel, ID_raise, 1, ret); \
|
17
|
-
}
|
18
|
-
|
19
|
-
typedef struct Gyro_watcher {
|
20
|
-
int active;
|
21
|
-
int generation;
|
22
|
-
|
23
|
-
struct ev_loop *ev_loop;
|
24
|
-
|
25
|
-
VALUE self;
|
26
|
-
VALUE fiber;
|
27
|
-
VALUE selector;
|
28
|
-
} Gyro_watcher_t;
|
29
|
-
|
30
|
-
|
31
|
-
#define GYRO_WATCHER_DECL(type) \
|
32
|
-
struct type type; \
|
33
|
-
int active; \
|
34
|
-
int generation; \
|
35
|
-
struct ev_loop *ev_loop; \
|
36
|
-
VALUE self; \
|
37
|
-
VALUE fiber; \
|
38
|
-
VALUE selector;
|
39
|
-
|
40
|
-
#define GYRO_WATCHER_INITIALIZE(o, self) \
|
41
|
-
o->active = 0; \
|
42
|
-
o->generation = __gyro_current_generation__; \
|
43
|
-
o->ev_loop = 0; \
|
44
|
-
o->self = self; \
|
45
|
-
o->fiber = Qnil; \
|
46
|
-
o->selector = Qnil;
|
47
|
-
|
48
|
-
#define GYRO_WATCHER_MARK(o) \
|
49
|
-
if (o->fiber != Qnil) rb_gc_mark(o->fiber); \
|
50
|
-
if (o->selector != Qnil) rb_gc_mark(o->selector);
|
51
|
-
|
52
|
-
#define GYRO_WATCHER_STOP_EXPAND(o) ev_ ## o ## _stop
|
53
|
-
#define GYRO_WATCHER_STOP(o) GYRO_WATCHER_STOP_EXPAND(o)
|
54
|
-
|
55
|
-
#define GYRO_WATCHER_FIELD_EXPAND(o) ev_ ## o
|
56
|
-
#define GYRO_WATCHER_FIELD(o) GYRO_WATCHER_FIELD_EXPAND(o)
|
57
|
-
|
58
|
-
#define GYRO_WATCHER_FREE(o) \
|
59
|
-
if (o->generation < __gyro_current_generation__) return; \
|
60
|
-
if (o->active) { \
|
61
|
-
ev_clear_pending(o->ev_loop, &o->GYRO_WATCHER_FIELD(o)); \
|
62
|
-
GYRO_WATCHER_STOP(o)(o->ev_loop, &o->GYRO_WATCHER_FIELD(o)); \
|
63
|
-
} \
|
64
|
-
xfree(o);
|
65
|
-
|
66
|
-
extern VALUE mGyro;
|
67
|
-
extern VALUE cGyro_Async;
|
68
|
-
extern VALUE cGyro_IO;
|
69
|
-
extern VALUE cGyro_Queue;
|
70
|
-
extern VALUE cGyro_Selector;
|
71
|
-
extern VALUE cGyro_Timer;
|
72
|
-
|
73
|
-
extern ID ID_call;
|
74
|
-
extern ID ID_caller;
|
75
|
-
extern ID ID_clear;
|
76
|
-
extern ID ID_each;
|
77
|
-
extern ID ID_fiber_trace;
|
78
|
-
extern ID ID_inspect;
|
79
|
-
extern ID ID_ivar_running;
|
80
|
-
extern ID ID_ivar_thread;
|
81
|
-
extern ID ID_new;
|
82
|
-
extern ID ID_raise;
|
83
|
-
extern ID ID_runnable;
|
84
|
-
extern ID ID_runnable_value;
|
85
|
-
extern ID ID_signal;
|
86
|
-
extern ID ID_size;
|
87
|
-
extern ID ID_switch_fiber;
|
88
|
-
extern ID ID_transfer;
|
89
|
-
extern ID ID_R;
|
90
|
-
extern ID ID_W;
|
91
|
-
extern ID ID_RW;
|
92
|
-
|
93
|
-
extern VALUE SYM_fiber_create;
|
94
|
-
extern VALUE SYM_fiber_ev_loop_enter;
|
95
|
-
extern VALUE SYM_fiber_ev_loop_leave;
|
96
|
-
extern VALUE SYM_fiber_run;
|
97
|
-
extern VALUE SYM_fiber_schedule;
|
98
|
-
extern VALUE SYM_fiber_switchpoint;
|
99
|
-
extern VALUE SYM_fiber_terminate;
|
100
|
-
|
101
|
-
extern int __tracing_enabled__;
|
102
|
-
extern int __gyro_current_generation__;
|
103
|
-
|
104
|
-
enum {
|
105
|
-
FIBER_STATE_NOT_SCHEDULED = 0,
|
106
|
-
FIBER_STATE_WAITING = 1,
|
107
|
-
FIBER_STATE_SCHEDULED = 2
|
108
|
-
};
|
109
|
-
|
110
|
-
// watcher flags
|
111
|
-
enum {
|
112
|
-
// a watcher's active field will be set to this after fork
|
113
|
-
GYRO_WATCHER_POST_FORK = 0xFF
|
114
|
-
};
|
115
|
-
|
116
|
-
VALUE Fiber_auto_async(VALUE self);
|
117
|
-
VALUE Fiber_auto_io(VALUE self);
|
118
|
-
void Fiber_make_runnable(VALUE fiber, VALUE value);
|
119
|
-
|
120
|
-
VALUE Gyro_Async_await(VALUE async);
|
121
|
-
VALUE Gyro_Async_await_no_raise(VALUE async);
|
122
|
-
|
123
|
-
VALUE Gyro_IO_auto_io(int fd, int events);
|
124
|
-
VALUE Gyro_IO_await(VALUE self);
|
125
|
-
|
126
|
-
void Gyro_Selector_add_active_watcher(VALUE self, VALUE watcher);
|
127
|
-
VALUE Gyro_Selector_break_out_of_ev_loop(VALUE self);
|
128
|
-
struct ev_loop *Gyro_Selector_current_thread_ev_loop();
|
129
|
-
struct ev_loop *Gyro_Selector_ev_loop(VALUE selector);
|
130
|
-
ev_tstamp Gyro_Selector_now(VALUE selector);
|
131
|
-
long Gyro_Selector_pending_count(VALUE self);
|
132
|
-
VALUE Gyro_Selector_post_fork(VALUE self);
|
133
|
-
void Gyro_Selector_remove_active_watcher(VALUE self, VALUE watcher);
|
134
|
-
VALUE Gyro_Selector_run(VALUE self, VALUE current_fiber);
|
135
|
-
void Gyro_Selector_run_no_wait(VALUE self, VALUE current_fiber, long runnable_count);
|
136
|
-
VALUE Gyro_switchpoint();
|
137
|
-
|
138
|
-
|
139
|
-
VALUE Gyro_snooze(VALUE self);
|
140
|
-
VALUE Gyro_Timer_await(VALUE self);
|
141
|
-
|
142
|
-
VALUE IO_read_watcher(VALUE io);
|
143
|
-
VALUE IO_write_watcher(VALUE io);
|
144
|
-
|
145
|
-
VALUE Gyro_Queue_push(VALUE self, VALUE value);
|
146
|
-
|
147
|
-
VALUE Thread_current_event_selector();
|
148
|
-
VALUE Thread_post_fork(VALUE thread);
|
149
|
-
VALUE Thread_ref(VALUE thread);
|
150
|
-
VALUE Thread_schedule_fiber(VALUE thread, VALUE fiber, VALUE value);
|
151
|
-
VALUE Thread_switch_fiber(VALUE thread);
|
152
|
-
VALUE Thread_unref(VALUE thread);
|
153
|
-
|
154
|
-
int io_setstrbuf(VALUE *str, long len);
|
155
|
-
void io_set_read_length(VALUE str, long n, int shrinkable);
|
156
|
-
VALUE io_enc_str(VALUE str, rb_io_t *fptr);
|
157
|
-
|
158
|
-
#endif /* RUBY_EV_H */
|