diff options
author | Koichi Sasada <ko1@atdot.net> | 2020-09-25 14:06:32 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2020-09-25 16:00:13 +0900 |
commit | 96739c422206d55acab4aee917d9d965c27b6fff (patch) | |
tree | b8163686b8f90a1776deb778be37680ff84d9614 /ractor.c | |
parent | 97416ae54cebe8bd4c77da5301b82509ec43aaf2 (diff) |
Frozen Struct can be shareable.
A frozen Struct object which refers to shareable objects should be
shareable.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3580
Diffstat (limited to 'ractor.c')
-rw-r--r-- | ractor.c | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -7,6 +7,7 @@ #include "vm_sync.h" #include "ractor.h" #include "internal/error.h" +#include "internal/struct.h" static VALUE rb_cRactor; static VALUE rb_eRactorError; @@ -1785,6 +1786,22 @@ rb_ractor_shareable_p_hash_i(VALUE key, VALUE value, VALUE arg) } static bool +ractor_struct_shareable_members_p(VALUE obj) +{ + VM_ASSERT(RB_TYPE_P(obj, T_STRUCT)); + + long len = RSTRUCT_LEN(obj); + const VALUE *ptr = RSTRUCT_CONST_PTR(obj); + + for (long i=0; i<len; i++) { + if (!rb_ractor_shareable_p(ptr[i])) { + return false; + } + } + return true; +} + +static bool ractor_obj_ivars_shareable_p(VALUE obj) { uint32_t len = ROBJECT_NUMIV(obj); @@ -1850,6 +1867,19 @@ rb_ractor_shareable_p_continue(VALUE obj) return false; } } + case T_STRUCT: + if (!RB_OBJ_FROZEN_RAW(obj) || + FL_TEST_RAW(obj, RUBY_FL_EXIVAR)) { + return false; + } + else { + if (ractor_struct_shareable_members_p(obj)) { + goto shareable; + } + else { + return false; + } + } case T_OBJECT: if (RB_OBJ_FROZEN_RAW(obj) && ractor_obj_ivars_shareable_p(obj)) { goto shareable; |