summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvo Anjo <ivo@ivoanjo.me>2021-02-21 12:29:02 +0000
committerIvo Anjo <ivo@ivoanjo.me>2021-02-21 12:58:09 +0000
commit0d1990bd304bf35ad02581bccb3c4cb5842f33f2 (patch)
treeddd93f6a38f18c43acf7fdeab4998c725efd068b
parentdb93a49e046647a2537cac3992db0a4cb9bdb5ad (diff)
downloadffi-0d1990bd304bf35ad02581bccb3c4cb5842f33f2.tar.gz
Name callback runner thread for easier debugging
Similar to what was done for the dispatcher thread.
-rw-r--r--ext/ffi_c/Function.c6
-rw-r--r--spec/ffi/async_callback_spec.rb11
2 files changed, 15 insertions, 2 deletions
diff --git a/ext/ffi_c/Function.c b/ext/ffi_c/Function.c
index 5bd9995..f68d132 100644
--- a/ext/ffi_c/Function.c
+++ b/ext/ffi_c/Function.c
@@ -310,7 +310,7 @@ function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc)
#if defined(DEFER_ASYNC_CALLBACK)
if (async_cb_thread == Qnil) {
async_cb_thread = rb_thread_create(async_cb_event, NULL);
- // Name thread, for better debugging
+ /* Name thread, for better debugging */
rb_funcall(async_cb_thread, rb_intern("name="), 1, rb_str_new2("FFI::Function Callback Dispatcher"));
}
#endif
@@ -527,7 +527,9 @@ async_cb_event(void* unused)
rb_thread_call_without_gvl(async_cb_wait, &w, async_cb_stop, &w);
if (w.cb != NULL) {
/* Start up a new ruby thread to run the ruby callback */
- rb_thread_create(async_cb_call, w.cb);
+ VALUE new_thread = rb_thread_create(async_cb_call, w.cb);
+ /* Name thread, for better debugging */
+ rb_funcall(new_thread, rb_intern("name="), 1, rb_str_new2("FFI::Function Callback Runner"));
}
}
diff --git a/spec/ffi/async_callback_spec.rb b/spec/ffi/async_callback_spec.rb
index 3d24369..02338e5 100644
--- a/spec/ffi/async_callback_spec.rb
+++ b/spec/ffi/async_callback_spec.rb
@@ -34,4 +34,15 @@ describe "async callback" do
expect(called).to be true
expect(v).to eq(0x7fffffff)
end
+
+ it "sets the name of the thread that runs the callback" do
+ skip "not yet supported on TruffleRuby" if RUBY_ENGINE == "truffleruby"
+ skip "not yet supported on JRuby" if RUBY_ENGINE == "jruby"
+
+ thread_name = nil
+
+ LibTest.testAsyncCallback(proc { thread_name = Thread.current.name }, 0)
+
+ expect(thread_name).to eq("FFI::Function Callback Runner")
+ end
end