Class: N::SafeArray
Overview
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.
20 21 22 |
# File 'lib/glue/array.rb', line 20 def initialize(delegator = nil) @sync = ::Sync.new() end |
Instance Attribute Details
#sync ⇒ Object (readonly)
Returns the value of attribute sync.
16 17 18 |
# File 'lib/glue/array.rb', line 16 def sync @sync end |
Instance Method Details
#<<(value) ⇒ Object
24 25 26 27 28 |
# File 'lib/glue/array.rb', line 24 def << (value) return @sync.synchronize(::Sync::SH) { super } end |
#[](key) ⇒ Object
36 37 38 39 40 |
# File 'lib/glue/array.rb', line 36 def [](key) return @sync.synchronize(::Sync::SH) { super } end |
#[]=(key, value) ⇒ Object
42 43 44 45 46 |
# File 'lib/glue/array.rb', line 42 def []=(key, value) return @sync.synchronize(::Sync::EX) { super } end |
#clear ⇒ Object
54 55 56 57 58 |
# File 'lib/glue/array.rb', line 54 def clear @sync.synchronize(::Sync::EX) { super } end |
#delete(key) ⇒ Object
48 49 50 51 52 |
# File 'lib/glue/array.rb', line 48 def delete(key) return @sync.synchronize(::Sync::EX) { super } end |
#delete_if(&block) ⇒ Object
30 31 32 33 34 |
# File 'lib/glue/array.rb', line 30 def delete_if(&block) return @sync.synchronize(::Sync::SH) { super } end |
#shift ⇒ Object
66 67 68 69 70 |
# File 'lib/glue/array.rb', line 66 def shift return @sync.synchronize(::Sync::EX) { super } end |
#size ⇒ Object
60 61 62 63 64 |
# File 'lib/glue/array.rb', line 60 def size return @sync.synchronize(::Sync::SH) { super } end |
#unshift(el) ⇒ Object
72 73 74 75 76 |
# File 'lib/glue/array.rb', line 72 def unshift(el) return @sync.synchronize(::Sync::EX) { super } end |