summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2023-11-17 02:29:11 +0900
committerKoichi Sasada <ko1@atdot.net>2023-12-08 13:16:19 +0900
commit352a885a0f1a4d4576c686301ee71ea887a345e5 (patch)
treeafb66f30ac5e3056d3cf3b96ca71d5c78b4f77a0 /vm.c
parent9b7a964318d04beb82680ff1d0c6eb571f4b8b5e (diff)
Thread specific storage APIs
This patch introduces thread specific storage APIs for tools which use `rb_internal_thread_event_hook` APIs. * `rb_internal_thread_specific_key_create()` to create a tool specific thread local storage key and allocate the storage if not available. * `rb_internal_thread_specific_set()` sets a data to thread and tool specific storage. * `rb_internal_thread_specific_get()` gets a data in thread and tool specific storage. Note that `rb_internal_thread_specific_get|set(thread_val, key)` can be called without GVL and safe for async signal and safe for multi-threading (native threads). So you can call it in any internal thread event hooks. Further more you can call it from other native threads. Of course `thread_val` should be living while accessing the data from this function. Note that you should not forget to clean up the set data.
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/vm.c b/vm.c
index 294ee389aa..d7ae74a968 100644
--- a/vm.c
+++ b/vm.c
@@ -3435,6 +3435,10 @@ thread_free(void *ptr)
rb_bug("thread_free: keeping_mutexes must be NULL (%p:%p)", (void *)th, (void *)th->keeping_mutexes);
}
+ if (th->specific_storage) {
+ ruby_xfree(th->specific_storage);
+ }
+
rb_threadptr_root_fiber_release(th);
if (th->vm && th->vm->ractor.main_thread == th) {