[前][次][番号順一覧][スレッド一覧]

ruby-changes:64462

From: Koichi <ko1@a...>
Date: Tue, 22 Dec 2020 23:32:40 +0900 (JST)
Subject: [ruby-changes:64462] cae8bbfe62 (master): pp is ractor-ready.

https://git.ruby-lang.org/ruby.git/commit/?id=cae8bbfe62

From cae8bbfe6271a15cf212a83a9c3ac3fedcdc7718 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Tue, 22 Dec 2020 17:07:23 +0900
Subject: pp is ractor-ready.

`@sharing_detection` is only one obstruction to support pp on
non-main ractors, so make it ractor-local.

diff --git a/lib/pp.rb b/lib/pp.rb
index dede0d1..a410a0d 100644
--- a/lib/pp.rb
+++ b/lib/pp.rb
@@ -93,11 +93,24 @@ class PP < PrettyPrint https://github.com/ruby/ruby/blob/trunk/lib/pp.rb#L93
   end
   # :startdoc:
 
-  @sharing_detection = false
-  class << self
-    # Returns the sharing detection flag as a boolean value.
-    # It is false by default.
-    attr_accessor :sharing_detection
+  if defined? ::Ractor
+    class << self
+      # Returns the sharing detection flag as a boolean value.
+      # It is false (nil) by default.
+      def sharing_detection
+        Ractor.current[:pp_sharing_detection]
+      end
+      def sharing_detection=(b)
+        Ractor.current[:pp_sharing_detection] = b
+      end
+    end
+  else
+    @sharing_detection = false
+    class << self
+      # Returns the sharing detection flag as a boolean value.
+      # It is false by default.
+      attr_accessor :sharing_detection
+    end
   end
 
   module PPMethods
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]