The timer installation procedure needed to run on the target pthread in
order to use the per-thread CPU time timer. This limitation came from
the fact that Ruby not exposing the underlying pthread's ID which can be
passed to pthread_getcpuclockid() (note that Thread#native_thread_id
returns the kernel thread ID, which is different from the pthread ID).
This patch overcomes this by copying CRuby-internal structs into our
code, enabling access to rb_thread_t->nt->thread_id. We lose some
robustness here since we will now need to catch up with changes on the
Ruby side, but we'll gain simpler code and more predictable behavior
(less callbacks!).
The timer installation procedure needed to run on the target pthread in order to use the per-thread CPU time timer. This limitation came from the fact that Ruby not exposing the underlying pthread's ID which can be passed to pthread_getcpuclockid() (note that
Thread#native_thread_id
returns the kernel thread ID, which is different from the pthread ID).This patch overcomes this by copying CRuby-internal structs into our code, enabling access to
rb_thread_t->nt->thread_id
. We lose some robustness here since we will now need to catch up with changes on the Ruby side, but we'll gain simpler code and more predictable behavior (less callbacks!).