Skip to content

Commit

Permalink
Drop dependency on mutex_m
Browse files Browse the repository at this point in the history
In Ruby 3.3.0 `mutex_m` is promoted to a default gem, which requires
to add it to the gemspec/gemfile.

But given how little usage it has in `concurrent-ruby` I think it might
as well just be not used.

Additionally including `Mutex_m` cause many undesirable methods to
be exposed, so simply using a Mutex instance variable is preferable.
  • Loading branch information
byroot authored and eregon committed Nov 20, 2023
1 parent 904c94d commit c3b877a
Showing 1 changed file with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,74 +8,77 @@ module Collection
# @!visibility private
class SynchronizedMapBackend < NonConcurrentMapBackend

require 'mutex_m'
include Mutex_m
# WARNING: Mutex_m is a non-reentrant lock, so the synchronized methods are
# not allowed to call each other.
def initialize(*args, &block)
super

# WARNING: Mutex is a non-reentrant lock, so the synchronized methods are
# not allowed to call each other.
@mutex = Mutex.new
end

def [](key)
synchronize { super }
@mutex.synchronize { super }
end

def []=(key, value)
synchronize { super }
@mutex.synchronize { super }
end

def compute_if_absent(key)
synchronize { super }
@mutex.synchronize { super }
end

def compute_if_present(key)
synchronize { super }
@mutex.synchronize { super }
end

def compute(key)
synchronize { super }
@mutex.synchronize { super }
end

def merge_pair(key, value)
synchronize { super }
@mutex.synchronize { super }
end

def replace_pair(key, old_value, new_value)
synchronize { super }
@mutex.synchronize { super }
end

def replace_if_exists(key, new_value)
synchronize { super }
@mutex.synchronize { super }
end

def get_and_set(key, value)
synchronize { super }
@mutex.synchronize { super }
end

def key?(key)
synchronize { super }
@mutex.synchronize { super }
end

def delete(key)
synchronize { super }
@mutex.synchronize { super }
end

def delete_pair(key, value)
synchronize { super }
@mutex.synchronize { super }
end

def clear
synchronize { super }
@mutex.synchronize { super }
end

def size
synchronize { super }
@mutex.synchronize { super }
end

def get_or_default(key, default_value)
synchronize { super }
@mutex.synchronize { super }
end

private
def dupped_backend
synchronize { super }
@mutex.synchronize { super }
end
end
end
Expand Down

0 comments on commit c3b877a

Please sign in to comment.