/
hash.rb
53 lines (40 loc) · 1.28 KB
/
hash.rb
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
require 'concurrent/utility/engine'
require 'concurrent/thread_safe/util'
module Concurrent
case
when Concurrent.on_cruby?
# @!macro [attach] concurrent_hash
#
# A thread-safe subclass of Hash. This version locks against the object
# itself for every method call, ensuring only one thread can be reading
# or writing at a time. This includes iteration methods like `#each`,
# which takes the lock repeatedly when reading an item.
#
# @see http://ruby-doc.org/core-2.2.0/Hash.html Ruby standard library `Hash`
class Hash < ::Hash
end
when Concurrent.on_jruby?
require 'jruby/synchronized'
# @!macro concurrent_hash
class Hash < ::Hash
include JRuby::Synchronized
end
when Concurrent.on_rbx?
require 'monitor'
require 'concurrent/thread_safe/util/data_structures'
# @!macro concurrent_hash
class Hash < ::Hash
end
ThreadSafe::Util.make_synchronized_on_rbx Concurrent::Hash
when Concurrent.on_truffleruby?
require 'concurrent/thread_safe/util/data_structures'
# @!macro concurrent_hash
class Hash < ::Hash
end
ThreadSafe::Util.make_synchronized_on_truffleruby Concurrent::Hash
else
warn 'Possibly unsupported Ruby implementation'
class Hash < ::Hash
end
end
end