event 0.9.0 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/event/selector/epoll.c +12 -7
- data/ext/event/selector/kqueue.c +11 -4
- data/ext/event/selector/selector.c +8 -5
- data/ext/event/selector/selector.h +1 -1
- data/ext/event/selector/uring.c +12 -7
- data/lib/event/debug/selector.rb +140 -0
- data/lib/event/selector/select.rb +5 -0
- data/lib/event/version.rb +1 -1
- metadata +3 -3
- data/lib/event/debug.rb +0 -126
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ede0cef441063c9e8675858ccbb0fb10a9e14403e812829531f8a5fedf144499
|
4
|
+
data.tar.gz: 47519c0f64233d29be411f6148cb1c831734ed36a56f863881d5fa14e2f7245e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16a588ae4f5319f430ffd31cf0374defaf099b87db406f27c6af8b667666038725587dfac4d3b328a5496a65335882263b846de1a67934df432beaceae23cff7
|
7
|
+
data.tar.gz: 61a29c0c4379953b56ac6aef3b002513ac58603f16b2c9656afb61fcfbb91b9954a47bbf3bb04a414977f7ba11205974e229c1d38856fc491b84124cae7814cf
|
data/ext/event/selector/epoll.c
CHANGED
@@ -112,14 +112,20 @@ VALUE Event_Selector_EPoll_close(VALUE self) {
|
|
112
112
|
return Qnil;
|
113
113
|
}
|
114
114
|
|
115
|
-
VALUE
|
115
|
+
VALUE Event_Selector_EPoll_transfer(VALUE self)
|
116
116
|
{
|
117
117
|
struct Event_Selector_EPoll *data = NULL;
|
118
118
|
TypedData_Get_Struct(self, struct Event_Selector_EPoll, &Event_Selector_EPoll_Type, data);
|
119
119
|
|
120
|
-
|
120
|
+
return Event_Selector_fiber_transfer(data->backend.loop, 0, NULL);
|
121
|
+
}
|
122
|
+
|
123
|
+
VALUE Event_Selector_EPoll_resume(int argc, VALUE *argv, VALUE self)
|
124
|
+
{
|
125
|
+
struct Event_Selector_EPoll *data = NULL;
|
126
|
+
TypedData_Get_Struct(self, struct Event_Selector_EPoll, &Event_Selector_EPoll_Type, data);
|
121
127
|
|
122
|
-
return
|
128
|
+
return Event_Selector_resume(&data->backend, argc, argv);
|
123
129
|
}
|
124
130
|
|
125
131
|
VALUE Event_Selector_EPoll_yield(VALUE self)
|
@@ -127,9 +133,7 @@ VALUE Event_Selector_EPoll_yield(VALUE self)
|
|
127
133
|
struct Event_Selector_EPoll *data = NULL;
|
128
134
|
TypedData_Get_Struct(self, struct Event_Selector_EPoll, &Event_Selector_EPoll_Type, data);
|
129
135
|
|
130
|
-
Event_Selector_yield(&data->backend);
|
131
|
-
|
132
|
-
return Qnil;
|
136
|
+
return Event_Selector_yield(&data->backend);
|
133
137
|
}
|
134
138
|
|
135
139
|
VALUE Event_Selector_EPoll_push(VALUE self, VALUE fiber)
|
@@ -147,7 +151,7 @@ VALUE Event_Selector_EPoll_raise(int argc, VALUE *argv, VALUE self)
|
|
147
151
|
struct Event_Selector_EPoll *data = NULL;
|
148
152
|
TypedData_Get_Struct(self, struct Event_Selector_EPoll, &Event_Selector_EPoll_Type, data);
|
149
153
|
|
150
|
-
return
|
154
|
+
return Event_Selector_raise(&data->backend, argc, argv);
|
151
155
|
}
|
152
156
|
|
153
157
|
VALUE Event_Selector_EPoll_ready_p(VALUE self) {
|
@@ -550,6 +554,7 @@ void Init_Event_Selector_EPoll(VALUE Event_Selector) {
|
|
550
554
|
rb_define_alloc_func(Event_Selector_EPoll, Event_Selector_EPoll_allocate);
|
551
555
|
rb_define_method(Event_Selector_EPoll, "initialize", Event_Selector_EPoll_initialize, 1);
|
552
556
|
|
557
|
+
rb_define_method(Event_Selector_EPoll, "transfer", Event_Selector_EPoll_transfer, 0);
|
553
558
|
rb_define_method(Event_Selector_EPoll, "resume", Event_Selector_EPoll_resume, -1);
|
554
559
|
rb_define_method(Event_Selector_EPoll, "yield", Event_Selector_EPoll_yield, 0);
|
555
560
|
rb_define_method(Event_Selector_EPoll, "push", Event_Selector_EPoll_push, 1);
|
data/ext/event/selector/kqueue.c
CHANGED
@@ -112,6 +112,14 @@ VALUE Event_Selector_KQueue_close(VALUE self) {
|
|
112
112
|
return Qnil;
|
113
113
|
}
|
114
114
|
|
115
|
+
VALUE Event_Selector_KQueue_transfer(VALUE self)
|
116
|
+
{
|
117
|
+
struct Event_Selector_KQueue *data = NULL;
|
118
|
+
TypedData_Get_Struct(self, struct Event_Selector_KQueue, &Event_Selector_KQueue_Type, data);
|
119
|
+
|
120
|
+
return Event_Selector_fiber_transfer(data->backend.loop, 0, NULL);
|
121
|
+
}
|
122
|
+
|
115
123
|
VALUE Event_Selector_KQueue_resume(int argc, VALUE *argv, VALUE self)
|
116
124
|
{
|
117
125
|
struct Event_Selector_KQueue *data = NULL;
|
@@ -125,9 +133,7 @@ VALUE Event_Selector_KQueue_yield(VALUE self)
|
|
125
133
|
struct Event_Selector_KQueue *data = NULL;
|
126
134
|
TypedData_Get_Struct(self, struct Event_Selector_KQueue, &Event_Selector_KQueue_Type, data);
|
127
135
|
|
128
|
-
Event_Selector_yield(&data->backend);
|
129
|
-
|
130
|
-
return Qnil;
|
136
|
+
return Event_Selector_yield(&data->backend);
|
131
137
|
}
|
132
138
|
|
133
139
|
VALUE Event_Selector_KQueue_push(VALUE self, VALUE fiber)
|
@@ -145,7 +151,7 @@ VALUE Event_Selector_KQueue_raise(int argc, VALUE *argv, VALUE self)
|
|
145
151
|
struct Event_Selector_KQueue *data = NULL;
|
146
152
|
TypedData_Get_Struct(self, struct Event_Selector_KQueue, &Event_Selector_KQueue_Type, data);
|
147
153
|
|
148
|
-
return
|
154
|
+
return Event_Selector_raise(&data->backend, argc, argv);
|
149
155
|
}
|
150
156
|
|
151
157
|
VALUE Event_Selector_KQueue_ready_p(VALUE self) {
|
@@ -616,6 +622,7 @@ void Init_Event_Selector_KQueue(VALUE Event_Selector) {
|
|
616
622
|
rb_define_alloc_func(Event_Selector_KQueue, Event_Selector_KQueue_allocate);
|
617
623
|
rb_define_method(Event_Selector_KQueue, "initialize", Event_Selector_KQueue_initialize, 1);
|
618
624
|
|
625
|
+
rb_define_method(Event_Selector_KQueue, "transfer", Event_Selector_KQueue_transfer, 0);
|
619
626
|
rb_define_method(Event_Selector_KQueue, "resume", Event_Selector_KQueue_resume, -1);
|
620
627
|
rb_define_method(Event_Selector_KQueue, "yield", Event_Selector_KQueue_yield, 0);
|
621
628
|
rb_define_method(Event_Selector_KQueue, "push", Event_Selector_KQueue_push, 1);
|
@@ -26,14 +26,17 @@ static ID id_transfer, id_alive_p;
|
|
26
26
|
VALUE Event_Selector_fiber_transfer(VALUE fiber, int argc, VALUE *argv) {
|
27
27
|
// TODO Consider introducing something like `rb_fiber_scheduler_transfer(...)`.
|
28
28
|
#ifdef HAVE__RB_FIBER_TRANSFER
|
29
|
-
if (RTEST(
|
30
|
-
|
29
|
+
if (RTEST(rb_obj_is_fiber(fiber))) {
|
30
|
+
if (RTEST(rb_fiber_alive_p(fiber))) {
|
31
|
+
return rb_fiber_transfer(fiber, argc, argv);
|
32
|
+
}
|
33
|
+
|
34
|
+
return Qnil;
|
31
35
|
}
|
32
|
-
#
|
36
|
+
#endif
|
33
37
|
if (RTEST(rb_funcall(fiber, id_alive_p, 0))) {
|
34
38
|
return rb_funcallv(fiber, id_transfer, argc, argv);
|
35
39
|
}
|
36
|
-
#endif
|
37
40
|
|
38
41
|
return Qnil;
|
39
42
|
}
|
@@ -197,7 +200,7 @@ static VALUE wait_and_raise(VALUE _arguments) {
|
|
197
200
|
return Event_Selector_fiber_raise(fiber, argc, argv);
|
198
201
|
}
|
199
202
|
|
200
|
-
VALUE
|
203
|
+
VALUE Event_Selector_raise(struct Event_Selector *backend, int argc, VALUE *argv)
|
201
204
|
{
|
202
205
|
rb_check_arity(argc, 2, UNLIMITED_ARGUMENTS);
|
203
206
|
|
@@ -105,7 +105,7 @@ void Event_Selector_mark(struct Event_Selector *backend) {
|
|
105
105
|
}
|
106
106
|
|
107
107
|
VALUE Event_Selector_resume(struct Event_Selector *backend, int argc, VALUE *argv);
|
108
|
-
VALUE
|
108
|
+
VALUE Event_Selector_raise(struct Event_Selector *backend, int argc, VALUE *argv);
|
109
109
|
|
110
110
|
static inline
|
111
111
|
VALUE Event_Selector_yield(struct Event_Selector *backend)
|
data/ext/event/selector/uring.c
CHANGED
@@ -115,14 +115,20 @@ VALUE Event_Selector_URing_close(VALUE self) {
|
|
115
115
|
return Qnil;
|
116
116
|
}
|
117
117
|
|
118
|
-
VALUE
|
118
|
+
VALUE Event_Selector_URing_transfer(VALUE self)
|
119
119
|
{
|
120
120
|
struct Event_Selector_URing *data = NULL;
|
121
121
|
TypedData_Get_Struct(self, struct Event_Selector_URing, &Event_Selector_URing_Type, data);
|
122
122
|
|
123
|
-
|
123
|
+
return Event_Selector_fiber_transfer(data->backend.loop, 0, NULL);
|
124
|
+
}
|
125
|
+
|
126
|
+
VALUE Event_Selector_URing_resume(int argc, VALUE *argv, VALUE self)
|
127
|
+
{
|
128
|
+
struct Event_Selector_URing *data = NULL;
|
129
|
+
TypedData_Get_Struct(self, struct Event_Selector_URing, &Event_Selector_URing_Type, data);
|
124
130
|
|
125
|
-
return
|
131
|
+
return Event_Selector_resume(&data->backend, argc, argv);
|
126
132
|
}
|
127
133
|
|
128
134
|
VALUE Event_Selector_URing_yield(VALUE self)
|
@@ -130,9 +136,7 @@ VALUE Event_Selector_URing_yield(VALUE self)
|
|
130
136
|
struct Event_Selector_URing *data = NULL;
|
131
137
|
TypedData_Get_Struct(self, struct Event_Selector_URing, &Event_Selector_URing_Type, data);
|
132
138
|
|
133
|
-
Event_Selector_yield(&data->backend);
|
134
|
-
|
135
|
-
return Qnil;
|
139
|
+
return Event_Selector_yield(&data->backend);
|
136
140
|
}
|
137
141
|
|
138
142
|
VALUE Event_Selector_URing_push(VALUE self, VALUE fiber)
|
@@ -150,7 +154,7 @@ VALUE Event_Selector_URing_raise(int argc, VALUE *argv, VALUE self)
|
|
150
154
|
struct Event_Selector_URing *data = NULL;
|
151
155
|
TypedData_Get_Struct(self, struct Event_Selector_URing, &Event_Selector_URing_Type, data);
|
152
156
|
|
153
|
-
return
|
157
|
+
return Event_Selector_raise(&data->backend, argc, argv);
|
154
158
|
}
|
155
159
|
|
156
160
|
VALUE Event_Selector_URing_ready_p(VALUE self) {
|
@@ -615,6 +619,7 @@ void Init_Event_Selector_URing(VALUE Event_Selector) {
|
|
615
619
|
rb_define_alloc_func(Event_Selector_URing, Event_Selector_URing_allocate);
|
616
620
|
rb_define_method(Event_Selector_URing, "initialize", Event_Selector_URing_initialize, 1);
|
617
621
|
|
622
|
+
rb_define_method(Event_Selector_URing, "transfer", Event_Selector_URing_transfer, 0);
|
618
623
|
rb_define_method(Event_Selector_URing, "resume", Event_Selector_URing_resume, -1);
|
619
624
|
rb_define_method(Event_Selector_URing, "yield", Event_Selector_URing_yield, 0);
|
620
625
|
rb_define_method(Event_Selector_URing, "push", Event_Selector_URing_push, 1);
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require "event/version"
|
22
|
+
|
23
|
+
module Event
|
24
|
+
module Debug
|
25
|
+
class Selector
|
26
|
+
def initialize(selector)
|
27
|
+
@selector = selector
|
28
|
+
|
29
|
+
@readable = {}
|
30
|
+
@writable = {}
|
31
|
+
@priority = {}
|
32
|
+
end
|
33
|
+
|
34
|
+
def close
|
35
|
+
if @selector.nil?
|
36
|
+
raise "Selector already closed!"
|
37
|
+
end
|
38
|
+
|
39
|
+
@selector.close
|
40
|
+
@selector = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def transfer(fiber, *arguments)
|
44
|
+
@selector.transfer(fiber, *arguments)
|
45
|
+
end
|
46
|
+
|
47
|
+
def transfer(*arguments)
|
48
|
+
@selector.transfer(*arguments)
|
49
|
+
end
|
50
|
+
|
51
|
+
def resume(*arguments)
|
52
|
+
@selector.resume(*arguments)
|
53
|
+
end
|
54
|
+
|
55
|
+
def yield
|
56
|
+
@selector.yield
|
57
|
+
end
|
58
|
+
|
59
|
+
def push(fiber)
|
60
|
+
@selector.push(fiber)
|
61
|
+
end
|
62
|
+
|
63
|
+
def raise(fiber, *arguments)
|
64
|
+
@selector.raise(fiber, *arguments)
|
65
|
+
end
|
66
|
+
|
67
|
+
def ready?
|
68
|
+
@selector.ready?
|
69
|
+
end
|
70
|
+
|
71
|
+
def process_wait(*arguments)
|
72
|
+
@selector.process_wait(*arguments)
|
73
|
+
end
|
74
|
+
|
75
|
+
def io_wait(fiber, io, events)
|
76
|
+
register_readable(fiber, io, events)
|
77
|
+
end
|
78
|
+
|
79
|
+
def select(duration = nil)
|
80
|
+
@selector.select(duration)
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def register_readable(fiber, io, events)
|
86
|
+
if (events & READABLE) > 0
|
87
|
+
if @readable.key?(io)
|
88
|
+
raise "Cannot wait for #{io} to become readable from multiple fibers."
|
89
|
+
end
|
90
|
+
|
91
|
+
begin
|
92
|
+
@readable[io] = fiber
|
93
|
+
|
94
|
+
register_writable(fiber, io, events)
|
95
|
+
ensure
|
96
|
+
@readable.delete(io)
|
97
|
+
end
|
98
|
+
else
|
99
|
+
register_writable(fiber, io, events)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def register_writable(fiber, io, events)
|
104
|
+
if (events & WRITABLE) > 0
|
105
|
+
if @writable.key?(io)
|
106
|
+
raise "Cannot wait for #{io} to become writable from multiple fibers."
|
107
|
+
end
|
108
|
+
|
109
|
+
begin
|
110
|
+
@writable[io] = fiber
|
111
|
+
|
112
|
+
register_priority(fiber, io, events)
|
113
|
+
ensure
|
114
|
+
@writable.delete(io)
|
115
|
+
end
|
116
|
+
else
|
117
|
+
register_priority(fiber, io, events)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def register_priority(fiber, io, events)
|
122
|
+
if (events & PRIORITY) > 0
|
123
|
+
if @priority.key?(io)
|
124
|
+
raise "Cannot wait for #{io} to become priority from multiple fibers."
|
125
|
+
end
|
126
|
+
|
127
|
+
begin
|
128
|
+
@priority[io] = fiber
|
129
|
+
|
130
|
+
@selector.io_wait(fiber, io, events)
|
131
|
+
ensure
|
132
|
+
@priority.delete(io)
|
133
|
+
end
|
134
|
+
else
|
135
|
+
@selector.io_wait(fiber, io, events)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -50,6 +50,11 @@ module Event
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
# Transfer from the current fiber to the event loop.
|
54
|
+
def transfer
|
55
|
+
@loop.transfer
|
56
|
+
end
|
57
|
+
|
53
58
|
# Transfer from the current fiber to the specified fiber. Put the current fiber into the ready list.
|
54
59
|
def resume(fiber, *arguments)
|
55
60
|
queue = Queue.new(Fiber.current)
|
data/lib/event/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: event
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -86,7 +86,7 @@ files:
|
|
86
86
|
- ext/event/selector/uring.c
|
87
87
|
- ext/event/selector/uring.h
|
88
88
|
- lib/event.rb
|
89
|
-
- lib/event/debug.rb
|
89
|
+
- lib/event/debug/selector.rb
|
90
90
|
- lib/event/selector.rb
|
91
91
|
- lib/event/selector/select.rb
|
92
92
|
- lib/event/version.rb
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.3.0.dev
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: An event loop.
|
data/lib/event/debug.rb
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
# Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require "event/version"
|
22
|
-
|
23
|
-
module Event
|
24
|
-
class Debug
|
25
|
-
def initialize(selector)
|
26
|
-
@selector = selector
|
27
|
-
|
28
|
-
@readable = {}
|
29
|
-
@writable = {}
|
30
|
-
@priority = {}
|
31
|
-
end
|
32
|
-
|
33
|
-
def close
|
34
|
-
if @selector.nil?
|
35
|
-
raise "Selector already closed!"
|
36
|
-
end
|
37
|
-
|
38
|
-
@selector.close
|
39
|
-
@selector = nil
|
40
|
-
end
|
41
|
-
|
42
|
-
def transfer(fiber, *arguments)
|
43
|
-
@selector.transfer(fiber, *arguments)
|
44
|
-
end
|
45
|
-
|
46
|
-
def yield
|
47
|
-
@selector.yield
|
48
|
-
end
|
49
|
-
|
50
|
-
def push(fiber)
|
51
|
-
@selector.push(fiber)
|
52
|
-
end
|
53
|
-
|
54
|
-
def raise(fiber, *arguments)
|
55
|
-
@selector.raise(fiber, *arguments)
|
56
|
-
end
|
57
|
-
|
58
|
-
def ready?
|
59
|
-
@selector.ready?
|
60
|
-
end
|
61
|
-
|
62
|
-
def io_wait(fiber, io, events)
|
63
|
-
register_readable(fiber, io, events)
|
64
|
-
end
|
65
|
-
|
66
|
-
def select(duration = nil)
|
67
|
-
@selector.select(duration)
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
def register_readable(fiber, io, events)
|
73
|
-
if (events & READABLE) > 0
|
74
|
-
if @readable.key?(io)
|
75
|
-
raise "Cannot wait for #{io} to become readable from multiple fibers."
|
76
|
-
end
|
77
|
-
|
78
|
-
begin
|
79
|
-
@readable[io] = fiber
|
80
|
-
|
81
|
-
register_writable(fiber, io, events)
|
82
|
-
ensure
|
83
|
-
@readable.delete(io)
|
84
|
-
end
|
85
|
-
else
|
86
|
-
register_writable(fiber, io, events)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def register_writable(fiber, io, events)
|
91
|
-
if (events & WRITABLE) > 0
|
92
|
-
if @writable.key?(io)
|
93
|
-
raise "Cannot wait for #{io} to become writable from multiple fibers."
|
94
|
-
end
|
95
|
-
|
96
|
-
begin
|
97
|
-
@writable[io] = fiber
|
98
|
-
|
99
|
-
register_priority(fiber, io, events)
|
100
|
-
ensure
|
101
|
-
@writable.delete(io)
|
102
|
-
end
|
103
|
-
else
|
104
|
-
register_priority(fiber, io, events)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def register_priority(fiber, io, events)
|
109
|
-
if (events & PRIORITY) > 0
|
110
|
-
if @priority.key?(io)
|
111
|
-
raise "Cannot wait for #{io} to become priority from multiple fibers."
|
112
|
-
end
|
113
|
-
|
114
|
-
begin
|
115
|
-
@priority[io] = fiber
|
116
|
-
|
117
|
-
@selector.io_wait(fiber, io, events)
|
118
|
-
ensure
|
119
|
-
@priority.delete(io)
|
120
|
-
end
|
121
|
-
else
|
122
|
-
@selector.io_wait(fiber, io, events)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|