Skip to content
Open
33 changes: 33 additions & 0 deletions .github/workflows/test-futex.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Test Futex

on: [push, pull_request]

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-26.04

steps:
- uses: actions/checkout@v7

- name: Install liburing with futex support
run: sudo apt-get update && sudo apt-get install -y liburing-dev

- uses: ruby/setup-ruby@v1
with:
ruby-version: ruby
bundler-cache: true

- name: Run futex tests
timeout-minutes: 5
env:
RUBYLIB: lib:ext
run: |
cd ext
bundle exec ruby extconf.rb
make
cd ..
bundle exec ruby -e 'require "io/event"; abort "IO::Event::Futex.wait_any is unavailable!" unless defined?(IO::Event::Futex) && IO::Event::Futex.respond_to?(:wait_any); selector = IO::Event::Selector::URing.new(Fiber.current); abort "futex_waitv is unavailable!" unless selector.respond_to?(:futex_waitv)'
bundle exec sus test/io/event/futex.rb
9 changes: 7 additions & 2 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@

have_func("rb_ext_ractor_safe")
have_func("&rb_fiber_transfer")
have_io_buffer = have_header("ruby/io/buffer.h")

if RUBY_PLATFORM.include?("linux") && have_io_buffer && have_header("linux/futex.h") && have_header("sys/syscall.h")
$srcs << "io/event/futex.c"
end

if have_library("uring") and have_header("liburing.h")
have_func("io_uring_prep_waitid", "liburing.h")
have_func("io_uring_prep_futex_wait", "liburing.h")
have_func("io_uring_prep_futex_waitv", "liburing.h")
$srcs << "io/event/selector/uring.c"
end

Expand All @@ -57,8 +64,6 @@
have_func("&rb_fiber_raise")
have_func("epoll_pwait2(0, 0, 0, 0, 0)", "sys/epoll.h") if enable_config("epoll_pwait2", true)

have_header("ruby/io/buffer.h")

# Feature detection for blocking operation support
if have_func("rb_fiber_scheduler_blocking_operation_extract")
# Feature detection for pthread support (needed for WorkerPool)
Expand Down
5 changes: 5 additions & 0 deletions ext/io/event/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "event.h"
#include "fiber.h"
#include "futex.h"
#include "selector/selector.h"

void Init_IO_Event(void)
Expand All @@ -15,6 +16,10 @@ void Init_IO_Event(void)

Init_IO_Event_Fiber(IO_Event);

#ifdef IO_EVENT_FUTEX
Init_IO_Event_Futex(IO_Event);
#endif

#ifdef HAVE_IO_EVENT_WORKER_POOL
Init_IO_Event_WorkerPool(IO_Event);
#endif
Expand Down
Loading
Loading