Skip to content

Commit

Permalink
check main-ractor or not first
Browse files Browse the repository at this point in the history
On non-multi-ractor-mode, the cost of rb_ractor_main_p() is low
so check it first.
  • Loading branch information
ko1 committed Oct 21, 2020
1 parent 762be87 commit 631eaa8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions variable.c
Expand Up @@ -923,7 +923,8 @@ generic_ivtbl(VALUE obj, ID id, bool force_check_ractor)
ASSERT_vm_locking();

if ((force_check_ractor || rb_is_instance_id(id)) && // not internal ID
UNLIKELY(rb_ractor_shareable_p(obj) && !rb_ractor_main_p())) {
UNLIKELY(!rb_ractor_main_p()) &&
UNLIKELY(rb_ractor_shareable_p(obj))) {
rb_raise(rb_eRuntimeError, "can not access instance variables of shareable objects from non-main Ractors");
}
return generic_iv_tbl_;
Expand Down Expand Up @@ -2952,7 +2953,7 @@ rb_const_set(VALUE klass, ID id, VALUE val)
QUOTE_ID(id));
}

if (!rb_ractor_shareable_p(val) && !rb_ractor_main_p()) {
if (!rb_ractor_main_p() && !rb_ractor_shareable_p(val)) {
rb_raise(rb_eNameError, "can not set constants with non-shareable objects by non-main Ractors");
}

Expand Down

0 comments on commit 631eaa8

Please sign in to comment.