diff options
author | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-16 18:49:26 +0900 |
---|---|---|
committer | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-30 00:39:06 +0900 |
commit | fcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch) | |
tree | 64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/ext/-test-/postponed_job/postponed_job.c |
Fresh start
Diffstat (limited to 'jni/ruby/ext/-test-/postponed_job/postponed_job.c')
-rw-r--r-- | jni/ruby/ext/-test-/postponed_job/postponed_job.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/jni/ruby/ext/-test-/postponed_job/postponed_job.c b/jni/ruby/ext/-test-/postponed_job/postponed_job.c new file mode 100644 index 0000000..157230e --- /dev/null +++ b/jni/ruby/ext/-test-/postponed_job/postponed_job.c @@ -0,0 +1,53 @@ +#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); + 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) +{ + pjob_callback((void *)obj); + 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); +} + |