Class: N::SafeHash
Overview
SafeHash
A thread-safe hash. We use a sync object instead of a mutex, because it is re-entrant. An exclusive lock is needed when writing, a shared lock IS NEEDED when reading uses the delegator pattern to allow for multiple implementations!
Direct Known Subclasses
Instance Attribute Summary collapse
-
#sync ⇒ Object
readonly
Returns the value of attribute sync.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(delegator = nil) ⇒ SafeHash
constructor
gmosx: delegator is not used.
- #keys ⇒ Object
- #size ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(delegator = nil) ⇒ SafeHash
gmosx: delegator is not used.
25 26 27 |
# File 'lib/glue/hash.rb', line 25 def initialize(delegator = nil) @sync = ::Sync.new end |
Instance Attribute Details
#sync ⇒ Object (readonly)
Returns the value of attribute sync.
21 22 23 |
# File 'lib/glue/hash.rb', line 21 def sync @sync end |
Instance Method Details
#[](key) ⇒ Object
29 30 31 32 33 |
# File 'lib/glue/hash.rb', line 29 def [](key) return @sync.synchronize(::Sync::SH) { super } end |
#[]=(key, value) ⇒ Object
35 36 37 38 39 |
# File 'lib/glue/hash.rb', line 35 def []=(key, value) return @sync.synchronize(::Sync::EX) { super } end |
#clear ⇒ Object
47 48 49 50 51 |
# File 'lib/glue/hash.rb', line 47 def clear @sync.synchronize(::Sync::EX) { super } end |
#delete(key) ⇒ Object
41 42 43 44 45 |
# File 'lib/glue/hash.rb', line 41 def delete(key) return @sync.synchronize(::Sync::EX) { super } end |
#keys ⇒ Object
65 66 67 68 69 |
# File 'lib/glue/hash.rb', line 65 def keys return @sync.synchronize(::Sync::SH) { super } end |
#size ⇒ Object
53 54 55 56 57 |
# File 'lib/glue/hash.rb', line 53 def size return @sync.synchronize(::Sync::SH) { super } end |
#values ⇒ Object
59 60 61 62 63 |
# File 'lib/glue/hash.rb', line 59 def values return @sync.synchronize(::Sync::SH) { super } end |