1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
require 'thread'
require 'concurrent/collection/map/non_concurrent_map_backend'
module Concurrent
# @!visibility private
module Collection
# @!visibility private
class MriMapBackend < NonConcurrentMapBackend
def initialize(options = nil)
super(options)
@write_lock = Mutex.new
end
def []=(key, value)
@write_lock.synchronize { super }
end
def compute_if_absent(key)
if stored_value = _get(key) # fast non-blocking path for the most likely case
stored_value
else
@write_lock.synchronize { super }
end
end
def compute_if_present(key)
@write_lock.synchronize { super }
end
def compute(key)
@write_lock.synchronize { super }
end
def merge_pair(key, value)
@write_lock.synchronize { super }
end
def replace_pair(key, old_value, new_value)
@write_lock.synchronize { super }
end
def replace_if_exists(key, new_value)
@write_lock.synchronize { super }
end
def get_and_set(key, value)
@write_lock.synchronize { super }
end
def delete(key)
@write_lock.synchronize { super }
end
def delete_pair(key, value)
@write_lock.synchronize { super }
end
def clear
@write_lock.synchronize { super }
end
end
end
end
|