Skip to content

Commit 9eae762

Browse files
committed
Extract common behavior back to AbstractThreadLocalVar class
1 parent 88166ef commit 9eae762

File tree

3 files changed

+9
-37
lines changed

3 files changed

+9
-37
lines changed

lib/concurrent/atomic/abstract_thread_local_var.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ def value=(value)
2525

2626
# @!macro thread_local_var_method_bind
2727
def bind(value, &block)
28-
raise NotImplementedError
28+
if block_given?
29+
old_value = self.value
30+
begin
31+
self.value = value
32+
yield
33+
ensure
34+
self.value = old_value
35+
end
36+
end
2937
end
3038

3139
protected

lib/concurrent/atomic/java_thread_local_var.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,6 @@ def value=(value)
2626
@var.set(value)
2727
end
2828

29-
# @!macro thread_local_var_method_bind
30-
def bind(value, &block)
31-
if block_given?
32-
old_value = @var.get
33-
begin
34-
@var.set(value)
35-
yield
36-
ensure
37-
@var.set(old_value)
38-
end
39-
end
40-
end
41-
4229
protected
4330

4431
# @!visibility private

lib/concurrent/atomic/ruby_thread_local_var.rb

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,6 @@ class RubyThreadLocalVar < AbstractThreadLocalVar
3535
@@next = 0
3636
private_constant :FREE, :LOCK, :ARRAYS
3737

38-
# @!macro [attach] thread_local_var_method_initialize
39-
#
40-
# Creates a thread local variable.
41-
#
42-
# @param [Object] default the default value when otherwise unset
43-
def initialize(default = nil)
44-
@default = default
45-
allocate_storage
46-
end
47-
4838
# @!macro thread_local_var_method_get
4939
def value
5040
if array = get_threadlocal_array
@@ -76,19 +66,6 @@ def value=(value)
7666
value
7767
end
7868

79-
# @!macro thread_local_var_method_bind
80-
def bind(value, &block)
81-
if block_given?
82-
old_value = self.value
83-
begin
84-
self.value = value
85-
yield
86-
ensure
87-
self.value = old_value
88-
end
89-
end
90-
end
91-
9269
protected
9370

9471
# @!visibility private

0 commit comments

Comments
 (0)