Skip to content

Commit 0aa778c

Browse files
committed
TLV used #thread_variable_get/set rather than #[].
1 parent f6b35d9 commit 0aa778c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/concurrent/atomic/thread_local_var.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def initialize(default = nil)
8383
#
8484
# @return [Object] the current value
8585
def value
86-
if array = Thread.current[:__threadlocal_array__]
86+
if array = Thread.current.thread_variable_get(:__threadlocal_array__)
8787
value = array[@index]
8888
if value.nil?
8989
@default
@@ -106,8 +106,8 @@ def value=(value)
106106
# We could keep the thread-local arrays in a hash, keyed by Thread
107107
# But why? That would require locking
108108
# Using Ruby's built-in thread-local storage is faster
109-
unless array = me[:__threadlocal_array__]
110-
array = me[:__threadlocal_array__] = []
109+
unless array = me.thread_variable_get(:__threadlocal_array__)
110+
array = me.thread_variable_set(:__threadlocal_array__, [])
111111
LOCK.synchronize { ARRAYS[array.object_id] = array }
112112
ObjectSpace.define_finalizer(me, self.class.thread_finalizer(array))
113113
end

0 commit comments

Comments
 (0)