Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Ruby 2.1 #40

Merged
merged 2 commits into from Mar 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 18 additions & 4 deletions ext/libev/ev.c
Expand Up @@ -3242,7 +3242,7 @@ time_update (EV_P_ ev_tstamp max_block)
}

/* ########## NIO4R PATCHERY HO! ########## */
#if defined(HAVE_RB_THREAD_BLOCKING_REGION)
#if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
struct ev_poll_args {
struct ev_loop *loop;
ev_tstamp waittime;
Expand All @@ -3262,7 +3262,7 @@ int
ev_run (EV_P_ int flags)
{
/* ########## NIO4R PATCHERY HO! ########## */
#if defined(HAVE_RB_THREAD_BLOCKING_REGION)
#if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
struct ev_poll_args poll_args;
#endif
/* ######################################## */
Expand Down Expand Up @@ -3425,10 +3425,24 @@ rb_thread_unsafe_dangerous_crazy_blocking_region_end(...);
#######################################################################
*/

#if defined(HAVE_RB_THREAD_BLOCKING_REGION)
/*
simulate to rb_thread_call_without_gvl using rb_theread_blocking_region.
https://github.com/brianmario/mysql2/blob/master/ext/mysql2/client.h#L8
*/

#ifndef HAVE_RB_THREAD_CALL_WITHOUT_GVL
#ifdef HAVE_RB_THREAD_BLOCKING_REGION

#define rb_thread_call_without_gvl(func, data1, ubf, data2) \
rb_thread_blocking_region((rb_blocking_function_t *)func, data1, ubf, data2)

#endif
#endif

#if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
poll_args.loop = loop;
poll_args.waittime = waittime;
rb_thread_blocking_region(ev_backend_poll, (void *)&poll_args, RUBY_UBF_IO, 0);
rb_thread_call_without_gvl(ev_backend_poll, (void *)&poll_args, RUBY_UBF_IO, 0);
#else
backend_poll (EV_A_ waittime);
#endif
Expand Down
6 changes: 5 additions & 1 deletion ext/nio4r/extconf.rb
Expand Up @@ -4,6 +4,10 @@
$defs << '-DHAVE_RB_THREAD_BLOCKING_REGION'
end

if have_func('rb_thread_call_without_gvl')
$defs << '-DHAVE_RB_THEREAD_CALL_WITHOUT_GVL'
end

if have_header('sys/select.h')
$defs << '-DEV_USE_SELECT'
end
Expand Down Expand Up @@ -41,4 +45,4 @@

makefile_contents.gsub! 'LIBS = $(LIBRUBYARG_SHARED)', 'LIBS = -lws2_32 $(LIBRUBYARG_SHARED)'
File.open('Makefile', 'w') { |f| f.write makefile_contents }
end
end
6 changes: 3 additions & 3 deletions ext/nio4r/selector.c
Expand Up @@ -312,7 +312,7 @@ static int NIO_Selector_run(struct NIO_Selector *selector, VALUE timeout)
int result;
selector->selecting = 1;

#if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_ALONE)
#if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) || defined(HAVE_RB_THREAD_ALONE)
/* Implement the optional timeout (if any) as a ev_timer */
if(timeout != Qnil) {
/* It seems libev is not a fan of timers being zero, so fudge a little */
Expand All @@ -326,7 +326,7 @@ static int NIO_Selector_run(struct NIO_Selector *selector, VALUE timeout)
ev_tstamp started_at = ev_now(selector->ev_loop);
#endif

#if defined(HAVE_RB_THREAD_BLOCKING_REGION)
#if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
/* libev is patched to release the GIL when it makes its system call */
ev_loop(selector->ev_loop, EVLOOP_ONESHOT);
#elif defined(HAVE_RB_THREAD_ALONE)
Expand All @@ -337,7 +337,7 @@ static int NIO_Selector_run(struct NIO_Selector *selector, VALUE timeout)
if(0) {
#endif /* defined(HAVE_RB_THREAD_BLOCKING_REGION) */

#if !defined(HAVE_RB_THREAD_BLOCKING_REGION)
#if !defined(HAVE_RB_THREAD_BLOCKING_REGION) && !defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
TRAP_BEG;
ev_loop(selector->ev_loop, EVLOOP_ONESHOT);
TRAP_END;
Expand Down