From 80cb9165fa34185b601970da407a295a78ec9eff Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Sat, 19 Dec 2020 05:52:18 +0900 Subject: add "copy: true" option for Ractor.make_shareable Ractor.make_shareable(obj) tries to make obj a shareable object by changing the attribute of obj and traversable objects from obj (mainly freeze them). "copy: true" option is more conservative approach by make deep copied object and make it sharable. It doesn't affect any existing objects. --- ractor.rb | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'ractor.rb') diff --git a/ractor.rb b/ractor.rb index 2196a93352..e4fbdfe102 100644 --- a/ractor.rb +++ b/ractor.rb @@ -214,9 +214,28 @@ class Ractor } end - def self.make_shareable obj - __builtin_cexpr! %q{ - rb_ractor_make_shareable(obj); - } + # make obj sharable. + # + # Basically, traverse referring objects from obj and freeze them. + # + # When a sharable object is found in traversing, stop traversing + # from this shareable object. + # + # If copy keyword is true, it makes a deep copied object + # and make it sharable. This is safer option (but it can take more time). + # + # Note that the specification and implementation of this method are not + # matured and can be changed in a future. + # + def self.make_shareable obj, copy: false + if copy + __builtin_cexpr! %q{ + rb_ractor_make_copy_shareable(obj); + } + else + __builtin_cexpr! %q{ + rb_ractor_make_shareable(obj); + } + end end end -- cgit v1.2.3