/* ![[previous]](../icons/n_left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/n_top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
DEFINITIONS
This source file includes following definitions.
- native_sleep_callback
- thread_runnable_sleep
- Init_call_without_gvl
#include "ruby/ruby.h"
#include "ruby/thread.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);
}