io-event 0.2.0 → 0.2.4
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/ext/IO_Event.bundle +0 -0
- data/ext/Makefile +25 -24
- data/ext/event.o +0 -0
- data/ext/extconf.h +4 -0
- data/ext/interrupt.o +0 -0
- data/ext/io/event/interrupt.c +34 -10
- data/ext/io/event/interrupt.h +4 -0
- data/ext/io/event/selector/epoll.c +32 -17
- data/ext/io/event/selector/kqueue.c +16 -4
- data/ext/io/event/selector/selector.h +2 -0
- data/ext/io/event/selector/uring.c +19 -14
- data/ext/kqueue.o +0 -0
- data/ext/mkmf.log +27 -45
- data/ext/selector.o +0 -0
- data/lib/io/event/debug/selector.rb +3 -3
- data/lib/io/event/interrupt.rb +1 -3
- data/lib/io/event/selector/select.rb +15 -10
- data/lib/io/event/selector.rb +0 -5
- data/lib/io/event/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4082e35d4449813886e1f44ffd9f6825a48b69c5207b1bb7685d6fd920a6e7a0
|
4
|
+
data.tar.gz: c312e74c8e0c458e86215110cb5cd21f431709c4a120db4c37c670bb227528d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 795d6a27a0d074d7045c727ae241ea3c5fb3f14bed0e9541ee7d29f92f474896eb57a12b5e09838725e120b46ee084f3ebe4373a9f30915b46551a586d67d0a5
|
7
|
+
data.tar.gz: 5eb59147bd4c6f66678e962e3df79b876668fb3c6ac4d60aa27859080c7e6cf6c0eb3f25a4200552f0e829501337e5465f9994aa92c662b6a81afdacbb622990
|
data/ext/IO_Event.bundle
CHANGED
Binary file
|
data/ext/Makefile
CHANGED
@@ -3,6 +3,7 @@ SHELL = /bin/sh
|
|
3
3
|
|
4
4
|
# V=0 quiet, V=1 verbose. other values don't work.
|
5
5
|
V = 0
|
6
|
+
V0 = $(V:0=)
|
6
7
|
Q1 = $(V:1=)
|
7
8
|
Q = $(Q1:0=@)
|
8
9
|
ECHO1 = $(V:1=@ :)
|
@@ -12,12 +13,12 @@ NULLCMD = :
|
|
12
13
|
#### Start of system configuration section. ####
|
13
14
|
|
14
15
|
srcdir = .
|
15
|
-
topdir = /Users/samuel/.rubies/ruby-
|
16
|
+
topdir = /Users/samuel/.rubies/ruby-head/include/ruby-3.1.0
|
16
17
|
hdrdir = $(topdir)
|
17
|
-
arch_hdrdir = /Users/samuel/.rubies/ruby-
|
18
|
+
arch_hdrdir = /Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21
|
18
19
|
PATH_SEPARATOR = :
|
19
20
|
VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby:$(srcdir)/io/event:$(srcdir)/io/event/selector
|
20
|
-
prefix = $(DESTDIR)/Users/samuel/.rubies/ruby-
|
21
|
+
prefix = $(DESTDIR)/Users/samuel/.rubies/ruby-head
|
21
22
|
rubysitearchprefix = $(rubylibprefix)/$(sitearch)
|
22
23
|
rubyarchprefix = $(rubylibprefix)/$(arch)
|
23
24
|
rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
|
@@ -50,8 +51,8 @@ dvidir = $(docdir)
|
|
50
51
|
htmldir = $(docdir)
|
51
52
|
infodir = $(datarootdir)/info
|
52
53
|
docdir = $(datarootdir)/doc/$(PACKAGE)
|
53
|
-
oldincludedir = $(
|
54
|
-
includedir = $(prefix)/include
|
54
|
+
oldincludedir = $(DESTDIR)/usr/include
|
55
|
+
includedir = $(SDKROOT)$(prefix)/include
|
55
56
|
runstatedir = $(localstatedir)/run
|
56
57
|
localstatedir = $(prefix)/var
|
57
58
|
sharedstatedir = $(prefix)/com
|
@@ -65,33 +66,33 @@ archdir = $(rubyarchdir)
|
|
65
66
|
|
66
67
|
|
67
68
|
CC_WRAPPER =
|
68
|
-
CC = clang
|
69
|
-
CXX = clang++
|
69
|
+
CC = clang
|
70
|
+
CXX = clang++
|
70
71
|
LIBRUBY = $(LIBRUBY_A)
|
71
72
|
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
72
73
|
LIBRUBYARG_SHARED =
|
73
|
-
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -framework
|
74
|
+
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -framework CoreFoundation $(MAINLIBS)
|
74
75
|
empty =
|
75
76
|
OUTFLAG = -o $(empty)
|
76
77
|
COUTFLAG = -o $(empty)
|
77
78
|
CSRCFLAG = $(empty)
|
78
79
|
|
79
80
|
RUBY_EXTCONF_H = extconf.h
|
80
|
-
cflags = $(optflags) $(debugflags) $(warnflags)
|
81
|
+
cflags = -fdeclspec $(optflags) $(debugflags) $(warnflags)
|
81
82
|
cxxflags =
|
82
|
-
optflags = -O3
|
83
|
+
optflags = -O3 -fno-fast-math
|
83
84
|
debugflags = -ggdb3
|
84
|
-
warnflags = -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens
|
85
|
+
warnflags = -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef
|
85
86
|
cppflags =
|
86
87
|
CCDLFLAGS = -fno-common
|
87
|
-
CFLAGS = $(CCDLFLAGS) $(cflags)
|
88
|
+
CFLAGS = $(CCDLFLAGS) $(cflags) -pipe -Wall $(ARCH_FLAG)
|
88
89
|
INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
|
89
90
|
DEFS =
|
90
|
-
CPPFLAGS = -DRUBY_EXTCONF_H=\"$(RUBY_EXTCONF_H)\"
|
91
|
-
CXXFLAGS = $(CCDLFLAGS)
|
92
|
-
ldflags = -L. -fstack-protector-strong
|
93
|
-
dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress
|
94
|
-
ARCH_FLAG =
|
91
|
+
CPPFLAGS = -DRUBY_EXTCONF_H=\"$(RUBY_EXTCONF_H)\" -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT $(DEFS) $(cppflags)
|
92
|
+
CXXFLAGS = $(CCDLFLAGS) -fdeclspec $(ARCH_FLAG)
|
93
|
+
ldflags = -L. -fstack-protector-strong
|
94
|
+
dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress
|
95
|
+
ARCH_FLAG =
|
95
96
|
DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
|
96
97
|
LDSHARED = $(CC) -dynamic -bundle
|
97
98
|
LDSHAREDXX = $(CXX) -dynamic -bundle
|
@@ -99,7 +100,7 @@ AR = ar
|
|
99
100
|
EXEEXT =
|
100
101
|
|
101
102
|
RUBY_INSTALL_NAME = $(RUBY_BASE_NAME)
|
102
|
-
RUBY_SO_NAME = ruby.3.
|
103
|
+
RUBY_SO_NAME = ruby.3.1
|
103
104
|
RUBYW_INSTALL_NAME =
|
104
105
|
RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
|
105
106
|
RUBYW_BASE_NAME = rubyw
|
@@ -107,13 +108,13 @@ RUBY_BASE_NAME = ruby
|
|
107
108
|
|
108
109
|
arch = arm64-darwin21
|
109
110
|
sitearch = $(arch)
|
110
|
-
ruby_version = 3.
|
111
|
+
ruby_version = 3.1.0
|
111
112
|
ruby = $(bindir)/$(RUBY_BASE_NAME)
|
112
113
|
RUBY = $(ruby)
|
113
114
|
ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/backward.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h $(RUBY_EXTCONF_H)
|
114
115
|
|
115
116
|
RM = rm -f
|
116
|
-
RM_RF =
|
117
|
+
RM_RF = rm -fr
|
117
118
|
RMDIRS = rmdir -p
|
118
119
|
MAKEDIRS = /opt/local/bin/gmkdir -p
|
119
120
|
INSTALL = /opt/local/bin/ginstall -c
|
@@ -125,8 +126,8 @@ TOUCH = exit >
|
|
125
126
|
#### End of system configuration section. ####
|
126
127
|
|
127
128
|
preload =
|
128
|
-
libpath = . $(libdir)
|
129
|
-
LIBPATH = -L. -L$(libdir)
|
129
|
+
libpath = . $(libdir)
|
130
|
+
LIBPATH = -L. -L$(libdir)
|
130
131
|
DEFFILE =
|
131
132
|
|
132
133
|
CLEANFILES = mkmf.log
|
@@ -159,7 +160,7 @@ HDRDIR = $(sitehdrdir)$(target_prefix)
|
|
159
160
|
ARCHHDRDIR = $(sitearchhdrdir)$(target_prefix)
|
160
161
|
TARGET_SO_DIR =
|
161
162
|
TARGET_SO = $(TARGET_SO_DIR)$(DLLIB)
|
162
|
-
CLEANLIBS = $(TARGET_SO)
|
163
|
+
CLEANLIBS = $(TARGET_SO) $(TARGET_SO).dSYM
|
163
164
|
CLEANOBJS = *.o *.bak
|
164
165
|
|
165
166
|
all: $(DLLIB)
|
@@ -172,7 +173,7 @@ clean-rb-default::
|
|
172
173
|
clean-rb::
|
173
174
|
clean-so::
|
174
175
|
clean: clean-so clean-static clean-rb-default clean-rb
|
175
|
-
-$(Q)$(
|
176
|
+
-$(Q)$(RM_RF) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
|
176
177
|
|
177
178
|
distclean-rb-default::
|
178
179
|
distclean-rb::
|
data/ext/event.o
CHANGED
Binary file
|
data/ext/extconf.h
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
#ifndef EXTCONF_H
|
2
2
|
#define EXTCONF_H
|
3
3
|
#define HAVE_RB_EXT_RACTOR_SAFE 1
|
4
|
+
#define HAVE__RB_FIBER_TRANSFER 1
|
4
5
|
#define HAVE_SYS_EVENT_H 1
|
6
|
+
#define HAVE_RB_IO_DESCRIPTOR 1
|
5
7
|
#define HAVE_RB_FIBER_CURRENT 1
|
8
|
+
#define HAVE__RB_FIBER_RAISE 1
|
9
|
+
#define HAVE_RUBY_IO_BUFFER_H 1
|
6
10
|
#endif
|
data/ext/interrupt.o
CHANGED
Binary file
|
data/ext/io/event/interrupt.c
CHANGED
@@ -21,19 +21,16 @@
|
|
21
21
|
// static const int DEBUG = 0;
|
22
22
|
|
23
23
|
#include "interrupt.h"
|
24
|
-
#include <fcntl.h>
|
25
24
|
#include <unistd.h>
|
26
25
|
|
27
|
-
#ifdef HAVE_SYS_EVENTFD_H
|
28
|
-
#include <sys/eventfd.h>
|
29
|
-
#endif
|
30
|
-
|
31
26
|
#include "selector/selector.h"
|
32
27
|
|
33
28
|
#ifdef HAVE_SYS_EVENTFD_H
|
29
|
+
#include <sys/eventfd.h>
|
30
|
+
|
34
31
|
void IO_Event_Interrupt_open(struct IO_Event_Interrupt *interrupt)
|
35
32
|
{
|
36
|
-
interrupt->descriptor =
|
33
|
+
interrupt->descriptor = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
|
37
34
|
rb_update_max_fd(interrupt->descriptor);
|
38
35
|
}
|
39
36
|
|
@@ -45,13 +42,25 @@ void IO_Event_Interrupt_close(struct IO_Event_Interrupt *interrupt)
|
|
45
42
|
void IO_Event_Interrupt_signal(struct IO_Event_Interrupt *interrupt)
|
46
43
|
{
|
47
44
|
uint64_t value = 1;
|
48
|
-
write(interrupt->descriptor, &value, sizeof(value));
|
45
|
+
ssize_t result = write(interrupt->descriptor, &value, sizeof(value));
|
46
|
+
|
47
|
+
if (result == -1) {
|
48
|
+
if (errno == EAGAIN || errno == EWOULDBLOCK) return;
|
49
|
+
|
50
|
+
rb_sys_fail("IO_Event_Interrupt_signal:write");
|
51
|
+
}
|
49
52
|
}
|
50
53
|
|
51
54
|
void IO_Event_Interrupt_clear(struct IO_Event_Interrupt *interrupt)
|
52
55
|
{
|
53
56
|
uint64_t value = 0;
|
54
|
-
read(interrupt->descriptor, &value, sizeof(value));
|
57
|
+
ssize_t result = read(interrupt->descriptor, &value, sizeof(value));
|
58
|
+
|
59
|
+
if (result == -1) {
|
60
|
+
if (errno == EAGAIN || errno == EWOULDBLOCK) return;
|
61
|
+
|
62
|
+
rb_sys_fail("IO_Event_Interrupt_clear:read");
|
63
|
+
}
|
55
64
|
}
|
56
65
|
#else
|
57
66
|
void IO_Event_Interrupt_open(struct IO_Event_Interrupt *interrupt)
|
@@ -63,6 +72,9 @@ void IO_Event_Interrupt_open(struct IO_Event_Interrupt *interrupt)
|
|
63
72
|
IO_Event_Selector_nonblock_set(interrupt->descriptor[0]);
|
64
73
|
IO_Event_Selector_nonblock_set(interrupt->descriptor[1]);
|
65
74
|
#endif
|
75
|
+
|
76
|
+
rb_update_max_fd(interrupt->descriptor[0]);
|
77
|
+
rb_update_max_fd(interrupt->descriptor[1]);
|
66
78
|
}
|
67
79
|
|
68
80
|
void IO_Event_Interrupt_close(struct IO_Event_Interrupt *interrupt)
|
@@ -73,12 +85,24 @@ void IO_Event_Interrupt_close(struct IO_Event_Interrupt *interrupt)
|
|
73
85
|
|
74
86
|
void IO_Event_Interrupt_signal(struct IO_Event_Interrupt *interrupt)
|
75
87
|
{
|
76
|
-
write(interrupt->descriptor[1], ".", 1);
|
88
|
+
ssize_t result = write(interrupt->descriptor[1], ".", 1);
|
89
|
+
|
90
|
+
if (result == -1) {
|
91
|
+
if (errno == EAGAIN || errno == EWOULDBLOCK) return;
|
92
|
+
|
93
|
+
rb_sys_fail("IO_Event_Interrupt_signal:write");
|
94
|
+
}
|
77
95
|
}
|
78
96
|
|
79
97
|
void IO_Event_Interrupt_clear(struct IO_Event_Interrupt *interrupt)
|
80
98
|
{
|
81
99
|
char buffer[128];
|
82
|
-
read(interrupt->descriptor[0], buffer, sizeof(buffer));
|
100
|
+
ssize_t result = read(interrupt->descriptor[0], buffer, sizeof(buffer));
|
101
|
+
|
102
|
+
if (result == -1) {
|
103
|
+
if (errno == EAGAIN || errno == EWOULDBLOCK) return;
|
104
|
+
|
105
|
+
rb_sys_fail("IO_Event_Interrupt_clear:read");
|
106
|
+
}
|
83
107
|
}
|
84
108
|
#endif
|
data/ext/io/event/interrupt.h
CHANGED
@@ -28,6 +28,8 @@
|
|
28
28
|
#include "pidfd.c"
|
29
29
|
#include "../interrupt.h"
|
30
30
|
|
31
|
+
static const int DEBUG = 0;
|
32
|
+
|
31
33
|
static VALUE IO_Event_Selector_EPoll = Qnil;
|
32
34
|
|
33
35
|
enum {EPOLL_MAX_EVENTS = 64};
|
@@ -36,7 +38,7 @@ struct IO_Event_Selector_EPoll {
|
|
36
38
|
struct IO_Event_Selector backend;
|
37
39
|
int descriptor;
|
38
40
|
int blocked;
|
39
|
-
IO_Event_Interrupt interrupt;
|
41
|
+
struct IO_Event_Interrupt interrupt;
|
40
42
|
};
|
41
43
|
|
42
44
|
void IO_Event_Selector_EPoll_Type_mark(void *_data)
|
@@ -90,18 +92,18 @@ VALUE IO_Event_Selector_EPoll_allocate(VALUE self) {
|
|
90
92
|
return instance;
|
91
93
|
}
|
92
94
|
|
93
|
-
void IO_Event_Interrupt_add(IO_Event_Interrupt *interrupt, struct IO_Event_Selector_EPoll *data) {
|
95
|
+
void IO_Event_Interrupt_add(struct IO_Event_Interrupt *interrupt, struct IO_Event_Selector_EPoll *data) {
|
94
96
|
int descriptor = IO_Event_Interrupt_descriptor(interrupt);
|
95
97
|
|
96
98
|
struct epoll_event event = {
|
97
99
|
.events = EPOLLIN|EPOLLRDHUP,
|
98
|
-
.data = {.ptr = NULL
|
100
|
+
.data = {.ptr = NULL},
|
99
101
|
};
|
100
102
|
|
101
103
|
int result = epoll_ctl(data->descriptor, EPOLL_CTL_ADD, descriptor, &event);
|
102
104
|
|
103
105
|
if (result == -1) {
|
104
|
-
rb_sys_fail("
|
106
|
+
rb_sys_fail("IO_Event_Interrupt_add:epoll_ctl");
|
105
107
|
}
|
106
108
|
}
|
107
109
|
|
@@ -376,7 +378,11 @@ VALUE io_read_loop(VALUE _arguments) {
|
|
376
378
|
break;
|
377
379
|
} else if (result > 0) {
|
378
380
|
offset += result;
|
379
|
-
|
381
|
+
|
382
|
+
// Ensure we don't underflow length:
|
383
|
+
if ((size_t)result < length)
|
384
|
+
length -= result;
|
385
|
+
else break;
|
380
386
|
} else if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
381
387
|
IO_Event_Selector_EPoll_io_wait(arguments->self, arguments->fiber, arguments->io, RB_INT2NUM(IO_EVENT_READABLE));
|
382
388
|
} else {
|
@@ -448,6 +454,8 @@ VALUE io_write_loop(VALUE _arguments) {
|
|
448
454
|
|
449
455
|
if (result >= 0) {
|
450
456
|
offset += result;
|
457
|
+
|
458
|
+
// Result must always be <= than length:
|
451
459
|
length -= result;
|
452
460
|
} else if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
453
461
|
IO_Event_Selector_EPoll_io_wait(arguments->self, arguments->fiber, arguments->io, RB_INT2NUM(IO_EVENT_WRITABLE));
|
@@ -557,40 +565,47 @@ VALUE IO_Event_Selector_EPoll_select(VALUE self, VALUE duration) {
|
|
557
565
|
.timeout = 0
|
558
566
|
};
|
559
567
|
|
568
|
+
// Process any currently pending events:
|
560
569
|
select_internal_with_gvl(&arguments);
|
561
|
-
|
562
|
-
// If
|
563
|
-
|
570
|
+
|
571
|
+
// If we:
|
572
|
+
// 1. Didn't process any ready fibers, and
|
573
|
+
// 2. Didn't process any events from non-blocking select (above), and
|
574
|
+
// 3. There are no items in the ready list,
|
575
|
+
// then we can perform a blocking select.
|
576
|
+
if (!ready && !arguments.count && !data->backend.ready) {
|
564
577
|
arguments.timeout = make_timeout(duration);
|
565
578
|
|
566
579
|
if (arguments.timeout != 0) {
|
580
|
+
// Wait for events to occur
|
567
581
|
select_internal_without_gvl(&arguments);
|
568
582
|
}
|
569
583
|
}
|
570
584
|
|
571
585
|
for (int i = 0; i < arguments.count; i += 1) {
|
572
|
-
|
573
|
-
|
586
|
+
const struct epoll_event *event = &arguments.events[i];
|
587
|
+
if (DEBUG) fprintf(stderr, "-> ptr=%p events=%d\n", event->data.ptr, event->events);
|
574
588
|
|
575
|
-
if (
|
589
|
+
if (event->data.ptr) {
|
590
|
+
VALUE fiber = (VALUE)event->data.ptr;
|
591
|
+
VALUE result = INT2NUM(event->events);
|
592
|
+
|
593
|
+
IO_Event_Selector_fiber_transfer(fiber, 1, &result);
|
594
|
+
} else {
|
576
595
|
IO_Event_Interrupt_clear(&data->interrupt);
|
577
596
|
}
|
578
|
-
|
579
|
-
// fprintf(stderr, "-> fiber=%p descriptor=%d\n", (void*)fiber, events[i].data.fd);
|
580
|
-
|
581
|
-
IO_Event_Selector_fiber_transfer(fiber, 1, &result);
|
582
597
|
}
|
583
598
|
|
584
599
|
return INT2NUM(arguments.count);
|
585
600
|
}
|
586
601
|
|
587
|
-
VALUE
|
602
|
+
VALUE IO_Event_Selector_EPoll_wakeup(VALUE self) {
|
588
603
|
struct IO_Event_Selector_EPoll *data = NULL;
|
589
604
|
TypedData_Get_Struct(self, struct IO_Event_Selector_EPoll, &IO_Event_Selector_EPoll_Type, data);
|
590
605
|
|
591
606
|
// If we are blocking, we can schedule a nop event to wake up the selector:
|
592
607
|
if (data->blocked) {
|
593
|
-
IO_Event_Interrupt_signal(data->interrupt);
|
608
|
+
IO_Event_Interrupt_signal(&data->interrupt);
|
594
609
|
|
595
610
|
return Qtrue;
|
596
611
|
}
|
@@ -400,7 +400,11 @@ VALUE io_read_loop(VALUE _arguments) {
|
|
400
400
|
break;
|
401
401
|
} else if (result > 0) {
|
402
402
|
offset += result;
|
403
|
-
|
403
|
+
|
404
|
+
// Ensure we don't underflow length:
|
405
|
+
if ((size_t)result < length)
|
406
|
+
length -= result;
|
407
|
+
else break;
|
404
408
|
} else if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
405
409
|
IO_Event_Selector_KQueue_io_wait(arguments->self, arguments->fiber, arguments->io, RB_INT2NUM(IO_EVENT_READABLE));
|
406
410
|
} else {
|
@@ -475,6 +479,8 @@ VALUE io_write_loop(VALUE _arguments) {
|
|
475
479
|
|
476
480
|
if (result >= 0) {
|
477
481
|
offset += result;
|
482
|
+
|
483
|
+
// Result must always be <= than length:
|
478
484
|
length -= result;
|
479
485
|
} else if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
480
486
|
IO_Event_Selector_KQueue_io_wait(arguments->self, arguments->fiber, arguments->io, RB_INT2NUM(IO_EVENT_WRITABLE));
|
@@ -572,6 +578,7 @@ void * select_internal(void *_arguments) {
|
|
572
578
|
static
|
573
579
|
void select_internal_without_gvl(struct select_arguments *arguments) {
|
574
580
|
arguments->data->blocked = 1;
|
581
|
+
|
575
582
|
rb_thread_call_without_gvl(select_internal, (void *)arguments, RUBY_UBF_IO, 0);
|
576
583
|
arguments->data->blocked = 0;
|
577
584
|
|
@@ -604,18 +611,23 @@ VALUE IO_Event_Selector_KQueue_select(VALUE self, VALUE duration) {
|
|
604
611
|
}
|
605
612
|
};
|
606
613
|
|
614
|
+
arguments.timeout = &arguments.storage;
|
615
|
+
|
607
616
|
// We break this implementation into two parts.
|
608
617
|
// (1) count = kevent(..., timeout = 0)
|
609
618
|
// (2) without gvl: kevent(..., timeout = 0) if count == 0 and timeout != 0
|
610
619
|
// This allows us to avoid releasing and reacquiring the GVL.
|
611
620
|
// Non-comprehensive testing shows this gives a 1.5x speedup.
|
612
|
-
arguments.timeout = &arguments.storage;
|
613
621
|
|
614
622
|
// First do the syscall with no timeout to get any immediately available events:
|
615
623
|
select_internal_with_gvl(&arguments);
|
616
624
|
|
617
|
-
// If
|
618
|
-
|
625
|
+
// If we:
|
626
|
+
// 1. Didn't process any ready fibers, and
|
627
|
+
// 2. Didn't process any events from non-blocking select (above), and
|
628
|
+
// 3. There are no items in the ready list,
|
629
|
+
// then we can perform a blocking select.
|
630
|
+
if (!ready && !arguments.count && !data->backend.ready) {
|
619
631
|
arguments.timeout = make_timeout(duration, &arguments.storage);
|
620
632
|
|
621
633
|
if (!timeout_nonblocking(arguments.timeout)) {
|
@@ -26,7 +26,6 @@
|
|
26
26
|
#include <time.h>
|
27
27
|
|
28
28
|
#include "pidfd.c"
|
29
|
-
#include "../interrupt.h"
|
30
29
|
|
31
30
|
static const int DEBUG = 0;
|
32
31
|
|
@@ -405,8 +404,11 @@ VALUE IO_Event_Selector_URing_io_read(VALUE self, VALUE fiber, VALUE io, VALUE b
|
|
405
404
|
break;
|
406
405
|
} else if (result > 0) {
|
407
406
|
offset += result;
|
408
|
-
|
409
|
-
|
407
|
+
|
408
|
+
// Ensure we don't underflow length:
|
409
|
+
if ((size_t)result < length)
|
410
|
+
length -= result;
|
411
|
+
else break;
|
410
412
|
} else if (-result == EAGAIN || -result == EWOULDBLOCK) {
|
411
413
|
IO_Event_Selector_URing_io_wait(self, fiber, io, RB_INT2NUM(IO_EVENT_READABLE));
|
412
414
|
} else {
|
@@ -561,7 +563,7 @@ int select_internal_without_gvl(struct select_arguments *arguments) {
|
|
561
563
|
return arguments->result;
|
562
564
|
}
|
563
565
|
|
564
|
-
#define IO_EVENT_SELECTOR_URING_UDATA_INTERRUPT ((__u64) -2)
|
566
|
+
// #define IO_EVENT_SELECTOR_URING_UDATA_INTERRUPT ((__u64) -2)
|
565
567
|
|
566
568
|
static inline
|
567
569
|
unsigned select_process_completions(struct io_uring *ring) {
|
@@ -578,10 +580,9 @@ unsigned select_process_completions(struct io_uring *ring) {
|
|
578
580
|
continue;
|
579
581
|
}
|
580
582
|
|
581
|
-
if (cqe->user_data == IO_EVENT_SELECTOR_URING_UDATA_INTERRUPT) {
|
582
|
-
|
583
|
-
|
584
|
-
}
|
583
|
+
// if (cqe->user_data == IO_EVENT_SELECTOR_URING_UDATA_INTERRUPT) {
|
584
|
+
// io_uring_cq_advance(ring, 1);
|
585
|
+
// }
|
585
586
|
|
586
587
|
VALUE fiber = (VALUE)cqe->user_data;
|
587
588
|
VALUE result = RB_INT2NUM(cqe->res);
|
@@ -608,8 +609,12 @@ VALUE IO_Event_Selector_URing_select(VALUE self, VALUE duration) {
|
|
608
609
|
|
609
610
|
int result = select_process_completions(&data->ring);
|
610
611
|
|
611
|
-
// If
|
612
|
-
|
612
|
+
// If we:
|
613
|
+
// 1. Didn't process any ready fibers, and
|
614
|
+
// 2. Didn't process any events from non-blocking select (above), and
|
615
|
+
// 3. There are no items in the ready list,
|
616
|
+
// then we can perform a blocking select.
|
617
|
+
if (!ready && !result && !data->backend.ready) {
|
613
618
|
// We might need to wait for events:
|
614
619
|
struct select_arguments arguments = {
|
615
620
|
.data = data,
|
@@ -634,8 +639,8 @@ VALUE IO_Event_Selector_URing_select(VALUE self, VALUE duration) {
|
|
634
639
|
}
|
635
640
|
|
636
641
|
VALUE IO_Event_Selector_URing_wakeup(VALUE self) {
|
637
|
-
struct
|
638
|
-
TypedData_Get_Struct(self, struct
|
642
|
+
struct IO_Event_Selector_URing *data = NULL;
|
643
|
+
TypedData_Get_Struct(self, struct IO_Event_Selector_URing, &IO_Event_Selector_URing_Type, data);
|
639
644
|
|
640
645
|
// If we are blocking, we can schedule a nop event to wake up the selector:
|
641
646
|
if (data->blocked) {
|
@@ -652,7 +657,7 @@ VALUE IO_Event_Selector_URing_wakeup(VALUE self) {
|
|
652
657
|
}
|
653
658
|
|
654
659
|
io_uring_prep_nop(sqe);
|
655
|
-
io_uring_submit(&
|
660
|
+
io_uring_submit(&data->ring);
|
656
661
|
|
657
662
|
return Qtrue;
|
658
663
|
}
|
@@ -667,7 +672,7 @@ void Init_IO_Event_Selector_URing(VALUE IO_Event_Selector) {
|
|
667
672
|
rb_define_alloc_func(IO_Event_Selector_URing, IO_Event_Selector_URing_allocate);
|
668
673
|
rb_define_method(IO_Event_Selector_URing, "initialize", IO_Event_Selector_URing_initialize, 1);
|
669
674
|
|
670
|
-
rb_define_method(IO_Event_Selector_URing, "loop", IO_Event_Selector_URing_loop,
|
675
|
+
rb_define_method(IO_Event_Selector_URing, "loop", IO_Event_Selector_URing_loop, 0);
|
671
676
|
|
672
677
|
rb_define_method(IO_Event_Selector_URing, "transfer", IO_Event_Selector_URing_transfer, 0);
|
673
678
|
rb_define_method(IO_Event_Selector_URing, "resume", IO_Event_Selector_URing_resume, -1);
|
data/ext/kqueue.o
CHANGED
Binary file
|
data/ext/mkmf.log
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
have_func: checking for rb_ext_ractor_safe()... -------------------- yes
|
2
2
|
|
3
|
-
"clang -
|
3
|
+
DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc "
|
4
4
|
checked program was:
|
5
5
|
/* begin */
|
6
6
|
1: #include "ruby.h"
|
@@ -11,7 +11,7 @@ checked program was:
|
|
11
11
|
6: }
|
12
12
|
/* end */
|
13
13
|
|
14
|
-
"clang -
|
14
|
+
DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc "
|
15
15
|
checked program was:
|
16
16
|
/* begin */
|
17
17
|
1: #include "ruby.h"
|
@@ -32,13 +32,9 @@ checked program was:
|
|
32
32
|
|
33
33
|
--------------------
|
34
34
|
|
35
|
-
have_func: checking for &rb_fiber_transfer()... --------------------
|
35
|
+
have_func: checking for &rb_fiber_transfer()... -------------------- yes
|
36
36
|
|
37
|
-
"clang -
|
38
|
-
conftest.c:14:76: error: use of undeclared identifier 'rb_fiber_transfer'
|
39
|
-
int t(void) { const volatile void *volatile p; p = (const volatile void *)&rb_fiber_transfer; return !p; }
|
40
|
-
^
|
41
|
-
1 error generated.
|
37
|
+
DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc "
|
42
38
|
checked program was:
|
43
39
|
/* begin */
|
44
40
|
1: #include "ruby.h"
|
@@ -61,7 +57,7 @@ checked program was:
|
|
61
57
|
|
62
58
|
have_library: checking for -luring... -------------------- no
|
63
59
|
|
64
|
-
"clang -
|
60
|
+
DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc -luring "
|
65
61
|
ld: library not found for -luring
|
66
62
|
clang: error: linker command failed with exit code 1 (use -v to see invocation)
|
67
63
|
checked program was:
|
@@ -87,7 +83,7 @@ checked program was:
|
|
87
83
|
|
88
84
|
have_header: checking for sys/epoll.h... -------------------- no
|
89
85
|
|
90
|
-
"clang -
|
86
|
+
DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall -c conftest.c"
|
91
87
|
conftest.c:3:10: fatal error: 'sys/epoll.h' file not found
|
92
88
|
#include <sys/epoll.h>
|
93
89
|
^~~~~~~~~~~~~
|
@@ -103,7 +99,7 @@ checked program was:
|
|
103
99
|
|
104
100
|
have_header: checking for sys/event.h... -------------------- yes
|
105
101
|
|
106
|
-
"clang -
|
102
|
+
DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall -c conftest.c"
|
107
103
|
checked program was:
|
108
104
|
/* begin */
|
109
105
|
1: #include "ruby.h"
|
@@ -115,7 +111,7 @@ checked program was:
|
|
115
111
|
|
116
112
|
have_header: checking for sys/eventfd.h... -------------------- no
|
117
113
|
|
118
|
-
"clang -
|
114
|
+
DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall -c conftest.c"
|
119
115
|
conftest.c:3:10: fatal error: 'sys/eventfd.h' file not found
|
120
116
|
#include <sys/eventfd.h>
|
121
117
|
^~~~~~~~~~~~~~~
|
@@ -129,9 +125,9 @@ checked program was:
|
|
129
125
|
|
130
126
|
--------------------
|
131
127
|
|
132
|
-
have_func: checking for rb_io_descriptor()... --------------------
|
128
|
+
have_func: checking for rb_io_descriptor()... -------------------- yes
|
133
129
|
|
134
|
-
"clang -
|
130
|
+
DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc "
|
135
131
|
conftest.c:14:57: error: use of undeclared identifier 'rb_io_descriptor'
|
136
132
|
int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_io_descriptor; return !p; }
|
137
133
|
^
|
@@ -154,12 +150,7 @@ checked program was:
|
|
154
150
|
14: int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_io_descriptor; return !p; }
|
155
151
|
/* end */
|
156
152
|
|
157
|
-
"clang -
|
158
|
-
Undefined symbols for architecture arm64:
|
159
|
-
"_rb_io_descriptor", referenced from:
|
160
|
-
_t in conftest-3b24c5.o
|
161
|
-
ld: symbol(s) not found for architecture arm64
|
162
|
-
clang: error: linker command failed with exit code 1 (use -v to see invocation)
|
153
|
+
DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc "
|
163
154
|
checked program was:
|
164
155
|
/* begin */
|
165
156
|
1: #include "ruby.h"
|
@@ -183,7 +174,7 @@ checked program was:
|
|
183
174
|
|
184
175
|
have_func: checking for &rb_process_status_wait()... -------------------- no
|
185
176
|
|
186
|
-
"clang -
|
177
|
+
DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc "
|
187
178
|
conftest.c:14:76: error: use of undeclared identifier 'rb_process_status_wait'
|
188
179
|
int t(void) { const volatile void *volatile p; p = (const volatile void *)&rb_process_status_wait; return !p; }
|
189
180
|
^
|
@@ -210,7 +201,7 @@ checked program was:
|
|
210
201
|
|
211
202
|
have_func: checking for rb_fiber_current()... -------------------- yes
|
212
203
|
|
213
|
-
"clang -
|
204
|
+
DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc "
|
214
205
|
checked program was:
|
215
206
|
/* begin */
|
216
207
|
1: #include "ruby.h"
|
@@ -231,17 +222,9 @@ checked program was:
|
|
231
222
|
|
232
223
|
--------------------
|
233
224
|
|
234
|
-
have_func: checking for &rb_fiber_raise()... --------------------
|
225
|
+
have_func: checking for &rb_fiber_raise()... -------------------- yes
|
235
226
|
|
236
|
-
"clang -
|
237
|
-
conftest.c:14:76: error: use of undeclared identifier 'rb_fiber_raise'; did you mean 'rb_fiber_resume'?
|
238
|
-
int t(void) { const volatile void *volatile p; p = (const volatile void *)&rb_fiber_raise; return !p; }
|
239
|
-
^~~~~~~~~~~~~~
|
240
|
-
rb_fiber_resume
|
241
|
-
/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/ruby/internal/intern/cont.h:32:7: note: 'rb_fiber_resume' declared here
|
242
|
-
VALUE rb_fiber_resume(VALUE fib, int argc, const VALUE *argv);
|
243
|
-
^
|
244
|
-
1 error generated.
|
227
|
+
DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc "
|
245
228
|
checked program was:
|
246
229
|
/* begin */
|
247
230
|
1: #include "ruby.h"
|
@@ -262,14 +245,9 @@ checked program was:
|
|
262
245
|
|
263
246
|
--------------------
|
264
247
|
|
265
|
-
have_header: checking for ruby/io/buffer.h... --------------------
|
248
|
+
have_header: checking for ruby/io/buffer.h... -------------------- yes
|
266
249
|
|
267
|
-
"clang -
|
268
|
-
conftest.c:3:10: fatal error: 'ruby/io/buffer.h' file not found
|
269
|
-
#include <ruby/io/buffer.h>
|
270
|
-
^~~~~~~~~~~~~~~~~~
|
271
|
-
conftest.c:3:10: note: did not find header 'io/buffer.h' in framework 'ruby' (loaded from '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks')
|
272
|
-
1 error generated.
|
250
|
+
DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall -c conftest.c"
|
273
251
|
checked program was:
|
274
252
|
/* begin */
|
275
253
|
1: #include "ruby.h"
|
@@ -281,11 +259,15 @@ checked program was:
|
|
281
259
|
|
282
260
|
extconf.h is:
|
283
261
|
/* begin */
|
284
|
-
1: #ifndef EXTCONF_H
|
285
|
-
2: #define EXTCONF_H
|
286
|
-
3: #define HAVE_RB_EXT_RACTOR_SAFE 1
|
287
|
-
4: #define
|
288
|
-
5: #define
|
289
|
-
6: #
|
262
|
+
1: #ifndef EXTCONF_H
|
263
|
+
2: #define EXTCONF_H
|
264
|
+
3: #define HAVE_RB_EXT_RACTOR_SAFE 1
|
265
|
+
4: #define HAVE__RB_FIBER_TRANSFER 1
|
266
|
+
5: #define HAVE_SYS_EVENT_H 1
|
267
|
+
6: #define HAVE_RB_IO_DESCRIPTOR 1
|
268
|
+
7: #define HAVE_RB_FIBER_CURRENT 1
|
269
|
+
8: #define HAVE__RB_FIBER_RAISE 1
|
270
|
+
9: #define HAVE_RUBY_IO_BUFFER_H 1
|
271
|
+
10: #endif
|
290
272
|
/* end */
|
291
273
|
|
data/ext/selector.o
CHANGED
Binary file
|
@@ -104,7 +104,7 @@ module IO::Event
|
|
104
104
|
private
|
105
105
|
|
106
106
|
def register_readable(fiber, io, events)
|
107
|
-
if (events & READABLE) > 0
|
107
|
+
if (events & IO::READABLE) > 0
|
108
108
|
if @readable.key?(io)
|
109
109
|
raise "Cannot wait for #{io} to become readable from multiple fibers."
|
110
110
|
end
|
@@ -122,7 +122,7 @@ module IO::Event
|
|
122
122
|
end
|
123
123
|
|
124
124
|
def register_writable(fiber, io, events)
|
125
|
-
if (events & WRITABLE) > 0
|
125
|
+
if (events & IO::WRITABLE) > 0
|
126
126
|
if @writable.key?(io)
|
127
127
|
raise "Cannot wait for #{io} to become writable from multiple fibers."
|
128
128
|
end
|
@@ -140,7 +140,7 @@ module IO::Event
|
|
140
140
|
end
|
141
141
|
|
142
142
|
def register_priority(fiber, io, events)
|
143
|
-
if (events & PRIORITY) > 0
|
143
|
+
if (events & IO::PRIORITY) > 0
|
144
144
|
if @priority.key?(io)
|
145
145
|
raise "Cannot wait for #{io} to become priority from multiple fibers."
|
146
146
|
end
|
data/lib/io/event/interrupt.rb
CHANGED
@@ -18,8 +18,6 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
|
-
require_relative 'selector'
|
22
|
-
|
23
21
|
module IO::Event
|
24
22
|
# A thread safe synchronisation primative.
|
25
23
|
class Interrupt
|
@@ -33,7 +31,7 @@ module IO::Event
|
|
33
31
|
|
34
32
|
@fiber = Fiber.new do
|
35
33
|
while true
|
36
|
-
if @selector.io_wait(@fiber, @input, READABLE)
|
34
|
+
if @selector.io_wait(@fiber, @input, IO::READABLE)
|
37
35
|
@input.read_nonblock(1)
|
38
36
|
end
|
39
37
|
end
|
@@ -37,10 +37,15 @@ module IO::Event
|
|
37
37
|
|
38
38
|
attr :loop
|
39
39
|
|
40
|
+
# If the event loop is currently blocked,
|
40
41
|
def wakeup
|
41
42
|
if @blocked
|
42
43
|
@interrupt.signal
|
44
|
+
|
45
|
+
return true
|
43
46
|
end
|
47
|
+
|
48
|
+
return false
|
44
49
|
end
|
45
50
|
|
46
51
|
def close
|
@@ -112,12 +117,12 @@ module IO::Event
|
|
112
117
|
def io_wait(fiber, io, events)
|
113
118
|
remove_readable = remove_writable = false
|
114
119
|
|
115
|
-
if (events & READABLE) > 0 or (events & PRIORITY) > 0
|
120
|
+
if (events & IO::READABLE) > 0 or (events & IO::PRIORITY) > 0
|
116
121
|
@readable[io] = fiber
|
117
122
|
remove_readable = true
|
118
123
|
end
|
119
124
|
|
120
|
-
if (events & WRITABLE) > 0
|
125
|
+
if (events & IO::WRITABLE) > 0
|
121
126
|
@writable[io] = fiber
|
122
127
|
remove_writable = true
|
123
128
|
end
|
@@ -138,9 +143,9 @@ module IO::Event
|
|
138
143
|
|
139
144
|
case result = io.read_nonblock(maximum_size, exception: false)
|
140
145
|
when :wait_readable
|
141
|
-
self.io_wait(fiber, io, READABLE)
|
146
|
+
self.io_wait(fiber, io, IO::READABLE)
|
142
147
|
when :wait_writable
|
143
|
-
self.io_wait(fiber, io, WRITABLE)
|
148
|
+
self.io_wait(fiber, io, IO::WRITABLE)
|
144
149
|
else
|
145
150
|
break unless result
|
146
151
|
|
@@ -162,9 +167,9 @@ module IO::Event
|
|
162
167
|
chunk = buffer.to_str(offset, length)
|
163
168
|
case result = io.write_nonblock(chunk, exception: false)
|
164
169
|
when :wait_readable
|
165
|
-
self.io_wait(fiber, io, READABLE)
|
170
|
+
self.io_wait(fiber, io, IO::READABLE)
|
166
171
|
when :wait_writable
|
167
|
-
self.io_wait(fiber, io, WRITABLE)
|
172
|
+
self.io_wait(fiber, io, IO::WRITABLE)
|
168
173
|
else
|
169
174
|
offset += result
|
170
175
|
length -= result
|
@@ -184,7 +189,7 @@ module IO::Event
|
|
184
189
|
w.close
|
185
190
|
end
|
186
191
|
|
187
|
-
self.io_wait(fiber, r, READABLE)
|
192
|
+
self.io_wait(fiber, r, IO::READABLE)
|
188
193
|
|
189
194
|
return thread.value
|
190
195
|
ensure
|
@@ -212,8 +217,8 @@ module IO::Event
|
|
212
217
|
duration = 0
|
213
218
|
end
|
214
219
|
|
215
|
-
# The GVL ensures this is sufficiently synchronised for `#wakeup` to work correctly.
|
216
220
|
@blocked = true
|
221
|
+
duration = 0 unless @ready.empty?
|
217
222
|
readable, writable, _ = ::IO.select(@readable.keys, @writable.keys, nil, duration)
|
218
223
|
@blocked = false
|
219
224
|
|
@@ -221,12 +226,12 @@ module IO::Event
|
|
221
226
|
|
222
227
|
readable&.each do |io|
|
223
228
|
fiber = @readable.delete(io)
|
224
|
-
ready[fiber] |= READABLE
|
229
|
+
ready[fiber] |= IO::READABLE
|
225
230
|
end
|
226
231
|
|
227
232
|
writable&.each do |io|
|
228
233
|
fiber = @writable.delete(io)
|
229
|
-
ready[fiber] |= WRITABLE
|
234
|
+
ready[fiber] |= IO::WRITABLE
|
230
235
|
end
|
231
236
|
|
232
237
|
ready.each do |fiber, events|
|
data/lib/io/event/selector.rb
CHANGED
@@ -21,11 +21,6 @@
|
|
21
21
|
require_relative 'selector/select'
|
22
22
|
|
23
23
|
module IO::Event
|
24
|
-
# These constants are the same as those defined in IO.
|
25
|
-
READABLE = IO::READABLE
|
26
|
-
PRIORITY = IO::PRIORITY
|
27
|
-
WRITABLE = IO::WRITABLE
|
28
|
-
|
29
24
|
module Selector
|
30
25
|
def self.default(env = ENV)
|
31
26
|
if name = env['IO_EVENT_SELECTOR']&.to_sym
|
data/lib/io/event/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: io-event
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bake
|
@@ -53,19 +53,19 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: sus
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0.5'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0.5'
|
69
69
|
description:
|
70
70
|
email:
|
71
71
|
executables: []
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
- !ruby/object:Gem::Version
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
|
-
rubygems_version: 3.
|
123
|
+
rubygems_version: 3.3.0.dev
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: An event loop.
|