1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/-test-/postponed_job/postponed_job.c
Koichi Sasada 36da0b3da1 check interrupts at each frame pop timing.
Asynchronous events such as signal trap, finalization timing,
thread switching and so on are managed by "interrupt_flag".
Ruby's threads check this flag periodically and if a thread
does not check this flag, above events doesn't happen.

This checking is CHECK_INTS() (related) macro and it is placed
at some places (laeve instruction and so on). However, at the end
of C methods, C blocks (IMEMO_IFUNC) etc there are no checking
and it can introduce uninterruptible thread.

To modify this situation, we decide to place CHECK_INTS() at
vm_pop_frame(). It increases interrupt checking points.
[Bug #16366]

This patch can introduce unexpected events...
2019-11-29 17:47:02 +09:00

69 lines
1.4 KiB
C

#include "ruby.h"
#include "ruby/debug.h"
static int counter;
static void
pjob_callback(void *data)
{
VALUE ary = (VALUE)data;
Check_Type(ary, T_ARRAY);
rb_ary_push(ary, INT2FIX(counter));
}
static VALUE
pjob_register(VALUE self, VALUE obj)
{
counter = 0;
rb_postponed_job_register(0, pjob_callback, (void *)obj);
rb_gc_start();
counter++;
rb_gc_start();
counter++;
rb_gc_start();
counter++;
return self;
}
static void
pjob_one_callback(void *data)
{
VALUE ary = (VALUE)data;
Check_Type(ary, T_ARRAY);
rb_ary_push(ary, INT2FIX(1));
}
static VALUE
pjob_register_one(VALUE self, VALUE obj)
{
rb_postponed_job_register_one(0, pjob_one_callback, (void *)obj);
rb_postponed_job_register_one(0, pjob_one_callback, (void *)obj);
rb_postponed_job_register_one(0, pjob_one_callback, (void *)obj);
return self;
}
static VALUE
pjob_call_direct(VALUE self, VALUE obj)
{
counter = 0;
pjob_callback((void *)obj);
rb_gc_start();
counter++;
rb_gc_start();
counter++;
rb_gc_start();
counter++;
return self;
}
void
Init_postponed_job(VALUE self)
{
VALUE mBug = rb_define_module("Bug");
rb_define_module_function(mBug, "postponed_job_register", pjob_register, 1);
rb_define_module_function(mBug, "postponed_job_register_one", pjob_register_one, 1);
rb_define_module_function(mBug, "postponed_job_call_direct", pjob_call_direct, 1);
}