Skip to content

Commit 3c66eb3

Browse files
luke-gruberjhawthorn
authored andcommitted
Change def->method_serial to be atomic
`rb_method_definition_create` can be called across different ractors at the same time, so `def->method_serial` should be atomic.
1 parent 328e302 commit 3c66eb3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

vm_method.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,15 +879,16 @@ method_definition_reset(const rb_method_entry_t *me)
879879
}
880880
}
881881

882+
static rb_atomic_t method_serial = 1;
883+
882884
rb_method_definition_t *
883885
rb_method_definition_create(rb_method_type_t type, ID mid)
884886
{
885887
rb_method_definition_t *def;
886888
def = ZALLOC(rb_method_definition_t);
887889
def->type = type;
888890
def->original_id = mid;
889-
static uintptr_t method_serial = 1;
890-
def->method_serial = method_serial++;
891+
def->method_serial = (uintptr_t)RUBY_ATOMIC_FETCH_ADD(method_serial, 1);
891892
def->ns = rb_current_namespace();
892893
return def;
893894
}

0 commit comments

Comments
 (0)