From 67693d8d806e67d6e50b303dd0be6ec06b81c853 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Sat, 28 Nov 2020 04:39:09 +0900 Subject: ractor local storage C-API To manage ractor-local data for C extension, the following APIs are defined. * rb_ractor_local_storage_value_newkey * rb_ractor_local_storage_value * rb_ractor_local_storage_value_set * rb_ractor_local_storage_ptr_newkey * rb_ractor_local_storage_ptr * rb_ractor_local_storage_ptr_set At first, you need to create a key of storage by rb_ractor_local_(value|ptr)_newkey(). For ptr storage, it accepts the type of storage, how to mark and how to free with ractor's lifetime. rb_ractor_local_storage_value/set are used to access a VALUE and rb_ractor_local_storage_ptr/set are used to access a pointer. random.c uses this API. --- ractor_core.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'ractor_core.h') diff --git a/ractor_core.h b/ractor_core.h index 6e9a63dc28..b0295155ac 100644 --- a/ractor_core.h +++ b/ractor_core.h @@ -123,14 +123,16 @@ struct rb_ractor_struct { struct list_node vmlr_node; + // ractor local data + + st_table *local_storage; + VALUE r_stdin; VALUE r_stdout; VALUE r_stderr; VALUE verbose; VALUE debug; - struct rb_random_struct *default_rand; // used in random.c - // gc.c rb_objspace_reachable_objects_from struct gc_mark_func_data_struct { void *data; @@ -163,9 +165,15 @@ void rb_ractor_vm_barrier_interrupt_running_thread(rb_ractor_t *r); void rb_ractor_terminate_interrupt_main_thread(rb_ractor_t *r); void rb_ractor_terminate_all(void); bool rb_ractor_main_p_(void); +void rb_ractor_finish_marking(void); RUBY_SYMBOL_EXPORT_BEGIN bool rb_ractor_shareable_p_continue(VALUE obj); + +// THIS FUNCTION SHOULD NOT CALL WHILE INCREMENTAL MARKING!! +// This function is for T_DATA::free_func +void rb_ractor_local_storage_delkey(rb_ractor_local_key_t key); + RUBY_SYMBOL_EXPORT_END RUBY_EXTERN bool ruby_multi_ractor; -- cgit v1.2.1