Skip to content

Commit

Permalink
Use 1.9's rb_thread_blocking_region_begin/end
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Feb 8, 2009
1 parent 1e0d382 commit 5cb0794
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
23 changes: 19 additions & 4 deletions ext/em.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions ext/em.h
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ext/extconf.rb
Expand Up @@ -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:
Expand Down

0 comments on commit 5cb0794

Please sign in to comment.