1
- require 'concurrent/thread_safe/util/xor_shift_random '
1
+ require 'concurrent/thread_safe/util'
2
2
3
3
module Concurrent
4
4
@@ -88,7 +88,7 @@ module ThreadSafe
88
88
# operations (insert, delete, and replace) require locks. We do not want to
89
89
# waste the space required to associate a distinct lock object with each bin,
90
90
# so instead use the first node of a bin list itself as a lock. Blocking
91
- # support for these locks relies +Util::CheapLockable. However, we also need a
91
+ # support for these locks relies +Concurrent::ThreadSafe:: Util::CheapLockable. However, we also need a
92
92
# +try_lock+ construction, so we overlay these by using bits of the +Node+
93
93
# hash field for lock control (see above), and so normally use builtin
94
94
# monitors only for blocking and signalling using
@@ -188,7 +188,7 @@ module ThreadSafe
188
188
class AtomicReferenceMapBackend
189
189
190
190
# @!visibility private
191
- class Table < Util ::PowerOfTwoTuple
191
+ class Table < Concurrent :: ThreadSafe :: Util ::PowerOfTwoTuple
192
192
def cas_new_node ( i , hash , key , value )
193
193
cas ( i , nil , Node . new ( hash , key , value ) )
194
194
end
@@ -236,19 +236,19 @@ def delete_node_at(i, node, predecessor_node)
236
236
#
237
237
# @!visibility private
238
238
class Node
239
- extend Util ::Volatile
239
+ extend Concurrent :: ThreadSafe :: Util ::Volatile
240
240
attr_volatile :hash , :value , :next
241
241
242
- include Util ::CheapLockable
242
+ include Concurrent :: ThreadSafe :: Util ::CheapLockable
243
243
244
- bit_shift = Util ::FIXNUM_BIT_SIZE - 2 # need 2 bits for ourselves
244
+ bit_shift = Concurrent :: ThreadSafe :: Util ::FIXNUM_BIT_SIZE - 2 # need 2 bits for ourselves
245
245
# Encodings for special uses of Node hash fields. See above for explanation.
246
246
MOVED = ( '10' << ( '0' * bit_shift ) ) . to_i ( 2 ) # hash field for forwarding nodes
247
247
LOCKED = ( '01' << ( '0' * bit_shift ) ) . to_i ( 2 ) # set/tested only as a bit
248
248
WAITING = ( '11' << ( '0' * bit_shift ) ) . to_i ( 2 ) # both bits set/tested together
249
249
HASH_BITS = ( '00' << ( '1' * bit_shift ) ) . to_i ( 2 ) # usable bits of normal node hash
250
250
251
- SPIN_LOCK_ATTEMPTS = Util ::CPU_COUNT > 1 ? Util ::CPU_COUNT * 2 : 0
251
+ SPIN_LOCK_ATTEMPTS = Concurrent :: ThreadSafe :: Util ::CPU_COUNT > 1 ? Concurrent :: ThreadSafe :: Util ::CPU_COUNT * 2 : 0
252
252
253
253
attr_reader :key
254
254
@@ -272,14 +272,14 @@ def initialize(hash, key, value, next_node = nil)
272
272
def try_await_lock ( table , i )
273
273
if table && i >= 0 && i < table . size # bounds check, TODO: why are we bounds checking?
274
274
spins = SPIN_LOCK_ATTEMPTS
275
- randomizer = base_randomizer = Util ::XorShiftRandom . get
275
+ randomizer = base_randomizer = Concurrent :: ThreadSafe :: Util ::XorShiftRandom . get
276
276
while equal? ( table . volatile_get ( i ) ) && self . class . locked_hash? ( my_hash = hash )
277
277
if spins >= 0
278
278
if ( randomizer = ( randomizer >> 1 ) ) . even? # spin at random
279
279
if ( spins -= 1 ) == 0
280
280
Thread . pass # yield before blocking
281
281
else
282
- randomizer = base_randomizer = Util ::XorShiftRandom . xorshift ( base_randomizer ) if randomizer . zero?
282
+ randomizer = base_randomizer = Concurrent :: ThreadSafe :: Util ::XorShiftRandom . xorshift ( base_randomizer ) if randomizer . zero?
283
283
end
284
284
end
285
285
elsif cas_hash ( my_hash , my_hash | WAITING )
@@ -349,14 +349,14 @@ def locked_hash?(hash)
349
349
350
350
NOW_RESIZING = -1
351
351
DEFAULT_CAPACITY = 16
352
- MAX_CAPACITY = Util ::MAX_INT
352
+ MAX_CAPACITY = Concurrent :: ThreadSafe :: Util ::MAX_INT
353
353
354
354
# The buffer size for skipped bins during transfers. The
355
355
# value is arbitrary but should be large enough to avoid
356
356
# most locking stalls during resizes.
357
357
TRANSFER_BUFFER_SIZE = 32
358
358
359
- extend Util ::Volatile
359
+ extend Concurrent :: ThreadSafe :: Util ::Volatile
360
360
attr_volatile :table , # The array of bins. Lazily initialized upon first insertion. Size is always a power of two.
361
361
362
362
# Table initialization and resizing control. When negative, the
@@ -368,7 +368,7 @@ def locked_hash?(hash)
368
368
369
369
def initialize ( options = nil )
370
370
super ( )
371
- @counter = Util ::Adder . new
371
+ @counter = Concurrent :: ThreadSafe :: Util ::Adder . new
372
372
initial_capacity = options && options [ :initial_capacity ] || DEFAULT_CAPACITY
373
373
self . size_control = ( capacity = table_size_for ( initial_capacity ) ) > MAX_CAPACITY ? MAX_CAPACITY : capacity
374
374
end
@@ -747,7 +747,7 @@ def attempt_get_and_set(key, value, hash, current_table, i, node, node_hash)
747
747
748
748
def initialize_copy ( other )
749
749
super
750
- @counter = Util ::Adder . new
750
+ @counter = Concurrent :: ThreadSafe :: Util ::Adder . new
751
751
self . table = nil
752
752
self . size_control = ( other_table = other . table ) ? other_table . size : DEFAULT_CAPACITY
753
753
self
0 commit comments