1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* include/ruby/debug.h, vm_trace.c: add rb_postponed_job API.

Postponed jobs are registered with this API. Registered jobs
  are invoked at `ruby-running-safe-point' as soon as possible.
  This timing is completely same as finalizer timing.
  There are two APIs:
* rb_postponed_job_register(flags, func, data): register a
  postponed job with data. flags are reserved.
* rb_postponed_job_register_one(flags, func, data): same as
  `rb_postponed_job_register', but only one `func' job is
  registered (skip if `func' is already registered).
  This change is mostly written by Aman Gupta (tmm1).
  https://bugs.ruby-lang.org/issues/8107#note-15
  [Feature #8107]
* gc.c: use postponed job API for finalizer.
* common.mk: add dependency from vm_trace.c to debug.h.
* ext/-test-/postponed_job/extconf.rb, postponed_job.c,
  test/-ext-/postponed_job/test_postponed_job.rb: add a test.
* thread.c: implement postponed API.
* vm_core.h: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2013-05-26 21:30:44 +00:00
parent 767debf92e
commit e2793a908e
10 changed files with 179 additions and 13 deletions

View file

@ -0,0 +1 @@
create_makefile('-test-/postponed_job')

View file

@ -0,0 +1,32 @@
#include "ruby.h"
#include "ruby/debug.h"
static void
pjob_callback(void *data)
{
VALUE ary = (VALUE)data;
Check_Type(ary, T_ARRAY);
rb_ary_replace(ary, rb_funcall(Qnil, rb_intern("caller"), 0));
}
static VALUE
pjob_register(VALUE self, VALUE obj)
{
rb_postponed_job_register(0, pjob_callback, (void *)obj);
}
static VALUE
pjob_call_direct(VALUE self, VALUE obj)
{
pjob_callback((void *)obj);
}
void
Init_task(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_call_direct", pjob_call_direct, 1);
}