Class ThreadSafe::AtomicReferenceCacheBackend::Node
In: lib/thread_safe/atomic_reference_cache_backend.rb
Parent: Object

Key-value entry. Nodes with a hash field of MOVED are special, and do not contain user keys or values. Otherwise, keys are never nil, and NULL value fields indicate that a node is in the process of being deleted or created. For purposes of read-only access, a key may be read before a value, but can only be used after checking value to be +!= NULL+.

Methods

Included Modules

Util::CheapLockable

Constants

MOVED = ('10' << ('0' * bit_shift)).to_i(2)   Encodings for special uses of Node hash fields. See above for explanation.
LOCKED = ('01' << ('0' * bit_shift)).to_i(2)
WAITING = ('11' << ('0' * bit_shift)).to_i(2)
HASH_BITS = ('00' << ('1' * bit_shift)).to_i(2)
SPIN_LOCK_ATTEMPTS = Util::CPU_COUNT > 1 ? Util::CPU_COUNT * 2 : 0

Attributes

key  [R] 

Public Class methods

Public Instance methods

Spins a while if LOCKED bit set and this node is the first of its bin, and then sets WAITING bits on hash field and blocks (once) if they are still set. It is OK for this method to return even if lock is not available upon exit, which enables these simple single-wait mechanics.

The corresponding signalling operation is performed within callers: Upon detecting that WAITING has been set when unlocking lock (via a failed CAS from non-waiting LOCKED state), unlockers acquire the cheap_synchronize lock and perform a cheap_broadcast.

[Validate]