summaryrefslogtreecommitdiff
path: root/ext/json/lib
diff options
context:
space:
mode:
authorKenta Murata <mrkn@mrkn.jp>2020-12-21 15:45:50 +0900
committerKenta Murata <mrkn@mrkn.jp>2020-12-21 22:10:42 +0900
commit596da98b3ff28ff48b10aed0bbe75287862eacbb (patch)
treebdfe69c9ba9b7886b28063cb9b6b65e6ece2de96 /ext/json/lib
parent98cc15ed1e9193e17fad6b87cccf8f8b5ade7801 (diff)
[json] Make JSON.create_id thread-safe
Diffstat (limited to 'ext/json/lib')
-rw-r--r--ext/json/lib/json/common.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/ext/json/lib/json/common.rb b/ext/json/lib/json/common.rb
index c34fa61eb7d..747effee12d 100644
--- a/ext/json/lib/json/common.rb
+++ b/ext/json/lib/json/common.rb
@@ -109,7 +109,20 @@ module JSON
# JSON.create_id # => 'json_class'
attr_accessor :create_id
end
- self.create_id = 'json_class'
+
+ DEFAULT_CREATE_ID = 'json_class'.freeze
+ private_constant :DEFAULT_CREATE_ID
+
+ CREATE_ID_TLS_KEY = "JSON.create_id".freeze
+ private_constant :CREATE_ID_TLS_KEY
+
+ def self.create_id
+ Thread.current[CREATE_ID_TLS_KEY] || DEFAULT_CREATE_ID
+ end
+
+ def self.create_id=(new_value)
+ Thread.current[CREATE_ID_TLS_KEY] = new_value.dup.freeze
+ end
NaN = 0.0/0