diff options
author | Nobuyoshi Nakada <[email protected]> | 2025-05-23 20:14:20 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2025-05-25 15:22:43 +0900 |
commit | aad9fa285398d48b5647f8a36922b8d817a24156 (patch) | |
tree | b789aa228c8cfe1f3e006cc9156970587aa19514 /variable.c | |
parent | fc518fe1ff0410f836b01577b8c4f3940404a24b (diff) |
Use RB_VM_LOCKING
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/13439
Diffstat (limited to 'variable.c')
-rw-r--r-- | variable.c | 81 |
1 files changed, 21 insertions, 60 deletions
diff --git a/variable.c b/variable.c index 5c381f80ba..b19e4c0034 100644 --- a/variable.c +++ b/variable.c @@ -303,9 +303,7 @@ rb_mod_set_temporary_name(VALUE mod, VALUE name) if (NIL_P(name)) { // Set the temporary classpath to NULL (anonymous): - RB_VM_LOCK_ENTER(); - set_sub_temporary_name(mod, 0); - RB_VM_LOCK_LEAVE(); + RB_VM_LOCKING() { set_sub_temporary_name(mod, 0);} } else { // Ensure the name is a string: @@ -322,9 +320,7 @@ rb_mod_set_temporary_name(VALUE mod, VALUE name) name = rb_str_new_frozen(name); // Set the temporary classpath to the given name: - RB_VM_LOCK_ENTER(); - set_sub_temporary_name(mod, name); - RB_VM_LOCK_LEAVE(); + RB_VM_LOCKING() { set_sub_temporary_name(mod, name);} } return mod; @@ -1209,14 +1205,12 @@ rb_gen_fields_tbl_get(VALUE obj, ID id, struct gen_fields_tbl **fields_tbl) st_data_t data; int r = 0; - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { if (st_lookup(generic_fields_tbl(obj, id, false), (st_data_t)obj, &data)) { *fields_tbl = (struct gen_fields_tbl *)data; r = 1; } } - RB_VM_LOCK_LEAVE(); return r; } @@ -1273,8 +1267,7 @@ rb_free_generic_ivar(VALUE obj) bool too_complex = rb_shape_obj_too_complex_p(obj); - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { if (st_delete(generic_fields_tbl_no_ractor_check(obj), &key, &value)) { struct gen_fields_tbl *fields_tbl = (struct gen_fields_tbl *)value; @@ -1285,7 +1278,6 @@ rb_free_generic_ivar(VALUE obj) xfree(fields_tbl); } } - RB_VM_LOCK_LEAVE(); } size_t @@ -1311,8 +1303,7 @@ rb_generic_shape_id(VALUE obj) struct gen_fields_tbl *fields_tbl = 0; shape_id_t shape_id = 0; - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { st_table* global_iv_table = generic_fields_tbl(obj, 0, false); if (global_iv_table && st_lookup(global_iv_table, obj, (st_data_t *)&fields_tbl)) { @@ -1322,7 +1313,6 @@ rb_generic_shape_id(VALUE obj) shape_id = SPECIAL_CONST_SHAPE_ID; } } - RB_VM_LOCK_LEAVE(); return shape_id; } @@ -1421,8 +1411,7 @@ rb_ivar_lookup(VALUE obj, ID id, VALUE undef) bool found = false; VALUE val; - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { #if !SHAPE_IN_BASIC_FLAGS shape_id = RCLASS_SHAPE_ID(obj); #endif @@ -1452,7 +1441,6 @@ rb_ivar_lookup(VALUE obj, ID id, VALUE undef) } } } - RB_VM_LOCK_LEAVE(); if (found && rb_is_instance_id(id) && @@ -1678,8 +1666,7 @@ obj_transition_too_complex(VALUE obj, st_table *table) RCLASS_SET_FIELDS_HASH(obj, table); break; default: - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { struct st_table *gen_ivs = generic_fields_tbl_no_ractor_check(obj); struct gen_fields_tbl *old_fields_tbl = NULL; @@ -1709,7 +1696,6 @@ obj_transition_too_complex(VALUE obj, st_table *table) fields_tbl->shape_id = shape_id; #endif } - RB_VM_LOCK_LEAVE(); } xfree(old_fields); @@ -1911,11 +1897,9 @@ generic_ivar_set_shape_fields(VALUE obj, void *data) struct gen_fields_lookup_ensure_size *fields_lookup = data; - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { st_update(generic_fields_tbl(obj, fields_lookup->id, false), (st_data_t)obj, generic_fields_lookup_ensure_size, (st_data_t)fields_lookup); } - RB_VM_LOCK_LEAVE(); FL_SET_RAW(obj, FL_EXIVAR); @@ -1958,11 +1942,9 @@ generic_ivar_set_too_complex_table(VALUE obj, void *data) #endif fields_tbl->as.complex.table = st_init_numtable_with_size(1); - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { st_insert(generic_fields_tbl(obj, fields_lookup->id, false), (st_data_t)obj, (st_data_t)fields_tbl); } - RB_VM_LOCK_LEAVE(); FL_SET_RAW(obj, FL_EXIVAR); } @@ -2132,8 +2114,7 @@ rb_shape_set_shape_id(VALUE obj, shape_id_t shape_id) default: if (shape_id != SPECIAL_CONST_SHAPE_ID) { struct gen_fields_tbl *fields_tbl = 0; - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { st_table* global_iv_table = generic_fields_tbl(obj, 0, false); if (st_lookup(global_iv_table, obj, (st_data_t *)&fields_tbl)) { @@ -2143,7 +2124,6 @@ rb_shape_set_shape_id(VALUE obj, shape_id_t shape_id) rb_bug("Expected shape_id entry in global iv table"); } } - RB_VM_LOCK_LEAVE(); } } #endif @@ -2501,12 +2481,10 @@ rb_copy_generic_ivar(VALUE dest, VALUE obj) * c.fields_tbl may change in gen_fields_copy due to realloc, * no need to free */ - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { generic_fields_tbl_no_ractor_check(dest); st_insert(generic_fields_tbl_no_ractor_check(obj), (st_data_t)dest, (st_data_t)new_fields_tbl); } - RB_VM_LOCK_LEAVE(); rb_shape_set_shape(dest, shape_to_set_on_dest); } @@ -2527,8 +2505,7 @@ rb_replace_generic_ivar(VALUE clone, VALUE obj) { RUBY_ASSERT(FL_TEST(obj, FL_EXIVAR)); - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { st_data_t fields_tbl, obj_data = (st_data_t)obj; if (st_delete(generic_fields_tbl_, &obj_data, &fields_tbl)) { FL_UNSET_RAW(obj, FL_EXIVAR); @@ -2540,7 +2517,6 @@ rb_replace_generic_ivar(VALUE clone, VALUE obj) rb_bug("unreachable"); } } - RB_VM_LOCK_LEAVE(); } void @@ -2554,11 +2530,9 @@ rb_field_foreach(VALUE obj, rb_ivar_foreach_callback_func *func, st_data_t arg, case T_CLASS: case T_MODULE: IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(0); - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { class_fields_each(obj, func, arg, ivar_only); } - RB_VM_LOCK_LEAVE(); break; default: if (FL_TEST(obj, FL_EXIVAR)) { @@ -3367,11 +3341,9 @@ autoload_const_set(struct autoload_const *ac) { check_before_mod_set(ac->module, ac->name, ac->value, "constant"); - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { const_tbl_update(ac, true); } - RB_VM_LOCK_LEAVE(); return 0; /* ignored */ } @@ -3916,12 +3888,10 @@ rb_local_constants(VALUE mod) if (!tbl) return rb_ary_new2(0); - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { ary = rb_ary_new2(rb_id_table_size(tbl)); rb_id_table_foreach(tbl, rb_local_constants_i, (void *)ary); } - RB_VM_LOCK_LEAVE(); return ary; } @@ -3934,11 +3904,9 @@ rb_mod_const_at(VALUE mod, void *data) tbl = st_init_numtable(); } if (RCLASS_CONST_TBL(mod)) { - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { rb_id_table_foreach(RCLASS_CONST_TBL(mod), sv_i, tbl); } - RB_VM_LOCK_LEAVE(); } return tbl; } @@ -4113,15 +4081,13 @@ set_namespace_path(VALUE named_namespace, VALUE namespace_path) { struct rb_id_table *const_table = RCLASS_CONST_TBL(named_namespace); - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { RCLASS_WRITE_CLASSPATH(named_namespace, namespace_path, true); if (const_table) { rb_id_table_foreach(const_table, set_namespace_path_i, &namespace_path); } } - RB_VM_LOCK_LEAVE(); } static void @@ -4149,8 +4115,7 @@ const_set(VALUE klass, ID id, VALUE val) check_before_mod_set(klass, id, val, "constant"); - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { struct rb_id_table *tbl = RCLASS_WRITABLE_CONST_TBL(klass); if (!tbl) { tbl = rb_id_table_create(0); @@ -4170,7 +4135,6 @@ const_set(VALUE klass, ID id, VALUE val) const_tbl_update(&ac, false); } } - RB_VM_LOCK_LEAVE(); /* * Resolve and cache class name immediately to resolve ambiguity @@ -4846,8 +4810,7 @@ rb_class_ivar_set(VALUE obj, ID id, VALUE val) rb_class_ensure_writable(obj); - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { existing = general_ivar_set(obj, id, val, NULL, class_ivar_set_shape_fields, class_ivar_set_shape_resize_fields, @@ -4855,7 +4818,6 @@ rb_class_ivar_set(VALUE obj, ID id, VALUE val) class_ivar_set_transition_too_complex, class_ivar_set_too_complex_table).existing; } - RB_VM_LOCK_LEAVE(); return existing; } @@ -4898,11 +4860,9 @@ const_lookup(struct rb_id_table *tbl, ID id) if (tbl) { VALUE val; bool r; - RB_VM_LOCK_ENTER(); - { + RB_VM_LOCKING() { r = rb_id_table_lookup(tbl, id, &val); } - RB_VM_LOCK_LEAVE(); if (r) return (rb_const_entry_t *)val; } @@ -4914,3 +4874,4 @@ rb_const_lookup(VALUE klass, ID id) { return const_lookup(RCLASS_CONST_TBL(klass), id); } + |