@@ -14,7 +14,7 @@ class AtomicMarkableReference < ::Concurrent::Synchronization::Object
14
14
# @!macro [attach] atomic_markable_reference_method_initialize
15
15
def initialize ( value = nil , mark = false )
16
16
super ( )
17
- self . reference = ImmutableArray [ value , mark ]
17
+ self . reference = immutable_array ( value , mark )
18
18
end
19
19
20
20
# @!macro [attach] atomic_markable_reference_method_compare_and_set
@@ -53,7 +53,7 @@ def compare_and_set(expected_val, new_val, expected_mark, new_mark)
53
53
return false unless expected_val . equal? curr_val
54
54
end
55
55
56
- prospect = ImmutableArray [ new_val , new_mark ]
56
+ prospect = immutable_array ( new_val , new_mark )
57
57
58
58
compare_and_set_reference current , prospect
59
59
end
@@ -63,7 +63,7 @@ def compare_and_set(expected_val, new_val, expected_mark, new_mark)
63
63
#
64
64
# Gets the current reference and marked values.
65
65
#
66
- # @return [ImmutableArray ] the current reference and marked values
66
+ # @return [Array ] the current reference and marked values
67
67
def get
68
68
reference
69
69
end
@@ -95,9 +95,9 @@ def mark
95
95
# @param [Object] new_val the new value
96
96
# @param [Boolean] new_mark the new mark
97
97
#
98
- # @return [ImmutableArray ] both the new value and the new mark
98
+ # @return [Array ] both the new value and the new mark
99
99
def set ( new_val , new_mark )
100
- self . reference = ImmutableArray [ new_val , new_mark ]
100
+ self . reference = immutable_array ( new_val , new_mark )
101
101
end
102
102
103
103
# @!macro [attach] atomic_markable_reference_method_update
@@ -111,14 +111,14 @@ def set(new_val, new_mark)
111
111
# @yieldparam [Object] old_val the starting value of the atomic reference
112
112
# @yieldparam [Boolean] old_mark the starting state of marked
113
113
#
114
- # @return [ImmutableArray ] the new value and new mark
114
+ # @return [Array ] the new value and new mark
115
115
def update
116
116
loop do
117
117
old_val , old_mark = reference
118
118
new_val , new_mark = yield old_val , old_mark
119
119
120
120
if compare_and_set old_val , new_val , old_mark , new_mark
121
- return ImmutableArray [ new_val , new_mark ]
121
+ return immutable_array ( new_val , new_mark )
122
122
end
123
123
end
124
124
end
@@ -134,7 +134,7 @@ def update
134
134
# @yieldparam [Object] old_val the starting value of the atomic reference
135
135
# @yieldparam [Boolean] old_mark the starting state of marked
136
136
#
137
- # @return [ImmutableArray ] the new value and marked state
137
+ # @return [Array ] the new value and marked state
138
138
#
139
139
# @raise [Concurrent::ConcurrentUpdateError] if the update fails
140
140
def try_update!
@@ -148,7 +148,7 @@ def try_update!
148
148
'the `AtomicMarkableReference#update` method.'
149
149
end
150
150
151
- ImmutableArray [ new_val , new_mark ]
151
+ immutable_array ( new_val , new_mark )
152
152
end
153
153
154
154
# @!macro [attach] atomic_markable_reference_method_try_update
@@ -161,22 +161,21 @@ def try_update!
161
161
# @yieldparam [Object] old_val the starting value of the atomic reference
162
162
# @yieldparam [Boolean] old_mark the starting state of marked
163
163
#
164
- # @return [ImmutableArray ] the new value and marked state, or nil if
164
+ # @return [Array ] the new value and marked state, or nil if
165
165
# the update failed
166
166
def try_update
167
167
old_val , old_mark = reference
168
168
new_val , new_mark = yield old_val , old_mark
169
169
170
170
return unless compare_and_set old_val , new_val , old_mark , new_mark
171
171
172
- ImmutableArray [ new_val , new_mark ]
172
+ immutable_array ( new_val , new_mark )
173
173
end
174
174
175
- # Internal/private ImmutableArray for representing pairs
176
- class ImmutableArray < ::Array
177
- def self . new ( *args )
178
- super ( *args ) . freeze
179
- end
175
+ private
176
+
177
+ def immutable_array ( *args )
178
+ args . freeze
180
179
end
181
180
end
182
181
end
0 commit comments