Skip to content

Commit c3b877a

Browse files
byrooteregon
authored andcommitted
Drop dependency on mutex_m
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.
1 parent 904c94d commit c3b877a

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

lib/concurrent-ruby/concurrent/collection/map/synchronized_map_backend.rb

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,74 +8,77 @@ module Collection
88
# @!visibility private
99
class SynchronizedMapBackend < NonConcurrentMapBackend
1010

11-
require 'mutex_m'
12-
include Mutex_m
13-
# WARNING: Mutex_m is a non-reentrant lock, so the synchronized methods are
14-
# not allowed to call each other.
11+
def initialize(*args, &block)
12+
super
13+
14+
# WARNING: Mutex is a non-reentrant lock, so the synchronized methods are
15+
# not allowed to call each other.
16+
@mutex = Mutex.new
17+
end
1518

1619
def [](key)
17-
synchronize { super }
20+
@mutex.synchronize { super }
1821
end
1922

2023
def []=(key, value)
21-
synchronize { super }
24+
@mutex.synchronize { super }
2225
end
2326

2427
def compute_if_absent(key)
25-
synchronize { super }
28+
@mutex.synchronize { super }
2629
end
2730

2831
def compute_if_present(key)
29-
synchronize { super }
32+
@mutex.synchronize { super }
3033
end
3134

3235
def compute(key)
33-
synchronize { super }
36+
@mutex.synchronize { super }
3437
end
3538

3639
def merge_pair(key, value)
37-
synchronize { super }
40+
@mutex.synchronize { super }
3841
end
3942

4043
def replace_pair(key, old_value, new_value)
41-
synchronize { super }
44+
@mutex.synchronize { super }
4245
end
4346

4447
def replace_if_exists(key, new_value)
45-
synchronize { super }
48+
@mutex.synchronize { super }
4649
end
4750

4851
def get_and_set(key, value)
49-
synchronize { super }
52+
@mutex.synchronize { super }
5053
end
5154

5255
def key?(key)
53-
synchronize { super }
56+
@mutex.synchronize { super }
5457
end
5558

5659
def delete(key)
57-
synchronize { super }
60+
@mutex.synchronize { super }
5861
end
5962

6063
def delete_pair(key, value)
61-
synchronize { super }
64+
@mutex.synchronize { super }
6265
end
6366

6467
def clear
65-
synchronize { super }
68+
@mutex.synchronize { super }
6669
end
6770

6871
def size
69-
synchronize { super }
72+
@mutex.synchronize { super }
7073
end
7174

7275
def get_or_default(key, default_value)
73-
synchronize { super }
76+
@mutex.synchronize { super }
7477
end
7578

7679
private
7780
def dupped_backend
78-
synchronize { super }
81+
@mutex.synchronize { super }
7982
end
8083
end
8184
end

0 commit comments

Comments
 (0)