event 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e30a246aa5197439b7c1d9511cd158b56b7f4965ef18a5eaee6057832d5bf8f
4
- data.tar.gz: d579312da337ed20caf61f0fd6be719874a90b2f43860cc7315244abc59f11e0
3
+ metadata.gz: 73f2afe0a8b33db63d97b134f1c8c2ae2778d2a1982ee335e1fa17df2c6a1aba
4
+ data.tar.gz: 608e5adf0b404609b4ffebdfce321e1a6aa09d4e0067b2157c48562536599006
5
5
  SHA512:
6
- metadata.gz: b183345fc94fd11872fd10b0401f87330b5334a016c43f4ffe6113c8a4c1f43c89a7eaba6319ff1530dd0f5364cb0a47843781abb45c233f4f9e619f837cdb8e
7
- data.tar.gz: d702a3aa9ae7792a4d689a9afe23b5c99e93823b59b50de7058b1ff1ffd983b7bba30931b5581397deca8bc11726248c46516e7c933331fdb8c25feaeed7793e
6
+ metadata.gz: 1b33aa76aca72169ad6c8f0b054b58f960a8f255bd77d12d44ab85622367474cac9f65edd3db39e8d414d27851963476301757465aa874879d794c11437743d5
7
+ data.tar.gz: b30be2add6fe30be434ed728ebd49bec2ded7b3cb290f9512d7856be4508576342d4164ce6d018d345ba0bc4e8397d8dde4836cdb71566dba677036295fc37c5
@@ -0,0 +1,267 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ # V=0 quiet, V=1 verbose. other values don't work.
5
+ V = 0
6
+ V0 = $(V:0=)
7
+ Q1 = $(V:1=)
8
+ Q = $(Q1:0=@)
9
+ ECHO1 = $(V:1=@ :)
10
+ ECHO = $(ECHO1:0=@ echo)
11
+ NULLCMD = :
12
+
13
+ #### Start of system configuration section. ####
14
+
15
+ srcdir = .
16
+ topdir = /home/samuel/.rubies/ruby-head/include/ruby-3.1.0
17
+ hdrdir = $(topdir)
18
+ arch_hdrdir = /home/samuel/.rubies/ruby-head/include/ruby-3.1.0/x86_64-linux
19
+ PATH_SEPARATOR = :
20
+ VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby:$(srcdir)/backend
21
+ prefix = $(DESTDIR)/home/samuel/.rubies/ruby-head
22
+ rubysitearchprefix = $(rubylibprefix)/$(sitearch)
23
+ rubyarchprefix = $(rubylibprefix)/$(arch)
24
+ rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
25
+ exec_prefix = $(prefix)
26
+ vendorarchhdrdir = $(vendorhdrdir)/$(sitearch)
27
+ sitearchhdrdir = $(sitehdrdir)/$(sitearch)
28
+ rubyarchhdrdir = $(rubyhdrdir)/$(arch)
29
+ vendorhdrdir = $(rubyhdrdir)/vendor_ruby
30
+ sitehdrdir = $(rubyhdrdir)/site_ruby
31
+ rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME)
32
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
33
+ vendorlibdir = $(vendordir)/$(ruby_version)
34
+ vendordir = $(rubylibprefix)/vendor_ruby
35
+ sitearchdir = $(sitelibdir)/$(sitearch)
36
+ sitelibdir = $(sitedir)/$(ruby_version)
37
+ sitedir = $(rubylibprefix)/site_ruby
38
+ rubyarchdir = $(rubylibdir)/$(arch)
39
+ rubylibdir = $(rubylibprefix)/$(ruby_version)
40
+ sitearchincludedir = $(includedir)/$(sitearch)
41
+ archincludedir = $(includedir)/$(arch)
42
+ sitearchlibdir = $(libdir)/$(sitearch)
43
+ archlibdir = $(libdir)/$(arch)
44
+ ridir = $(datarootdir)/$(RI_BASE_NAME)
45
+ mandir = $(datarootdir)/man
46
+ localedir = $(datarootdir)/locale
47
+ libdir = $(exec_prefix)/lib
48
+ psdir = $(docdir)
49
+ pdfdir = $(docdir)
50
+ dvidir = $(docdir)
51
+ htmldir = $(docdir)
52
+ infodir = $(datarootdir)/info
53
+ docdir = $(datarootdir)/doc/$(PACKAGE)
54
+ oldincludedir = $(DESTDIR)/usr/include
55
+ includedir = $(prefix)/include
56
+ runstatedir = $(localstatedir)/run
57
+ localstatedir = $(prefix)/var
58
+ sharedstatedir = $(prefix)/com
59
+ sysconfdir = $(prefix)/etc
60
+ datadir = $(datarootdir)
61
+ datarootdir = $(prefix)/share
62
+ libexecdir = $(exec_prefix)/libexec
63
+ sbindir = $(exec_prefix)/sbin
64
+ bindir = $(exec_prefix)/bin
65
+ archdir = $(rubyarchdir)
66
+
67
+
68
+ CC_WRAPPER =
69
+ CC = gcc
70
+ CXX = g++
71
+ LIBRUBY = $(LIBRUBY_A)
72
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
73
+ LIBRUBYARG_SHARED = -Wl,-rpath,$(libdir) -L$(libdir)
74
+ LIBRUBYARG_STATIC = -Wl,-rpath,$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)-static $(MAINLIBS)
75
+ empty =
76
+ OUTFLAG = -o $(empty)
77
+ COUTFLAG = -o $(empty)
78
+ CSRCFLAG = $(empty)
79
+
80
+ RUBY_EXTCONF_H = extconf.h
81
+ cflags = $(optflags) $(debugflags) $(warnflags)
82
+ cxxflags =
83
+ optflags = -O3 -fno-fast-math
84
+ debugflags = -ggdb3
85
+ warnflags = -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wundef
86
+ cppflags =
87
+ CCDLFLAGS = -fPIC
88
+ CFLAGS = $(CCDLFLAGS) $(cflags) -Wall $(ARCH_FLAG)
89
+ INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
90
+ DEFS =
91
+ CPPFLAGS = -DRUBY_EXTCONF_H=\"$(RUBY_EXTCONF_H)\" $(DEFS) $(cppflags)
92
+ CXXFLAGS = $(CCDLFLAGS) $(ARCH_FLAG)
93
+ ldflags = -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic
94
+ dldflags = -Wl,--compress-debug-sections=zlib
95
+ ARCH_FLAG =
96
+ DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
97
+ LDSHARED = $(CC) -shared
98
+ LDSHAREDXX = $(CXX) -shared
99
+ AR = gcc-ar
100
+ EXEEXT =
101
+
102
+ RUBY_INSTALL_NAME = $(RUBY_BASE_NAME)
103
+ RUBY_SO_NAME = ruby
104
+ RUBYW_INSTALL_NAME =
105
+ RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
106
+ RUBYW_BASE_NAME = rubyw
107
+ RUBY_BASE_NAME = ruby
108
+
109
+ arch = x86_64-linux
110
+ sitearch = $(arch)
111
+ ruby_version = 3.1.0
112
+ ruby = $(bindir)/$(RUBY_BASE_NAME)
113
+ RUBY = $(ruby)
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)
115
+
116
+ RM = rm -f
117
+ RM_RF = $(RUBY) -run -e rm -- -rf
118
+ RMDIRS = rmdir --ignore-fail-on-non-empty -p
119
+ MAKEDIRS = /usr/bin/mkdir -p
120
+ INSTALL = /usr/bin/install -c
121
+ INSTALL_PROG = $(INSTALL) -m 0755
122
+ INSTALL_DATA = $(INSTALL) -m 644
123
+ COPY = cp
124
+ TOUCH = exit >
125
+
126
+ #### End of system configuration section. ####
127
+
128
+ preload =
129
+ libpath = . $(libdir)
130
+ LIBPATH = -L. -L$(libdir) -Wl,-rpath,$(libdir)
131
+ DEFFILE =
132
+
133
+ CLEANFILES = mkmf.log
134
+ DISTCLEANFILES =
135
+ DISTCLEANDIRS =
136
+
137
+ extout =
138
+ extout_prefix =
139
+ target_prefix = /event
140
+ LOCAL_LIBS =
141
+ LIBS = -luring -lm -lc
142
+ ORIG_SRCS = event.c
143
+ SRCS = $(ORIG_SRCS) event.c backend.c uring.c epoll.c
144
+ OBJS = event.o backend.o uring.o epoll.o
145
+ HDRS = $(srcdir)/event.h $(srcdir)/extconf.h
146
+ LOCAL_HDRS =
147
+ TARGET = event
148
+ TARGET_NAME = event
149
+ TARGET_ENTRY = Init_$(TARGET_NAME)
150
+ DLLIB = $(TARGET).so
151
+ EXTSTATIC =
152
+ STATIC_LIB =
153
+
154
+ TIMESTAMP_DIR = .
155
+ BINDIR = $(bindir)
156
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
157
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
158
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
159
+ HDRDIR = $(sitehdrdir)$(target_prefix)
160
+ ARCHHDRDIR = $(sitearchhdrdir)$(target_prefix)
161
+ TARGET_SO_DIR =
162
+ TARGET_SO = $(TARGET_SO_DIR)$(DLLIB)
163
+ CLEANLIBS = $(TARGET_SO)
164
+ CLEANOBJS = *.o *.bak
165
+
166
+ all: $(DLLIB)
167
+ static: $(STATIC_LIB)
168
+ .PHONY: all install static install-so install-rb
169
+ .PHONY: clean clean-so clean-static clean-rb
170
+
171
+ clean-static::
172
+ clean-rb-default::
173
+ clean-rb::
174
+ clean-so::
175
+ clean: clean-so clean-static clean-rb-default clean-rb
176
+ -$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
177
+
178
+ distclean-rb-default::
179
+ distclean-rb::
180
+ distclean-so::
181
+ distclean-static::
182
+ distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
183
+ -$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
184
+ -$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
185
+ -$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
186
+
187
+ realclean: distclean
188
+ install: install-so install-rb
189
+
190
+ install-so: $(DLLIB) $(TIMESTAMP_DIR)/.sitearchdir.-.event.time
191
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
192
+ clean-static::
193
+ -$(Q)$(RM) $(STATIC_LIB)
194
+ install-rb: pre-install-rb do-install-rb install-rb-default
195
+ install-rb-default: pre-install-rb-default do-install-rb-default
196
+ pre-install-rb: Makefile
197
+ pre-install-rb-default: Makefile
198
+ do-install-rb:
199
+ do-install-rb-default:
200
+ pre-install-rb-default:
201
+ @$(NULLCMD)
202
+ $(TIMESTAMP_DIR)/.sitearchdir.-.event.time:
203
+ $(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR)
204
+ $(Q) $(TOUCH) $@
205
+
206
+ site-install: site-install-so site-install-rb
207
+ site-install-so: install-so
208
+ site-install-rb: install-rb
209
+
210
+ .SUFFIXES: .c .m .cc .mm .cxx .cpp .o .S
211
+
212
+ .cc.o:
213
+ $(ECHO) compiling $(<)
214
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
215
+
216
+ .cc.S:
217
+ $(ECHO) translating $(<)
218
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
219
+
220
+ .mm.o:
221
+ $(ECHO) compiling $(<)
222
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
223
+
224
+ .mm.S:
225
+ $(ECHO) translating $(<)
226
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
227
+
228
+ .cxx.o:
229
+ $(ECHO) compiling $(<)
230
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
231
+
232
+ .cxx.S:
233
+ $(ECHO) translating $(<)
234
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
235
+
236
+ .cpp.o:
237
+ $(ECHO) compiling $(<)
238
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
239
+
240
+ .cpp.S:
241
+ $(ECHO) translating $(<)
242
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
243
+
244
+ .c.o:
245
+ $(ECHO) compiling $(<)
246
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
247
+
248
+ .c.S:
249
+ $(ECHO) translating $(<)
250
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
251
+
252
+ .m.o:
253
+ $(ECHO) compiling $(<)
254
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
255
+
256
+ .m.S:
257
+ $(ECHO) translating $(<)
258
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
259
+
260
+ $(TARGET_SO): $(OBJS) Makefile
261
+ $(ECHO) linking shared-object event/$(DLLIB)
262
+ -$(Q)$(RM) $(@)
263
+ $(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
264
+
265
+
266
+
267
+ $(OBJS): $(HDRS) $(ruby_headers)
Binary file
@@ -0,0 +1,39 @@
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
+ #include "backend.h"
22
+
23
+ static ID id_transfer, id_alive_p;
24
+
25
+ void Init_Event_Backend(VALUE Event_Backend) {
26
+ id_transfer = rb_intern("transfer");
27
+ id_alive_p = rb_intern("alive?");
28
+ }
29
+
30
+ VALUE
31
+ Event_Backend_resume_safe(VALUE fiber, VALUE result) {
32
+ VALUE alive = rb_funcall(fiber, id_alive_p, 0);
33
+
34
+ if (RTEST(alive)) {
35
+ return rb_funcall(fiber, id_transfer, 1, result);
36
+ } else {
37
+ return Qnil;
38
+ }
39
+ }
@@ -18,6 +18,9 @@
18
18
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  // THE SOFTWARE.
20
20
 
21
+ #include <ruby.h>
22
+ #include <ruby/thread.h>
23
+
21
24
  enum Event {
22
25
  READABLE = 1,
23
26
  PRIORITY = 2,
@@ -26,4 +29,8 @@ enum Event {
26
29
  HANGUP = 16
27
30
  };
28
31
 
29
- #include <ruby/thread.h>
32
+ void
33
+ Init_Event_Backend();
34
+
35
+ VALUE
36
+ Event_Backend_resume_safe(VALUE fiber, VALUE argument);
@@ -272,13 +272,13 @@ VALUE Event_Backend_EPoll_select(VALUE self, VALUE duration) {
272
272
  .timeout = 0
273
273
  };
274
274
 
275
- select_internal_without_gvl(&arguments);
275
+ select_internal_with_gvl(&arguments);
276
276
 
277
277
  if (arguments.count == 0) {
278
278
  arguments.timeout = make_timeout(duration);
279
279
 
280
280
  if (arguments.timeout != 0) {
281
- select_internal_with_gvl(&arguments);
281
+ select_internal_without_gvl(&arguments);
282
282
  }
283
283
  }
284
284
 
@@ -288,7 +288,7 @@ VALUE Event_Backend_EPoll_select(VALUE self, VALUE duration) {
288
288
 
289
289
  // fprintf(stderr, "-> fiber=%p descriptor=%d\n", (void*)fiber, events[i].data.fd);
290
290
 
291
- rb_funcall(fiber, id_transfer, 1, result);
291
+ Event_Backend_resume_safe(fiber, result);
292
292
  }
293
293
 
294
294
  return INT2NUM(arguments.count);
@@ -325,7 +325,8 @@ VALUE Event_Backend_KQueue_select(VALUE self, VALUE duration) {
325
325
  for (int i = 0; i < arguments.count; i += 1) {
326
326
  VALUE fiber = (VALUE)arguments.events[i].udata;
327
327
  VALUE result = INT2NUM(arguments.events[i].filter);
328
- rb_funcall(fiber, id_transfer, 1, result);
328
+
329
+ Event_Backend_resume_safe(fiber, result);
329
330
  }
330
331
 
331
332
  return INT2NUM(arguments.count);
@@ -339,7 +340,7 @@ void Init_Event_Backend_KQueue(VALUE Event_Backend) {
339
340
 
340
341
  rb_define_alloc_func(Event_Backend_KQueue, Event_Backend_KQueue_allocate);
341
342
  rb_define_method(Event_Backend_KQueue, "initialize", Event_Backend_KQueue_initialize, 1);
342
- rb_define_method(Event_Backend_KQueue, "initialize", Event_Backend_KQueue_close, 0);
343
+ rb_define_method(Event_Backend_KQueue, "close", Event_Backend_KQueue_close, 0);
343
344
 
344
345
  rb_define_method(Event_Backend_KQueue, "io_wait", Event_Backend_KQueue_io_wait, 3);
345
346
  rb_define_method(Event_Backend_KQueue, "select", Event_Backend_KQueue_select, 1);
@@ -196,7 +196,8 @@ VALUE Event_Backend_URing_io_wait(VALUE self, VALUE fiber, VALUE io, VALUE event
196
196
 
197
197
  io_uring_prep_poll_add(sqe, descriptor, flags);
198
198
  io_uring_sqe_set_data(sqe, (void*)fiber);
199
- io_uring_submit(&data->ring);
199
+ // fprintf(stderr, "io_uring_submit\n");
200
+ // io_uring_submit(&data->ring);
200
201
 
201
202
  struct io_wait_arguments io_wait_arguments = {
202
203
  .data = data,
@@ -335,11 +336,18 @@ static
335
336
  void * select_internal(void *_arguments) {
336
337
  struct select_arguments * arguments = (struct select_arguments *)_arguments;
337
338
 
338
- arguments->count = io_uring_wait_cqes(&arguments->data->ring, arguments->cqes, 1, arguments->timeout, NULL);
339
+ io_uring_submit(&arguments->data->ring);
340
+
341
+ int result = io_uring_wait_cqes(&arguments->data->ring, arguments->cqes, 1, arguments->timeout, NULL);
339
342
 
340
- // If waiting resulted in a timeout, there are 0 events.
341
- if (arguments->count == -ETIME) {
343
+ if (result == -ETIME) {
344
+ // If waiting resulted in a timeout, there are 0 events.
342
345
  arguments->count = 0;
346
+ } else if (result == 0) {
347
+ // Otherwise, there was no error, at least 1 event was reported. So we ask for them all.
348
+ arguments->count = io_uring_peek_batch_cqe(&arguments->data->ring, arguments->cqes, URING_MAX_EVENTS);
349
+ } else {
350
+ arguments->count = result;
343
351
  }
344
352
 
345
353
  return NULL;
@@ -379,6 +387,9 @@ VALUE Event_Backend_URing_select(VALUE self, VALUE duration) {
379
387
 
380
388
  if (!timeout_nonblocking(arguments.timeout)) {
381
389
  result = select_internal_without_gvl(&arguments);
390
+ } else {
391
+ io_uring_submit(&data->ring);
392
+ result = io_uring_peek_batch_cqe(&data->ring, cqes, URING_MAX_EVENTS);
382
393
  }
383
394
  }
384
395
 
@@ -397,7 +408,7 @@ VALUE Event_Backend_URing_select(VALUE self, VALUE duration) {
397
408
 
398
409
  io_uring_cqe_seen(&data->ring, cqes[i]);
399
410
 
400
- rb_funcall(fiber, id_transfer, 1, result);
411
+ Event_Backend_resume_safe(fiber, result);
401
412
  }
402
413
 
403
414
  return INT2NUM(result);
data/ext/event/epoll.o ADDED
Binary file
data/ext/event/event.c CHANGED
@@ -19,6 +19,7 @@
19
19
  // THE SOFTWARE.
20
20
 
21
21
  #include "event.h"
22
+ #include "backend/backend.h"
22
23
 
23
24
  VALUE Event = Qnil;
24
25
  VALUE Event_Backend = Qnil;
@@ -32,6 +33,8 @@ void Init_event()
32
33
  Event = rb_define_module("Event");
33
34
  Event_Backend = rb_define_module_under(Event, "Backend");
34
35
 
36
+ Init_Event_Backend(Event_Backend);
37
+
35
38
  #ifdef EVENT_BACKEND_URING
36
39
  Init_Event_Backend_URing(Event_Backend);
37
40
  #endif
data/ext/event/event.h CHANGED
@@ -26,14 +26,14 @@
26
26
 
27
27
  void Init_event();
28
28
 
29
- #if HAVE_LIBURING_H
29
+ #ifdef HAVE_LIBURING_H
30
30
  #include "backend/uring.h"
31
31
  #endif
32
32
 
33
- #if HAVE_SYS_EPOLL_H
33
+ #ifdef HAVE_SYS_EPOLL_H
34
34
  #include "backend/epoll.h"
35
35
  #endif
36
36
 
37
- #if HAVE_SYS_EVENT_H
37
+ #ifdef HAVE_SYS_EVENT_H
38
38
  #include "backend/kqueue.h"
39
39
  #endif
data/ext/event/event.o ADDED
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ #ifndef EXTCONF_H
2
+ #define EXTCONF_H
3
+ #define HAVE_LIBURING_H 1
4
+ #define HAVE_SYS_EPOLL_H 1
5
+ #endif
data/ext/event/extconf.rb CHANGED
@@ -30,7 +30,7 @@ dir_config(extension_name)
30
30
 
31
31
  $CFLAGS << " -Wall"
32
32
 
33
- $srcs = ["event.c"]
33
+ $srcs = ["event.c", "backend/backend.c"]
34
34
  $VPATH << "$(srcdir)/backend"
35
35
 
36
36
  if have_library('uring') and have_header('liburing.h')
@@ -0,0 +1,84 @@
1
+ have_library: checking for -luring... -------------------- yes
2
+
3
+ "gcc -o conftest -I/home/samuel/.rubies/ruby-head/include/ruby-3.1.0/x86_64-linux -I/home/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/home/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wundef -Wall conftest.c -L. -L/home/samuel/.rubies/ruby-head/lib -Wl,-rpath,/home/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-rpath,/home/samuel/.rubies/ruby-head/lib -L/home/samuel/.rubies/ruby-head/lib -lruby-static -lz -lpthread -lrt -lrt -lgmp -ldl -lcrypt -lm -lm -lc"
4
+ checked program was:
5
+ /* begin */
6
+ 1: #include "ruby.h"
7
+ 2:
8
+ 3: int main(int argc, char **argv)
9
+ 4: {
10
+ 5: return !!argv[argc];
11
+ 6: }
12
+ /* end */
13
+
14
+ "gcc -o conftest -I/home/samuel/.rubies/ruby-head/include/ruby-3.1.0/x86_64-linux -I/home/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/home/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wundef -Wall conftest.c -L. -L/home/samuel/.rubies/ruby-head/lib -Wl,-rpath,/home/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-rpath,/home/samuel/.rubies/ruby-head/lib -L/home/samuel/.rubies/ruby-head/lib -lruby-static -lz -lpthread -lrt -lrt -lgmp -ldl -lcrypt -lm -luring -lm -lc"
15
+ checked program was:
16
+ /* begin */
17
+ 1: #include "ruby.h"
18
+ 2:
19
+ 3: /*top*/
20
+ 4: extern int t(void);
21
+ 5: int main(int argc, char **argv)
22
+ 6: {
23
+ 7: if (argc > 1000000) {
24
+ 8: int (* volatile tp)(void)=(int (*)(void))&t;
25
+ 9: printf("%d", (*tp)());
26
+ 10: }
27
+ 11:
28
+ 12: return !!argv[argc];
29
+ 13: }
30
+ 14:
31
+ 15: int t(void) { ; return 0; }
32
+ /* end */
33
+
34
+ --------------------
35
+
36
+ have_header: checking for liburing.h... -------------------- yes
37
+
38
+ "gcc -I/home/samuel/.rubies/ruby-head/include/ruby-3.1.0/x86_64-linux -I/home/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/home/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wundef -Wall -c conftest.c"
39
+ checked program was:
40
+ /* begin */
41
+ 1: #include "ruby.h"
42
+ 2:
43
+ 3: #include <liburing.h>
44
+ /* end */
45
+
46
+ --------------------
47
+
48
+ have_header: checking for sys/epoll.h... -------------------- yes
49
+
50
+ "gcc -I/home/samuel/.rubies/ruby-head/include/ruby-3.1.0/x86_64-linux -I/home/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/home/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wundef -Wall -c conftest.c"
51
+ checked program was:
52
+ /* begin */
53
+ 1: #include "ruby.h"
54
+ 2:
55
+ 3: #include <sys/epoll.h>
56
+ /* end */
57
+
58
+ --------------------
59
+
60
+ have_header: checking for sys/event.h... -------------------- no
61
+
62
+ "gcc -I/home/samuel/.rubies/ruby-head/include/ruby-3.1.0/x86_64-linux -I/home/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/home/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wundef -Wall -c conftest.c"
63
+ conftest.c:3:10: fatal error: sys/event.h: No such file or directory
64
+ 3 | #include <sys/event.h>
65
+ | ^~~~~~~~~~~~~
66
+ compilation terminated.
67
+ checked program was:
68
+ /* begin */
69
+ 1: #include "ruby.h"
70
+ 2:
71
+ 3: #include <sys/event.h>
72
+ /* end */
73
+
74
+ --------------------
75
+
76
+ extconf.h is:
77
+ /* begin */
78
+ 1: #ifndef EXTCONF_H
79
+ 2: #define EXTCONF_H
80
+ 3: #define HAVE_LIBURING_H 1
81
+ 4: #define HAVE_SYS_EPOLL_H 1
82
+ 5: #endif
83
+ /* end */
84
+
data/ext/event/uring.o ADDED
Binary file
data/lib/event.rb CHANGED
@@ -19,7 +19,7 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  require_relative 'event/version'
22
- require_relative 'event/backend/select'
22
+ require_relative 'event/backend'
23
23
 
24
24
  module Event
25
25
  # These constants are the same as those defined in IO.
@@ -0,0 +1,49 @@
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_relative 'backend/select'
22
+
23
+ module Event
24
+ module Backend
25
+ def self.default(env = ENV)
26
+ if backend = env['EVENT_BACKEND']&.to_sym
27
+ if Event::Backend.const_defined?(backend)
28
+ return Event::Backend.const_get(backend)
29
+ else
30
+ warn "Could not find EVENT_BACKEND=#{backend}!"
31
+ end
32
+ end
33
+
34
+ if self.const_defined?(:URing)
35
+ return Event::Backend::URing
36
+ elsif self.const_defined?(:KQueue)
37
+ return Event::Backend::KQueue
38
+ elsif self.const_defined?(:EPoll)
39
+ return Event::Backend::EPoll
40
+ else
41
+ return Event::Backend::Select
42
+ end
43
+ end
44
+
45
+ def self.new(...)
46
+ default.new(...)
47
+ end
48
+ end
49
+ end
@@ -69,7 +69,7 @@ module Event
69
69
  end
70
70
 
71
71
  ready.each do |fiber, events|
72
- fiber.transfer(events)
72
+ fiber.transfer(events) if fiber.alive?
73
73
  end
74
74
  end
75
75
  end
data/lib/event/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Event
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.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-05-05 00:00:00.000000000 Z
11
+ date: 2021-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bake
@@ -73,6 +73,9 @@ extensions:
73
73
  - ext/event/extconf.rb
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ext/event/Makefile
77
+ - ext/event/backend.o
78
+ - ext/event/backend/backend.c
76
79
  - ext/event/backend/backend.h
77
80
  - ext/event/backend/epoll.c
78
81
  - ext/event/backend/epoll.h
@@ -80,10 +83,17 @@ files:
80
83
  - ext/event/backend/kqueue.h
81
84
  - ext/event/backend/uring.c
82
85
  - ext/event/backend/uring.h
86
+ - ext/event/epoll.o
83
87
  - ext/event/event.c
84
88
  - ext/event/event.h
89
+ - ext/event/event.o
90
+ - ext/event/event.so
91
+ - ext/event/extconf.h
85
92
  - ext/event/extconf.rb
93
+ - ext/event/mkmf.log
94
+ - ext/event/uring.o
86
95
  - lib/event.rb
96
+ - lib/event/backend.rb
87
97
  - lib/event/backend/select.rb
88
98
  - lib/event/debug/selector.rb
89
99
  - lib/event/selector.rb
@@ -107,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
117
  - !ruby/object:Gem::Version
108
118
  version: '0'
109
119
  requirements: []
110
- rubygems_version: 3.2.15
120
+ rubygems_version: 3.3.0.dev
111
121
  signing_key:
112
122
  specification_version: 4
113
123
  summary: An event loop.