summaryrefslogtreecommitdiff
path: root/ractor.rb
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2020-12-19 05:52:18 +0900
committerKoichi Sasada <ko1@atdot.net>2020-12-19 05:52:18 +0900
commit80cb9165fa34185b601970da407a295a78ec9eff (patch)
treef19d3490ffb3fb4f5e68d02c0f551cf9d8fcbcc4 /ractor.rb
parentcee02d754d76563635c1db90d2ab6c01f8492470 (diff)
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.
Diffstat (limited to 'ractor.rb')
-rw-r--r--ractor.rb27
1 files changed, 23 insertions, 4 deletions
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