Skip to content

Commit d495d78

Browse files
committed
Detect whether io_uring is supported at run-time.
1 parent 0aa989c commit d495d78

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

ext/io/event/selector/uring.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,24 @@ VALUE IO_Event_Selector_URing_wakeup(VALUE self) {
11751175

11761176
#pragma mark - Native Methods
11771177

1178+
int IO_Event_Selector_URing_supported_p() {
1179+
struct io_uring ring;
1180+
int result = io_uring_queue_init(1, &ring, 0);
1181+
1182+
if (result < 0) {
1183+
return 0;
1184+
}
1185+
1186+
io_uring_queue_exit(&ring);
1187+
1188+
return 1;
1189+
}
1190+
11781191
void Init_IO_Event_Selector_URing(VALUE IO_Event_Selector) {
1192+
if (!IO_Event_Selector_URing_supported_p()) {
1193+
return;
1194+
}
1195+
11791196
VALUE IO_Event_Selector_URing = rb_define_class_under(IO_Event_Selector, "URing", rb_cObject);
11801197

11811198
rb_define_alloc_func(IO_Event_Selector_URing, IO_Event_Selector_URing_allocate);

0 commit comments

Comments
 (0)