polyphony 0.39 → 0.43.1
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/.github/workflows/test.yml +11 -2
- data/.gitignore +2 -2
- data/.rubocop.yml +30 -0
- data/CHANGELOG.md +23 -4
- data/Gemfile.lock +15 -12
- data/README.md +2 -1
- data/Rakefile +3 -3
- data/TODO.md +27 -97
- data/docs/_config.yml +56 -7
- data/docs/_sass/custom/custom.scss +6 -26
- data/docs/_sass/overrides.scss +0 -46
- data/docs/{user-guide → _user-guide}/all-about-timers.md +0 -0
- data/docs/_user-guide/index.md +9 -0
- data/docs/{user-guide → _user-guide}/web-server.md +0 -0
- data/docs/api-reference/fiber.md +2 -2
- data/docs/api-reference/index.md +9 -0
- data/docs/api-reference/polyphony-process.md +1 -1
- data/docs/api-reference/thread.md +1 -1
- data/docs/faq.md +21 -11
- data/docs/favicon.ico +0 -0
- data/docs/getting-started/index.md +10 -0
- data/docs/getting-started/installing.md +2 -6
- data/docs/getting-started/overview.md +486 -0
- data/docs/getting-started/tutorial.md +27 -19
- data/docs/index.md +6 -2
- data/docs/main-concepts/concurrency.md +0 -5
- data/docs/main-concepts/design-principles.md +69 -21
- data/docs/main-concepts/extending.md +1 -1
- data/docs/main-concepts/index.md +9 -0
- data/docs/polyphony-logo.png +0 -0
- data/examples/core/01-spinning-up-fibers.rb +1 -0
- data/examples/core/03-interrupting.rb +4 -1
- data/examples/core/04-handling-signals.rb +19 -0
- data/examples/core/xx-agent.rb +102 -0
- data/examples/core/xx-sleeping.rb +14 -6
- data/examples/io/tunnel.rb +48 -0
- 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 +13 -36
- data/examples/performance/thread-vs-fiber/polyphony_server_read_loop.rb +58 -0
- data/examples/performance/xx-array.rb +11 -0
- data/examples/performance/xx-fiber-switch.rb +9 -0
- data/examples/performance/xx-snooze.rb +15 -0
- data/ext/{gyro → polyphony}/extconf.rb +2 -2
- data/ext/{gyro → polyphony}/fiber.c +17 -23
- data/ext/{gyro → polyphony}/libev.c +0 -0
- data/ext/{gyro → polyphony}/libev.h +0 -0
- data/ext/polyphony/libev_agent.c +718 -0
- data/ext/polyphony/libev_queue.c +216 -0
- data/ext/polyphony/polyphony.c +73 -0
- data/ext/{gyro/gyro.h → polyphony/polyphony.h} +19 -39
- data/ext/polyphony/polyphony_ext.c +21 -0
- data/ext/polyphony/thread.c +200 -0
- data/ext/{gyro → polyphony}/tracing.c +1 -1
- data/lib/polyphony.rb +19 -14
- 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 +13 -11
- 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 +22 -14
- data/lib/polyphony/extensions/fiber.rb +4 -4
- data/lib/polyphony/extensions/io.rb +59 -25
- data/lib/polyphony/extensions/openssl.rb +36 -16
- data/lib/polyphony/extensions/socket.rb +28 -10
- 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 +4 -4
- data/test/helper.rb +12 -8
- data/test/test_agent.rb +124 -0
- data/test/{test_async.rb → test_event.rb} +15 -7
- data/test/test_ext.rb +25 -4
- data/test/test_fiber.rb +19 -10
- data/test/test_global_api.rb +11 -11
- data/test/test_io.rb +44 -29
- data/test/test_queue.rb +74 -0
- data/test/test_signal.rb +3 -40
- data/test/test_socket.rb +34 -0
- data/test/test_thread.rb +38 -17
- data/test/test_thread_pool.rb +2 -2
- data/test/test_throttler.rb +5 -3
- data/test/test_trace.rb +6 -5
- metadata +41 -43
- data/docs/_includes/nav.html +0 -51
- data/docs/_includes/prevnext.html +0 -17
- data/docs/_layouts/default.html +0 -106
- data/docs/api-reference.md +0 -11
- data/docs/api-reference/gyro-async.md +0 -57
- data/docs/api-reference/gyro-child.md +0 -29
- data/docs/api-reference/gyro-queue.md +0 -44
- data/docs/api-reference/gyro-timer.md +0 -51
- data/docs/api-reference/gyro.md +0 -25
- data/docs/getting-started.md +0 -10
- data/docs/main-concepts.md +0 -10
- data/docs/user-guide.md +0 -10
- data/examples/core/forever_sleep.rb +0 -19
- data/ext/gyro/async.c +0 -162
- data/ext/gyro/child.c +0 -141
- data/ext/gyro/gyro.c +0 -103
- data/ext/gyro/gyro_ext.c +0 -33
- data/ext/gyro/io.c +0 -489
- data/ext/gyro/queue.c +0 -142
- data/ext/gyro/selector.c +0 -228
- data/ext/gyro/signal.c +0 -133
- data/ext/gyro/socket.c +0 -210
- data/ext/gyro/thread.c +0 -308
- data/ext/gyro/timer.c +0 -151
- data/test/test_timer.rb +0 -32
data/ext/gyro/timer.c
DELETED
@@ -1,151 +0,0 @@
|
|
1
|
-
#include "gyro.h"
|
2
|
-
|
3
|
-
struct Gyro_Timer {
|
4
|
-
struct ev_timer ev_timer;
|
5
|
-
struct ev_loop *ev_loop;
|
6
|
-
int active;
|
7
|
-
double after;
|
8
|
-
double repeat;
|
9
|
-
VALUE self;
|
10
|
-
VALUE fiber;
|
11
|
-
VALUE selector;
|
12
|
-
};
|
13
|
-
|
14
|
-
VALUE cGyro_Timer = Qnil;
|
15
|
-
|
16
|
-
static void Gyro_Timer_mark(void *ptr) {
|
17
|
-
struct Gyro_Timer *timer = ptr;
|
18
|
-
if (timer->fiber != Qnil) {
|
19
|
-
rb_gc_mark(timer->fiber);
|
20
|
-
}
|
21
|
-
if (timer->selector != Qnil) {
|
22
|
-
rb_gc_mark(timer->selector);
|
23
|
-
}
|
24
|
-
}
|
25
|
-
|
26
|
-
static void Gyro_Timer_free(void *ptr) {
|
27
|
-
struct Gyro_Timer *timer = ptr;
|
28
|
-
switch (timer->active) {
|
29
|
-
case GYRO_WATCHER_POST_FORK:
|
30
|
-
return;
|
31
|
-
case 1:
|
32
|
-
ev_clear_pending(timer->ev_loop, &timer->ev_timer);
|
33
|
-
ev_timer_stop(timer->ev_loop, &timer->ev_timer);
|
34
|
-
default:
|
35
|
-
xfree(timer);
|
36
|
-
}
|
37
|
-
}
|
38
|
-
|
39
|
-
static size_t Gyro_Timer_size(const void *ptr) {
|
40
|
-
return sizeof(struct Gyro_Timer);
|
41
|
-
}
|
42
|
-
|
43
|
-
static const rb_data_type_t Gyro_Timer_type = {
|
44
|
-
"Gyro_Timer",
|
45
|
-
{Gyro_Timer_mark, Gyro_Timer_free, Gyro_Timer_size,},
|
46
|
-
0, 0, 0
|
47
|
-
};
|
48
|
-
|
49
|
-
static VALUE Gyro_Timer_allocate(VALUE klass) {
|
50
|
-
struct Gyro_Timer *timer = ALLOC(struct Gyro_Timer);
|
51
|
-
return TypedData_Wrap_Struct(klass, &Gyro_Timer_type, timer);
|
52
|
-
}
|
53
|
-
|
54
|
-
#define GetGyro_Timer(obj, timer) \
|
55
|
-
TypedData_Get_Struct((obj), struct Gyro_Timer, &Gyro_Timer_type, (timer))
|
56
|
-
|
57
|
-
inline void timer_activate(struct Gyro_Timer *timer) {
|
58
|
-
timer->fiber = rb_fiber_current();
|
59
|
-
timer->selector = Thread_current_event_selector();
|
60
|
-
timer->ev_loop = Gyro_Selector_ev_loop(timer->selector);
|
61
|
-
|
62
|
-
if (timer->active) return;
|
63
|
-
|
64
|
-
timer->active = 1;
|
65
|
-
Gyro_Selector_add_active_watcher(timer->selector, timer->self);
|
66
|
-
ev_timer_start(timer->ev_loop, &timer->ev_timer);
|
67
|
-
}
|
68
|
-
|
69
|
-
inline void timer_deactivate(struct Gyro_Timer *timer, int force_deactivate) {
|
70
|
-
if (!timer->active) return;
|
71
|
-
|
72
|
-
timer->fiber = Qnil;
|
73
|
-
|
74
|
-
// timer should not be deactivated if
|
75
|
-
if (timer->repeat && !force_deactivate) return;
|
76
|
-
|
77
|
-
ev_timer_stop(timer->ev_loop, &timer->ev_timer);
|
78
|
-
if (RTEST(timer->selector)) {
|
79
|
-
Gyro_Selector_remove_active_watcher(timer->selector, timer->self);
|
80
|
-
timer->selector = Qnil;
|
81
|
-
}
|
82
|
-
timer->ev_loop = 0;
|
83
|
-
timer->active = 0;
|
84
|
-
}
|
85
|
-
|
86
|
-
void Gyro_Timer_callback(struct ev_loop *ev_loop, struct ev_timer *ev_timer, int revents) {
|
87
|
-
struct Gyro_Timer *timer = (struct Gyro_Timer*)ev_timer;
|
88
|
-
|
89
|
-
if (timer->fiber != Qnil)
|
90
|
-
Fiber_make_runnable(timer->fiber, DBL2NUM(timer->after));
|
91
|
-
timer_deactivate(timer, 1);
|
92
|
-
}
|
93
|
-
|
94
|
-
static VALUE Gyro_Timer_initialize(VALUE self, VALUE after, VALUE repeat) {
|
95
|
-
struct Gyro_Timer *timer;
|
96
|
-
|
97
|
-
GetGyro_Timer(self, timer);
|
98
|
-
|
99
|
-
timer->self = self;
|
100
|
-
timer->fiber = Qnil;
|
101
|
-
timer->selector = Qnil;
|
102
|
-
timer->after = NUM2DBL(after);
|
103
|
-
timer->repeat = NUM2DBL(repeat);
|
104
|
-
timer->active = 0;
|
105
|
-
timer->ev_loop = 0;
|
106
|
-
|
107
|
-
ev_timer_init(&timer->ev_timer, Gyro_Timer_callback, timer->after, timer->repeat);
|
108
|
-
|
109
|
-
return Qnil;
|
110
|
-
}
|
111
|
-
|
112
|
-
VALUE Gyro_Timer_stop(VALUE self) {
|
113
|
-
struct Gyro_Timer *timer;
|
114
|
-
GetGyro_Timer(self, timer);
|
115
|
-
|
116
|
-
timer_deactivate(timer, 0);
|
117
|
-
return self;
|
118
|
-
}
|
119
|
-
|
120
|
-
VALUE Gyro_Timer_await(VALUE self) {
|
121
|
-
struct Gyro_Timer *timer;
|
122
|
-
GetGyro_Timer(self, timer);
|
123
|
-
|
124
|
-
timer_activate(timer);
|
125
|
-
VALUE ret = Gyro_switchpoint();
|
126
|
-
timer_deactivate(timer, 1);
|
127
|
-
|
128
|
-
TEST_RESUME_EXCEPTION(ret);
|
129
|
-
RB_GC_GUARD(ret);
|
130
|
-
return ret;
|
131
|
-
}
|
132
|
-
|
133
|
-
VALUE Gyro_Timer_deactivate_post_fork(VALUE self) {
|
134
|
-
struct Gyro_Timer *timer;
|
135
|
-
GetGyro_Timer(self, timer);
|
136
|
-
|
137
|
-
if (timer->active)
|
138
|
-
timer->active = GYRO_WATCHER_POST_FORK;
|
139
|
-
|
140
|
-
return self;
|
141
|
-
}
|
142
|
-
|
143
|
-
void Init_Gyro_Timer() {
|
144
|
-
cGyro_Timer = rb_define_class_under(mGyro, "Timer", rb_cData);
|
145
|
-
rb_define_alloc_func(cGyro_Timer, Gyro_Timer_allocate);
|
146
|
-
|
147
|
-
rb_define_method(cGyro_Timer, "initialize", Gyro_Timer_initialize, 2);
|
148
|
-
rb_define_method(cGyro_Timer, "await", Gyro_Timer_await, 0);
|
149
|
-
rb_define_method(cGyro_Timer, "deactivate_post_fork", Gyro_Timer_deactivate_post_fork, 0);
|
150
|
-
rb_define_method(cGyro_Timer, "stop", Gyro_Timer_stop, 0);
|
151
|
-
}
|
data/test/test_timer.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'helper'
|
4
|
-
|
5
|
-
class TimerTest < MiniTest::Test
|
6
|
-
def test_that_one_shot_timer_works
|
7
|
-
count = 0
|
8
|
-
t = Gyro::Timer.new(0.01, 0)
|
9
|
-
spin {
|
10
|
-
t.await
|
11
|
-
count += 1
|
12
|
-
}
|
13
|
-
suspend
|
14
|
-
assert_equal 1, count
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_that_repeating_timer_works
|
18
|
-
count = 0
|
19
|
-
t = Gyro::Timer.new(0.001, 0.001)
|
20
|
-
spin {
|
21
|
-
loop {
|
22
|
-
t.await
|
23
|
-
count += 1
|
24
|
-
break if count >= 3
|
25
|
-
}
|
26
|
-
}
|
27
|
-
suspend
|
28
|
-
assert_equal 3, count
|
29
|
-
ensure
|
30
|
-
t.stop
|
31
|
-
end
|
32
|
-
end
|