Skip to content

Commit

Permalink
testing thread cancelability is all loops wasn't a bright idea
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@2396 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
lrz committed Aug 27, 2009
1 parent 62c8572 commit 10ef9b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,11 @@ VALUE rb_vm_current_exception(void);
void rb_vm_set_current_exception(VALUE exception);
VALUE rb_vm_backtrace(int level);

#define TEST_THREAD_CANCEL() (pthread_testcancel())

VALUE rb_vm_pop_broken_value(void);
#define RETURN_IF_BROKEN() \
do { \
pthread_testcancel(); \
VALUE __v = rb_vm_pop_broken_value(); \
if (__v != Qundef) { \
return __v; \
Expand Down
5 changes: 5 additions & 0 deletions vm_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,14 @@ rb_yield_splat(VALUE values)
static VALUE
loop_i(void)
{
int count = 0;
for (;;) {
rb_yield(Qundef);
RETURN_IF_BROKEN();
if (++count < 100) {
TEST_THREAD_CANCEL();
count = 0;
}
}
return Qnil;
}
Expand Down

0 comments on commit 10ef9b1

Please sign in to comment.