io-event 1.6.5 → 1.9.0
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
- checksums.yaml.gz.sig +0 -0
- data/ext/extconf.rb +26 -13
- data/ext/io/event/{selector/array.h → array.h} +74 -18
- data/ext/io/event/event.c +9 -26
- data/ext/io/event/event.h +2 -19
- data/ext/io/event/fiber.c +63 -0
- data/ext/io/event/fiber.h +23 -0
- data/ext/io/event/interrupt.c +19 -27
- data/ext/io/event/interrupt.h +2 -19
- data/ext/io/event/{selector/list.h → list.h} +20 -2
- data/ext/io/event/profiler.c +505 -0
- data/ext/io/event/profiler.h +8 -0
- data/ext/io/event/selector/epoll.c +41 -43
- data/ext/io/event/selector/epoll.h +2 -19
- data/ext/io/event/selector/kqueue.c +34 -41
- data/ext/io/event/selector/kqueue.h +2 -19
- data/ext/io/event/selector/pidfd.c +2 -19
- data/ext/io/event/selector/selector.c +65 -102
- data/ext/io/event/selector/selector.h +51 -46
- data/ext/io/event/selector/uring.c +130 -47
- data/ext/io/event/selector/uring.h +2 -19
- data/ext/io/event/time.c +35 -0
- data/ext/io/event/time.h +17 -0
- data/lib/io/event/debug/selector.rb +44 -4
- data/lib/io/event/interrupt.rb +2 -2
- data/lib/io/event/native.rb +11 -0
- data/lib/io/event/priority_heap.rb +13 -14
- data/lib/io/event/profiler.rb +18 -0
- data/lib/io/event/selector/nonblock.rb +6 -2
- data/lib/io/event/selector/select.rb +25 -5
- data/lib/io/event/selector.rb +15 -5
- data/lib/io/event/support.rb +23 -2
- data/lib/io/event/timers.rb +42 -4
- data/lib/io/event/version.rb +4 -2
- data/lib/io/event.rb +5 -11
- data/license.md +4 -1
- data/readme.md +22 -4
- data/releases.md +57 -0
- data.tar.gz.sig +0 -0
- metadata +20 -11
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7265f0fb5702ae05b5d928a8efb9e5a5e877f62afc5c93d23fec26f8a3dd1437
|
|
4
|
+
data.tar.gz: 8ba9b4b0d4e95be1401b8952cccac1a9bcc93c7a0a40e843aea60f0015c791ad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b4346972aa2dbe00b560e2a1e2cce32a50e9acafaa0c9253f12791c183f35bea8e3cffba93eb93147b4d975ef05edeffef84e0ed8bf29934fb39c70ea1320c6f
|
|
7
|
+
data.tar.gz: 41b6b53ca30bd0934c702c1ff0899e0e8a6bd3bc97a95f455b0d6cf0be28ff690b69575c44d92a784226edea27958cd43c486e9d907989859e298d602536078b
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/ext/extconf.rb
CHANGED
|
@@ -2,46 +2,51 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
# Released under the MIT License.
|
|
5
|
-
# Copyright, 2021-
|
|
5
|
+
# Copyright, 2021-2025, by Samuel Williams.
|
|
6
6
|
# Copyright, 2023, by Math Ieu.
|
|
7
7
|
|
|
8
8
|
return if RUBY_DESCRIPTION =~ /jruby/
|
|
9
9
|
|
|
10
|
-
require
|
|
10
|
+
require "mkmf"
|
|
11
11
|
|
|
12
12
|
gem_name = File.basename(__dir__)
|
|
13
|
-
extension_name =
|
|
13
|
+
extension_name = "IO_Event"
|
|
14
14
|
|
|
15
15
|
# dir_config(extension_name)
|
|
16
16
|
|
|
17
17
|
$CFLAGS << " -Wall -Wno-unknown-pragmas -std=c99"
|
|
18
18
|
|
|
19
|
-
if ENV.key?(
|
|
19
|
+
if ENV.key?("RUBY_DEBUG")
|
|
20
|
+
$stderr.puts "Enabling debug mode..."
|
|
21
|
+
|
|
20
22
|
$CFLAGS << " -DRUBY_DEBUG -O0"
|
|
21
23
|
end
|
|
22
24
|
|
|
23
|
-
$srcs = ["io/event/event.c", "io/event/selector/selector.c"]
|
|
25
|
+
$srcs = ["io/event/event.c", "io/event/time.c", "io/event/fiber.c", "io/event/profiler.c", "io/event/selector/selector.c"]
|
|
24
26
|
$VPATH << "$(srcdir)/io/event"
|
|
25
27
|
$VPATH << "$(srcdir)/io/event/selector"
|
|
26
28
|
|
|
27
|
-
have_func(
|
|
28
|
-
have_func(
|
|
29
|
+
have_func("rb_ext_ractor_safe")
|
|
30
|
+
have_func("&rb_fiber_transfer")
|
|
29
31
|
|
|
30
|
-
if have_library(
|
|
32
|
+
if have_library("uring") and have_header("liburing.h")
|
|
33
|
+
# We might want to consider using this in the future:
|
|
34
|
+
# have_func("io_uring_submit_and_wait_timeout", "liburing.h")
|
|
35
|
+
|
|
31
36
|
$srcs << "io/event/selector/uring.c"
|
|
32
37
|
end
|
|
33
38
|
|
|
34
|
-
if have_header(
|
|
39
|
+
if have_header("sys/epoll.h")
|
|
35
40
|
$srcs << "io/event/selector/epoll.c"
|
|
36
41
|
end
|
|
37
42
|
|
|
38
|
-
if have_header(
|
|
43
|
+
if have_header("sys/event.h")
|
|
39
44
|
$srcs << "io/event/selector/kqueue.c"
|
|
40
45
|
end
|
|
41
46
|
|
|
42
|
-
have_header(
|
|
47
|
+
have_header("sys/wait.h")
|
|
43
48
|
|
|
44
|
-
have_header(
|
|
49
|
+
have_header("sys/eventfd.h")
|
|
45
50
|
$srcs << "io/event/interrupt.c"
|
|
46
51
|
|
|
47
52
|
have_func("rb_io_descriptor")
|
|
@@ -50,7 +55,15 @@ have_func("rb_fiber_current")
|
|
|
50
55
|
have_func("&rb_fiber_raise")
|
|
51
56
|
have_func("epoll_pwait2")
|
|
52
57
|
|
|
53
|
-
have_header(
|
|
58
|
+
have_header("ruby/io/buffer.h")
|
|
59
|
+
|
|
60
|
+
if ENV.key?("RUBY_SANITIZE")
|
|
61
|
+
$stderr.puts "Enabling sanitizers..."
|
|
62
|
+
|
|
63
|
+
# Add address and undefined behaviour sanitizers:
|
|
64
|
+
$CFLAGS << " -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer"
|
|
65
|
+
$LDFLAGS << " -fsanitize=address -fsanitize=undefined"
|
|
66
|
+
end
|
|
54
67
|
|
|
55
68
|
create_header
|
|
56
69
|
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
#include <errno.h>
|
|
9
9
|
#include <assert.h>
|
|
10
10
|
|
|
11
|
+
static const size_t IO_EVENT_ARRAY_MAXIMUM_COUNT = SIZE_MAX / sizeof(void*);
|
|
12
|
+
static const size_t IO_EVENT_ARRAY_DEFAULT_COUNT = 128;
|
|
13
|
+
|
|
11
14
|
struct IO_Event_Array {
|
|
12
15
|
// The array of pointers to elements:
|
|
13
16
|
void **base;
|
|
@@ -25,18 +28,27 @@ struct IO_Event_Array {
|
|
|
25
28
|
void (*element_free)(void*);
|
|
26
29
|
};
|
|
27
30
|
|
|
28
|
-
inline static
|
|
31
|
+
inline static int IO_Event_Array_initialize(struct IO_Event_Array *array, size_t count, size_t element_size)
|
|
29
32
|
{
|
|
33
|
+
array->limit = 0;
|
|
34
|
+
array->element_size = element_size;
|
|
35
|
+
|
|
30
36
|
if (count) {
|
|
31
37
|
array->base = (void**)calloc(count, sizeof(void*));
|
|
38
|
+
|
|
39
|
+
if (array->base == NULL) {
|
|
40
|
+
return -1;
|
|
41
|
+
}
|
|
42
|
+
|
|
32
43
|
array->count = count;
|
|
44
|
+
|
|
45
|
+
return 1;
|
|
33
46
|
} else {
|
|
34
47
|
array->base = NULL;
|
|
35
48
|
array->count = 0;
|
|
49
|
+
|
|
50
|
+
return 0;
|
|
36
51
|
}
|
|
37
|
-
|
|
38
|
-
array->limit = 0;
|
|
39
|
-
array->element_size = element_size;
|
|
40
52
|
}
|
|
41
53
|
|
|
42
54
|
inline static size_t IO_Event_Array_memory_size(const struct IO_Event_Array *array)
|
|
@@ -47,31 +59,51 @@ inline static size_t IO_Event_Array_memory_size(const struct IO_Event_Array *arr
|
|
|
47
59
|
|
|
48
60
|
inline static void IO_Event_Array_free(struct IO_Event_Array *array)
|
|
49
61
|
{
|
|
50
|
-
|
|
51
|
-
void
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
if (array->base) {
|
|
63
|
+
void **base = array->base;
|
|
64
|
+
size_t limit = array->limit;
|
|
65
|
+
|
|
66
|
+
array->base = NULL;
|
|
67
|
+
array->count = 0;
|
|
68
|
+
array->limit = 0;
|
|
69
|
+
|
|
70
|
+
for (size_t i = 0; i < limit; i += 1) {
|
|
71
|
+
void *element = base[i];
|
|
72
|
+
if (element) {
|
|
73
|
+
array->element_free(element);
|
|
74
|
+
|
|
75
|
+
free(element);
|
|
76
|
+
}
|
|
55
77
|
}
|
|
78
|
+
|
|
79
|
+
free(base);
|
|
56
80
|
}
|
|
57
|
-
|
|
58
|
-
if (array->base)
|
|
59
|
-
free(array->base);
|
|
60
|
-
|
|
61
|
-
array->base = NULL;
|
|
62
|
-
array->count = 0;
|
|
63
|
-
array->limit = 0;
|
|
64
81
|
}
|
|
65
82
|
|
|
66
83
|
inline static int IO_Event_Array_resize(struct IO_Event_Array *array, size_t count)
|
|
67
84
|
{
|
|
68
85
|
if (count <= array->count) {
|
|
86
|
+
// Already big enough:
|
|
69
87
|
return 0;
|
|
70
88
|
}
|
|
71
89
|
|
|
72
|
-
|
|
90
|
+
if (count > IO_EVENT_ARRAY_MAXIMUM_COUNT) {
|
|
91
|
+
errno = ENOMEM;
|
|
92
|
+
return -1;
|
|
93
|
+
}
|
|
94
|
+
|
|
73
95
|
size_t new_count = array->count;
|
|
74
|
-
|
|
96
|
+
|
|
97
|
+
// If the array is empty, we need to set the initial size:
|
|
98
|
+
if (new_count == 0) new_count = IO_EVENT_ARRAY_DEFAULT_COUNT;
|
|
99
|
+
else while (new_count < count) {
|
|
100
|
+
// Ensure we don't overflow:
|
|
101
|
+
if (new_count > (IO_EVENT_ARRAY_MAXIMUM_COUNT / 2)) {
|
|
102
|
+
new_count = IO_EVENT_ARRAY_MAXIMUM_COUNT;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Compute the next multiple (ideally a power of 2):
|
|
75
107
|
new_count *= 2;
|
|
76
108
|
}
|
|
77
109
|
|
|
@@ -87,6 +119,7 @@ inline static int IO_Event_Array_resize(struct IO_Event_Array *array, size_t cou
|
|
|
87
119
|
array->base = (void**)new_base;
|
|
88
120
|
array->count = new_count;
|
|
89
121
|
|
|
122
|
+
// Resizing sucessful:
|
|
90
123
|
return 1;
|
|
91
124
|
}
|
|
92
125
|
|
|
@@ -107,6 +140,7 @@ inline static void* IO_Event_Array_lookup(struct IO_Event_Array *array, size_t i
|
|
|
107
140
|
// Allocate the element if it doesn't exist:
|
|
108
141
|
if (*element == NULL) {
|
|
109
142
|
*element = malloc(array->element_size);
|
|
143
|
+
assert(*element);
|
|
110
144
|
|
|
111
145
|
if (array->element_initialize) {
|
|
112
146
|
array->element_initialize(*element);
|
|
@@ -119,6 +153,28 @@ inline static void* IO_Event_Array_lookup(struct IO_Event_Array *array, size_t i
|
|
|
119
153
|
return *element;
|
|
120
154
|
}
|
|
121
155
|
|
|
156
|
+
inline static void* IO_Event_Array_last(struct IO_Event_Array *array)
|
|
157
|
+
{
|
|
158
|
+
if (array->limit == 0) return NULL;
|
|
159
|
+
else return array->base[array->limit - 1];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
inline static void IO_Event_Array_truncate(struct IO_Event_Array *array, size_t limit)
|
|
163
|
+
{
|
|
164
|
+
if (limit < array->limit) {
|
|
165
|
+
for (size_t i = limit; i < array->limit; i += 1) {
|
|
166
|
+
void **element = array->base + i;
|
|
167
|
+
if (*element) {
|
|
168
|
+
array->element_free(*element);
|
|
169
|
+
free(*element);
|
|
170
|
+
*element = NULL;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
array->limit = limit;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
122
178
|
// Push a new element onto the end of the array.
|
|
123
179
|
inline static void* IO_Event_Array_push(struct IO_Event_Array *array)
|
|
124
180
|
{
|
data/ext/io/event/event.c
CHANGED
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
//
|
|
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.
|
|
1
|
+
// Released under the MIT License.
|
|
2
|
+
// Copyright, 2021-2025, by Samuel Williams.
|
|
20
3
|
|
|
21
4
|
#include "event.h"
|
|
5
|
+
#include "fiber.h"
|
|
6
|
+
#include "profiler.h"
|
|
22
7
|
#include "selector/selector.h"
|
|
23
|
-
|
|
24
|
-
VALUE IO_Event = Qnil;
|
|
25
|
-
VALUE IO_Event_Selector = Qnil;
|
|
8
|
+
#include <complex.h>
|
|
26
9
|
|
|
27
10
|
void Init_IO_Event(void)
|
|
28
11
|
{
|
|
@@ -30,12 +13,12 @@ void Init_IO_Event(void)
|
|
|
30
13
|
rb_ext_ractor_safe(true);
|
|
31
14
|
#endif
|
|
32
15
|
|
|
33
|
-
IO_Event = rb_define_module_under(rb_cIO, "Event");
|
|
34
|
-
rb_gc_register_mark_object(IO_Event);
|
|
16
|
+
VALUE IO_Event = rb_define_module_under(rb_cIO, "Event");
|
|
35
17
|
|
|
36
|
-
|
|
37
|
-
|
|
18
|
+
Init_IO_Event_Fiber(IO_Event);
|
|
19
|
+
Init_IO_Event_Profiler(IO_Event);
|
|
38
20
|
|
|
21
|
+
VALUE IO_Event_Selector = rb_define_module_under(IO_Event, "Selector");
|
|
39
22
|
Init_IO_Event_Selector(IO_Event_Selector);
|
|
40
23
|
|
|
41
24
|
#ifdef IO_EVENT_SELECTOR_URING
|
data/ext/io/event/event.h
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
//
|
|
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.
|
|
1
|
+
// Released under the MIT License.
|
|
2
|
+
// Copyright, 2021-2025, by Samuel Williams.
|
|
20
3
|
|
|
21
4
|
#pragma once
|
|
22
5
|
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Released under the MIT License.
|
|
2
|
+
// Copyright, 2025, by Samuel Williams.
|
|
3
|
+
|
|
4
|
+
#include "fiber.h"
|
|
5
|
+
|
|
6
|
+
static ID id_transfer, id_alive_p;
|
|
7
|
+
|
|
8
|
+
VALUE IO_Event_Fiber_transfer(VALUE fiber, int argc, VALUE *argv) {
|
|
9
|
+
// TODO Consider introducing something like `rb_fiber_scheduler_transfer(...)`.
|
|
10
|
+
#ifdef HAVE__RB_FIBER_TRANSFER
|
|
11
|
+
if (RTEST(rb_obj_is_fiber(fiber))) {
|
|
12
|
+
if (RTEST(rb_fiber_alive_p(fiber))) {
|
|
13
|
+
return rb_fiber_transfer(fiber, argc, argv);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// If it's a fiber, but dead, we are done.
|
|
17
|
+
return Qnil;
|
|
18
|
+
}
|
|
19
|
+
#endif
|
|
20
|
+
if (RTEST(rb_funcall(fiber, id_alive_p, 0))) {
|
|
21
|
+
return rb_funcallv(fiber, id_transfer, argc, argv);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return Qnil;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
#ifndef HAVE__RB_FIBER_RAISE
|
|
28
|
+
static ID id_raise;
|
|
29
|
+
|
|
30
|
+
VALUE IO_Event_Fiber_raise(VALUE fiber, int argc, VALUE *argv) {
|
|
31
|
+
return rb_funcallv(fiber, id_raise, argc, argv);
|
|
32
|
+
}
|
|
33
|
+
#endif
|
|
34
|
+
|
|
35
|
+
#ifndef HAVE_RB_FIBER_CURRENT
|
|
36
|
+
static ID id_current;
|
|
37
|
+
|
|
38
|
+
static VALUE IO_Event_Fiber_current(void) {
|
|
39
|
+
return rb_funcall(rb_cFiber, id_current, 0);
|
|
40
|
+
}
|
|
41
|
+
#endif
|
|
42
|
+
|
|
43
|
+
// There is no public interface for this... yet.
|
|
44
|
+
static ID id_blocking_p;
|
|
45
|
+
|
|
46
|
+
int IO_Event_Fiber_blocking(VALUE fiber) {
|
|
47
|
+
return RTEST(rb_funcall(fiber, id_blocking_p, 0));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
void Init_IO_Event_Fiber(VALUE IO_Event) {
|
|
51
|
+
id_transfer = rb_intern("transfer");
|
|
52
|
+
id_alive_p = rb_intern("alive?");
|
|
53
|
+
|
|
54
|
+
#ifndef HAVE__RB_FIBER_RAISE
|
|
55
|
+
id_raise = rb_intern("raise");
|
|
56
|
+
#endif
|
|
57
|
+
|
|
58
|
+
#ifndef HAVE_RB_FIBER_CURRENT
|
|
59
|
+
id_current = rb_intern("current");
|
|
60
|
+
#endif
|
|
61
|
+
|
|
62
|
+
id_blocking_p = rb_intern("blocking?");
|
|
63
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Released under the MIT License.
|
|
2
|
+
// Copyright, 2025, by Samuel Williams.
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#include <ruby.h>
|
|
7
|
+
|
|
8
|
+
VALUE IO_Event_Fiber_transfer(VALUE fiber, int argc, VALUE *argv);
|
|
9
|
+
|
|
10
|
+
#ifdef HAVE__RB_FIBER_RAISE
|
|
11
|
+
#define IO_Event_Fiber_raise(fiber, argc, argv) rb_fiber_raise(fiber, argc, argv)
|
|
12
|
+
#else
|
|
13
|
+
VALUE IO_Event_Fiber_raise(VALUE fiber, int argc, VALUE *argv);
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
#ifdef HAVE_RB_FIBER_CURRENT
|
|
17
|
+
#define IO_Event_Fiber_current() rb_fiber_current()
|
|
18
|
+
#else
|
|
19
|
+
VALUE IO_Event_Fiber_current(void);
|
|
20
|
+
#endif
|
|
21
|
+
|
|
22
|
+
int IO_Event_Fiber_blocking(VALUE fiber);
|
|
23
|
+
void Init_IO_Event_Fiber(VALUE IO_Event);
|
data/ext/io/event/interrupt.c
CHANGED
|
@@ -1,30 +1,18 @@
|
|
|
1
|
-
//
|
|
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
|
-
// static const int DEBUG = 0;
|
|
1
|
+
// Released under the MIT License.
|
|
2
|
+
// Copyright, 2021-2025, by Samuel Williams.
|
|
22
3
|
|
|
23
4
|
#include "interrupt.h"
|
|
24
5
|
#include <unistd.h>
|
|
25
6
|
|
|
26
7
|
#include "selector/selector.h"
|
|
27
8
|
|
|
9
|
+
#ifdef HAVE_RUBY_WIN32_H
|
|
10
|
+
#include <ruby/win32.h>
|
|
11
|
+
#if !defined(HAVE_PIPE) && !defined(pipe)
|
|
12
|
+
#define pipe(p) rb_w32_pipe(p)
|
|
13
|
+
#endif
|
|
14
|
+
#endif
|
|
15
|
+
|
|
28
16
|
#ifdef HAVE_SYS_EVENTFD_H
|
|
29
17
|
#include <sys/eventfd.h>
|
|
30
18
|
|
|
@@ -88,9 +76,11 @@ void IO_Event_Interrupt_signal(struct IO_Event_Interrupt *interrupt)
|
|
|
88
76
|
ssize_t result = write(interrupt->descriptor[1], ".", 1);
|
|
89
77
|
|
|
90
78
|
if (result == -1) {
|
|
91
|
-
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
|
92
|
-
|
|
93
|
-
|
|
79
|
+
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
|
80
|
+
// If we can't write to the pipe, it means the other end is full. In that case, we can be sure that the other end has already been woken up or is about to be woken up.
|
|
81
|
+
} else {
|
|
82
|
+
rb_sys_fail("IO_Event_Interrupt_signal:write");
|
|
83
|
+
}
|
|
94
84
|
}
|
|
95
85
|
}
|
|
96
86
|
|
|
@@ -100,9 +90,11 @@ void IO_Event_Interrupt_clear(struct IO_Event_Interrupt *interrupt)
|
|
|
100
90
|
ssize_t result = read(interrupt->descriptor[0], buffer, sizeof(buffer));
|
|
101
91
|
|
|
102
92
|
if (result == -1) {
|
|
103
|
-
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
|
104
|
-
|
|
105
|
-
|
|
93
|
+
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
|
94
|
+
// If we can't read from the pipe, it means the other end is empty. In that case, we can be sure that the other end is already clear.
|
|
95
|
+
} else {
|
|
96
|
+
rb_sys_fail("IO_Event_Interrupt_clear:read");
|
|
97
|
+
}
|
|
106
98
|
}
|
|
107
99
|
}
|
|
108
100
|
#endif
|
data/ext/io/event/interrupt.h
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
//
|
|
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.
|
|
1
|
+
// Released under the MIT License.
|
|
2
|
+
// Copyright, 2021-2025, by Samuel Williams.
|
|
20
3
|
|
|
21
4
|
#pragma once
|
|
22
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Released under the MIT License.
|
|
2
|
-
// Copyright, 2023, by Samuel Williams.
|
|
2
|
+
// Copyright, 2023-2025, by Samuel Williams.
|
|
3
3
|
|
|
4
4
|
#include <ruby.h>
|
|
5
5
|
#include <stdio.h>
|
|
@@ -38,6 +38,7 @@ inline static void IO_Event_List_append(struct IO_Event_List *list, struct IO_Ev
|
|
|
38
38
|
head->tail = node;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
// Prepend an item to the beginning of the list.
|
|
41
42
|
inline static void IO_Event_List_prepend(struct IO_Event_List *list, struct IO_Event_List *node)
|
|
42
43
|
{
|
|
43
44
|
assert(node->head == NULL);
|
|
@@ -64,6 +65,7 @@ inline static void IO_Event_List_pop(struct IO_Event_List *node)
|
|
|
64
65
|
node->head = node->tail = NULL;
|
|
65
66
|
}
|
|
66
67
|
|
|
68
|
+
// Remove an item from the list, if it is in a list.
|
|
67
69
|
inline static void IO_Event_List_free(struct IO_Event_List *node)
|
|
68
70
|
{
|
|
69
71
|
if (node->head && node->tail) {
|
|
@@ -71,11 +73,27 @@ inline static void IO_Event_List_free(struct IO_Event_List *node)
|
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
|
|
74
|
-
|
|
76
|
+
// Calculate the memory size of the list nodes.
|
|
77
|
+
inline static size_t IO_Event_List_memory_size(const struct IO_Event_List *list)
|
|
78
|
+
{
|
|
79
|
+
size_t memsize = 0;
|
|
80
|
+
|
|
81
|
+
const struct IO_Event_List *node = list->tail;
|
|
82
|
+
while (node != list) {
|
|
83
|
+
memsize += sizeof(struct IO_Event_List);
|
|
84
|
+
node = node->tail;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return memsize;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Return true if the list is empty.
|
|
91
|
+
inline static int IO_Event_List_empty(const struct IO_Event_List *list)
|
|
75
92
|
{
|
|
76
93
|
return list->head == list->tail;
|
|
77
94
|
}
|
|
78
95
|
|
|
96
|
+
// Enumerate all items in the list, assuming the list will not be modified during iteration.
|
|
79
97
|
inline static void IO_Event_List_immutable_each(struct IO_Event_List *list, void (*callback)(struct IO_Event_List *node))
|
|
80
98
|
{
|
|
81
99
|
struct IO_Event_List *node = list->tail;
|