Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use 1.9's rb_thread_blocking_region_begin/end

  • Loading branch information...
commit 5cb0794af9592b625a1832af8189e6eaf45defcf 1 parent 1e0d382
@tmm1 tmm1 authored
Showing with 41 additions and 7 deletions.
  1. +19 −4 ext/em.cpp
  2. +21 −2 ext/em.h
  3. +1 −1  ext/extconf.rb
View
23 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
View
23 ext/em.h
@@ -32,8 +32,27 @@ See the file COPYING for complete licensing information.
#ifdef BUILD_FOR_RUBY
#include <ruby.h>
- #include <rubysig.h>
- #define EmSelect rb_thread_select
+ #ifdef HAVE_TBR_BEGIN
+ #define EmSelect select
+ #undef HAVE_TBR
+ //#include <rubysig.h>
+ //#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 <rubysig.h>
+ #define RB_TRAP_BEGIN TRAP_BEG
+ #define RB_TRAP_END TRAP_END
+ #endif
#else
#define EmSelect select
#endif
View
2  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:
Please sign in to comment.
Something went wrong with that request. Please try again.