From 9ca41e999159096cb0872b4babbb94bf5d1af4ce Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 9 Nov 2023 13:56:29 +0100 Subject: GVL Instrumentation: pass thread->self as part of event data Context: https://github.com/ivoanjo/gvl-tracing/pull/4 Some hooks may want to collect data on a per thread basis. Right now the only way to identify the concerned thread is to use `rb_nativethread_self()` or similar, but even then because of the thread cache or MaNy, two distinct Ruby threads may report the same native thread id. By passing `thread->self`, hooks can use it as a key to store the metadata. NB: Most hooks are executed outside the GVL, so such data collection need to use a thread-safe data-structure, and shouldn't use the reference in other ways from inside the hook. They must also either pin that value or handle compaction. --- include/ruby/thread.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include/ruby') diff --git a/include/ruby/thread.h b/include/ruby/thread.h index d6a543af91..f6eea65b70 100644 --- a/include/ruby/thread.h +++ b/include/ruby/thread.h @@ -227,7 +227,9 @@ void *rb_nogvl(void *(*func)(void *), void *data1, #define RUBY_INTERNAL_THREAD_EVENT_MASK 0xff /** All Thread events */ -typedef void rb_internal_thread_event_data_t; // for future extension. +typedef struct rb_internal_thread_event_data { + VALUE thread; +} rb_internal_thread_event_data_t; typedef void (*rb_internal_thread_event_callback)(rb_event_flag_t event, const rb_internal_thread_event_data_t *event_data, -- cgit v1.2.3