Class: ThreadSafe::AtomicReferenceCacheBackend::Table
Instance Method Summary
collapse
Instance Method Details
#cas_new_node(i, hash, key, value) ⇒ Object
182
183
184
|
# File 'lib/thread_safe/atomic_reference_cache_backend.rb', line 182
def cas_new_node(i, hash, key, value)
cas(i, nil, Node.new(hash, key, value))
end
|
#delete_node_at(i, node, predecessor_node) ⇒ Object
212
213
214
215
216
217
218
|
# File 'lib/thread_safe/atomic_reference_cache_backend.rb', line 212
def delete_node_at(i, node, predecessor_node)
if predecessor_node
predecessor_node.next = node.next
else
volatile_set(i, node.next)
end
end
|
#try_lock_via_hash(i, node, node_hash) ⇒ Object
206
207
208
209
210
|
# File 'lib/thread_safe/atomic_reference_cache_backend.rb', line 206
def try_lock_via_hash(i, node, node_hash)
node.try_lock_via_hash(node_hash) do
yield if volatile_get(i) == node
end
end
|
#try_to_cas_in_computed(i, hash, key) ⇒ Object
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
# File 'lib/thread_safe/atomic_reference_cache_backend.rb', line 186
def try_to_cas_in_computed(i, hash, key)
succeeded = false
new_value = nil
new_node = Node.new(locked_hash = hash | LOCKED, key, NULL)
if cas(i, nil, new_node)
begin
if NULL == (new_value = yield(NULL))
was_null = true
else
new_node.value = new_value
end
succeeded = true
ensure
volatile_set(i, nil) if !succeeded || was_null
new_node.unlock_via_hash(locked_hash, hash)
end
end
return succeeded, new_value
end
|