mirror of
https://github.com/ruby/ruby.git
synced 2025-09-24 13:03:57 +02:00
[json] Make JSON.create_id thread-safe
This commit is contained in:
parent
98cc15ed1e
commit
596da98b3f
1 changed files with 14 additions and 1 deletions
|
@ -109,7 +109,20 @@ module JSON
|
||||||
# JSON.create_id # => 'json_class'
|
# JSON.create_id # => 'json_class'
|
||||||
attr_accessor :create_id
|
attr_accessor :create_id
|
||||||
end
|
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
|
NaN = 0.0/0
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue