ruby-changes:63533
From: Koichi <ko1@a...>
Date: Fri, 6 Nov 2020 16:15:07 +0900 (JST)
Subject: [ruby-changes:63533] 7718e9588b (master): a part of T_DATA object can Ractor#send
https://git.ruby-lang.org/ruby.git/commit/?id=7718e9588b From 7718e9588b4d7d83c8f9a89dce10b06b9f97bddb Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Fri, 6 Nov 2020 03:21:08 +0900 Subject: a part of T_DATA object can Ractor#send T_DATA objects can refer unshareable objects and they should be copied recursively, however there is no way to replace with copied unshareable objects. However, if a T_DATA object refers only shareable objects, there is no need to replace. So this kind of T_DATA object (such as Time, Dir, File::Status and so on) can be sent by Ractor.send. diff --git a/ractor.c b/ractor.c index 5b05d98..c30f5ce 100644 --- a/ractor.c +++ b/ractor.c @@ -2181,6 +2181,24 @@ void rb_hash_transient_heap_evacuate(VALUE hash, int promote); https://github.com/ruby/ruby/blob/trunk/ractor.c#L2181 void rb_struct_transient_heap_evacuate(VALUE st, int promote); #endif +static void +obj_refer_only_shareables_p_i(VALUE obj, void *ptr) +{ + int *pcnt = (int *)ptr; + + if (!rb_ractor_shareable_p(obj)) { + pcnt++; + } +} + +static int +obj_refer_only_shareables_p(VALUE obj) +{ + int cnt = 0; + rb_objspace_reachable_objects_from(obj, obj_refer_only_shareables_p_i, &cnt); + return cnt == 0; +} + static int obj_traverse_replace_i(VALUE obj, struct obj_traverse_replace_data *data) { @@ -2329,6 +2347,14 @@ obj_traverse_replace_i(VALUE obj, struct obj_traverse_replace_data *data) https://github.com/ruby/ruby/blob/trunk/ractor.c#L2347 break; case T_DATA: + if (!data->move && obj_refer_only_shareables_p(obj)) { + break; + } + else { + rb_raise(rb_eRactorError, "can not %s %"PRIsVALUE" object.", + data->move ? "move" : "copy", rb_class_of(obj)); + } + case T_IMEMO: // not supported yet return 1; -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/