diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/-test-/gvl/call_without_gvl/call_without_gvl.c | 35 | ||||
-rw-r--r-- | ext/-test-/gvl/call_without_gvl/extconf.rb | 1 |
2 files changed, 36 insertions, 0 deletions
diff --git a/ext/-test-/gvl/call_without_gvl/call_without_gvl.c b/ext/-test-/gvl/call_without_gvl/call_without_gvl.c new file mode 100644 index 0000000000..0ee64a24ac --- /dev/null +++ b/ext/-test-/gvl/call_without_gvl/call_without_gvl.c @@ -0,0 +1,35 @@ +#include "ruby/ruby.h" +#include "ruby/thread.h" +#include <sys/select.h> + +static void* +native_sleep_callback(void *data) +{ + struct timeval *timeval = data; + select(0, NULL, NULL, NULL, timeval); + + return NULL; +} + + +static VALUE +thread_runnable_sleep(VALUE thread, VALUE timeout) +{ + struct timeval timeval; + + if (NIL_P(timeout)) { + rb_raise(rb_eArgError, "timeout must be non nil"); + } + + timeval = rb_time_interval(timeout); + + rb_thread_call_without_gvl(native_sleep_callback, &timeval, RUBY_UBF_IO, NULL); + + return thread; +} + +void +Init_call_without_gvl(void) +{ + rb_define_method(rb_cThread, "__runnable_sleep__", thread_runnable_sleep, 1); +} diff --git a/ext/-test-/gvl/call_without_gvl/extconf.rb b/ext/-test-/gvl/call_without_gvl/extconf.rb new file mode 100644 index 0000000000..601944c9e5 --- /dev/null +++ b/ext/-test-/gvl/call_without_gvl/extconf.rb @@ -0,0 +1 @@ +create_makefile("-test-/gvl/call_without_gvl") |