diff --git a/ext/em.cpp b/ext/em.cpp index 31d733700..f59c64356 100644 --- a/ext/em.cpp +++ b/ext/em.cpp @@ -429,11 +429,11 @@ bool EventMachine_t::_RunEpollOnce() int s; #ifdef BUILD_FOR_RUBY - TRAP_BEG; + RB_TRAP_BEGIN; #endif s = epoll_wait (epfd, ev, MaxEpollDescriptors, 50); #ifdef BUILD_FOR_RUBY - TRAP_END; + RB_TRAP_END; #endif if (s > 0) { @@ -545,7 +545,14 @@ bool EventMachine_t::_RunKqueueOnce() struct kevent Karray [maxKevents]; struct timespec ts = {0, 10000000}; // Too frequent. Use blocking_region - int k = kevent (kqfd, NULL, 0, Karray, maxKevents, &ts); + int k; + #ifdef BUILD_FOR_RUBY + RB_TRAP_BEGIN; + #endif + k = kevent (kqfd, NULL, 0, Karray, maxKevents, &ts); + #ifdef BUILD_FOR_RUBY + RB_TRAP_END; + #endif struct kevent *ke = Karray; while (k > 0) { EventableDescriptor *ed = (EventableDescriptor*) (ke->udata); @@ -669,7 +676,15 @@ int SelectData_t::_Select() #endif #ifndef HAVE_TBR - return EmSelect (maxsocket+1, &fdreads, &fdwrites, NULL, &tv); + int s; + #ifdef BUILD_FOR_RUBY + RB_TRAP_BEGIN; + #endif + s = EmSelect (maxsocket+1, &fdreads, &fdwrites, NULL, &tv); + #ifdef BUILD_FOR_RUBY + RB_TRAP_END; + #endif + return s; #endif } #endif diff --git a/ext/em.h b/ext/em.h index 33047e054..bc669d564 100644 --- a/ext/em.h +++ b/ext/em.h @@ -32,8 +32,27 @@ See the file COPYING for complete licensing information. #ifdef BUILD_FOR_RUBY #include - #include - #define EmSelect rb_thread_select + #ifdef HAVE_TBR_BEGIN + #define EmSelect select + #undef HAVE_TBR + //#include + //#define RB_TRAP_BEGIN TRAP_BEG + //#define RB_TRAP_END TRAP_END + struct rb_blocking_region_buffer; + RUBY_EXTERN struct rb_blocking_region_buffer *rb_thread_blocking_region_begin(void); + RUBY_EXTERN void rb_thread_blocking_region_end(struct rb_blocking_region_buffer *); + #define RB_TRAP_BEGIN do {struct rb_blocking_region_buffer* __region = rb_thread_blocking_region_begin(); + #define RB_TRAP_END rb_thread_blocking_region_end(__region);} while (0) + #elif HAVE_TBR + #define EmSelect rb_thread_select + #define RB_TRAP_BEGIN + #define RB_TRAP_END + #else + #define EmSelect rb_thread_select + #include + #define RB_TRAP_BEGIN TRAP_BEG + #define RB_TRAP_END TRAP_END + #endif #else #define EmSelect select #endif diff --git a/ext/extconf.rb b/ext/extconf.rb index 6e5b72cbf..56854cb79 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -33,7 +33,7 @@ def add_define(name) require 'mkmf' add_define 'BUILD_FOR_RUBY' - +add_define "HAVE_TBR_BEGIN" if have_func('rb_thread_blocking_region_begin') add_define "HAVE_TBR" if have_func('rb_thread_blocking_region') and have_macro('RB_UBF_DFL', 'ruby.h') # Minor platform details between *nix and Windows: