Class: N::SafeArray
- Inherits:
-
Array
- Object
- Array
- N::SafeArray
- Defined in:
- lib/n/utils/array.rb
Overview
SafeArray
A thread-safe array. 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
Instance Attribute Summary collapse
-
#sync ⇒ Object
readonly
Returns the value of attribute sync.
Instance Method Summary collapse
- #<<(value) ⇒ Object
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #delete_if(&block) ⇒ Object
-
#initialize(delegator = nil) ⇒ SafeArray
constructor
gmosx: delegator is not used.
- #shift ⇒ Object
- #size ⇒ Object
- #unshift(el) ⇒ Object
Constructor Details
#initialize(delegator = nil) ⇒ SafeArray
gmosx: delegator is not used.
32 33 34 |
# File 'lib/n/utils/array.rb', line 32 def initialize(delegator = nil) @sync = ::Sync.new() end |
Instance Attribute Details
#sync ⇒ Object (readonly)
Returns the value of attribute sync.
28 29 30 |
# File 'lib/n/utils/array.rb', line 28 def sync @sync end |
Instance Method Details
#<<(value) ⇒ Object
36 37 38 39 40 |
# File 'lib/n/utils/array.rb', line 36 def << (value) return @sync.synchronize(::Sync::SH) { super } end |
#[](key) ⇒ Object
48 49 50 51 52 |
# File 'lib/n/utils/array.rb', line 48 def [](key) return @sync.synchronize(::Sync::SH) { super } end |
#[]=(key, value) ⇒ Object
54 55 56 57 58 |
# File 'lib/n/utils/array.rb', line 54 def []=(key, value) return @sync.synchronize(::Sync::EX) { super } end |
#clear ⇒ Object
66 67 68 69 70 |
# File 'lib/n/utils/array.rb', line 66 def clear @sync.synchronize(::Sync::EX) { super } end |
#delete(key) ⇒ Object
60 61 62 63 64 |
# File 'lib/n/utils/array.rb', line 60 def delete(key) return @sync.synchronize(::Sync::EX) { super } end |
#delete_if(&block) ⇒ Object
42 43 44 45 46 |
# File 'lib/n/utils/array.rb', line 42 def delete_if(&block) return @sync.synchronize(::Sync::SH) { super } end |
#shift ⇒ Object
78 79 80 81 82 |
# File 'lib/n/utils/array.rb', line 78 def shift return @sync.synchronize(::Sync::EX) { super } end |
#size ⇒ Object
72 73 74 75 76 |
# File 'lib/n/utils/array.rb', line 72 def size return @sync.synchronize(::Sync::SH) { super } end |
#unshift(el) ⇒ Object
84 85 86 87 88 |
# File 'lib/n/utils/array.rb', line 84 def unshift(el) return @sync.synchronize(::Sync::EX) { super } end |