mirror of
https://github.com/ruby/ruby.git
synced 2026-01-26 12:14:51 +00:00
Store ractor_id directly on EC
This is easier to access as ec->ractor_id instead of pointer-chasing through ec->thread->ractor->ractor_id Co-authored-by: Luke Gruber <luke.gru@gmail.com>
This commit is contained in:
parent
aace29d485
commit
63b082cf0e
Notes:
git
2025-12-18 21:44:20 +00:00
1
thread.c
1
thread.c
@ -860,6 +860,7 @@ thread_create_core(VALUE thval, struct thread_create_params *params)
|
||||
#endif
|
||||
th->invoke_type = thread_invoke_type_ractor_proc;
|
||||
th->ractor = params->g;
|
||||
th->ec->ractor_id = rb_ractor_id(th->ractor);
|
||||
th->ractor->threads.main = th;
|
||||
th->invoke_arg.proc.proc = rb_proc_isolate_bang(params->proc, Qnil);
|
||||
th->invoke_arg.proc.args = INT2FIX(RARRAY_LENINT(params->args));
|
||||
|
||||
1
vm.c
1
vm.c
@ -3955,6 +3955,7 @@ th_init(rb_thread_t *th, VALUE self, rb_vm_t *vm)
|
||||
th->ec->local_storage_recursive_hash_for_trace = Qnil;
|
||||
|
||||
th->ec->storage = Qnil;
|
||||
th->ec->ractor_id = rb_ractor_id(th->ractor);
|
||||
|
||||
#if OPT_CALL_THREADED_CODE
|
||||
th->retval = Qundef;
|
||||
|
||||
@ -1048,6 +1048,7 @@ struct rb_execution_context_struct {
|
||||
rb_fiber_t *fiber_ptr;
|
||||
struct rb_thread_struct *thread_ptr;
|
||||
rb_serial_t serial;
|
||||
rb_serial_t ractor_id;
|
||||
|
||||
/* storage (ec (fiber) local) */
|
||||
struct rb_id_table *local_storage;
|
||||
@ -2070,6 +2071,13 @@ rb_ec_ractor_ptr(const rb_execution_context_t *ec)
|
||||
}
|
||||
}
|
||||
|
||||
static inline rb_serial_t
|
||||
rb_ec_ractor_id(const rb_execution_context_t *ec)
|
||||
{
|
||||
VM_ASSERT(ec->ractor_id == rb_ractor_id(rb_ec_ractor_ptr(ec)));
|
||||
return ec->ractor_id;
|
||||
}
|
||||
|
||||
static inline rb_vm_t *
|
||||
rb_ec_vm_ptr(const rb_execution_context_t *ec)
|
||||
{
|
||||
|
||||
@ -4120,7 +4120,7 @@ vm_call_bmethod_body(rb_execution_context_t *ec, struct rb_calling_info *calling
|
||||
VALUE procv = cme->def->body.bmethod.proc;
|
||||
|
||||
if (!RB_OBJ_SHAREABLE_P(procv) &&
|
||||
cme->def->body.bmethod.defined_ractor_id != rb_ractor_id(rb_ec_ractor_ptr(ec))) {
|
||||
cme->def->body.bmethod.defined_ractor_id != rb_ec_ractor_id(ec)) {
|
||||
rb_raise(rb_eRuntimeError, "defined with an un-shareable Proc in a different Ractor");
|
||||
}
|
||||
|
||||
@ -4143,7 +4143,7 @@ vm_call_iseq_bmethod(rb_execution_context_t *ec, rb_control_frame_t *cfp, struct
|
||||
VALUE procv = cme->def->body.bmethod.proc;
|
||||
|
||||
if (!RB_OBJ_SHAREABLE_P(procv) &&
|
||||
cme->def->body.bmethod.defined_ractor_id != rb_ractor_id(rb_ec_ractor_ptr(ec))) {
|
||||
cme->def->body.bmethod.defined_ractor_id != rb_ec_ractor_id(ec)) {
|
||||
rb_raise(rb_eRuntimeError, "defined with an un-shareable Proc in a different Ractor");
|
||||
}
|
||||
|
||||
|
||||
@ -1030,7 +1030,7 @@ rb_method_definition_set(const rb_method_entry_t *me, rb_method_definition_t *de
|
||||
}
|
||||
case VM_METHOD_TYPE_BMETHOD:
|
||||
RB_OBJ_WRITE(me, &def->body.bmethod.proc, (VALUE)opts);
|
||||
def->body.bmethod.defined_ractor_id = rb_ractor_id(rb_ec_ractor_ptr(GET_EC()));
|
||||
def->body.bmethod.defined_ractor_id = rb_ec_ractor_id(GET_EC());
|
||||
return;
|
||||
case VM_METHOD_TYPE_NOTIMPLEMENTED:
|
||||
setup_method_cfunc_struct(UNALIGNED_MEMBER_PTR(def, body.cfunc), (VALUE(*)(ANYARGS))rb_f_notimplement_internal, -1);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user