summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenta Murata <mrkn@mrkn.jp>2020-12-21 15:45:50 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-12-22 13:57:29 +0900
commit4d6482bb16e1214927c962c363bb765a4954fdc4 (patch)
tree5c131318cded9598f17ecffd93ddc4c8371580f7
parent483009dd8a6e9f2a19bce8f77a9541531f4a3eec (diff)
downloadjson-4d6482bb16e1214927c962c363bb765a4954fdc4.tar.gz
[json] Make JSON.create_id thread-safe
-rw-r--r--lib/json/common.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/json/common.rb b/lib/json/common.rb
index c34fa61..747effe 100644
--- a/lib/json/common.rb
+++ b/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