Class: OsCtld::Devices::Lock
- Inherits:
-
Object
- Object
- OsCtld::Devices::Lock
- Includes:
- Singleton
- Defined in:
- lib/osctld/devices/lock.rb
Overview
Protect manipulation of device access trees
When managing group/container devices, it is often necessary to read or modify both parent and child groups. For the lack of a better mechanism, all operations on device access trees should be done only while holding this per-pool lock.
Instance Method Summary collapse
- #acquire(pool) ⇒ Object
-
#initialize ⇒ Lock
constructor
A new instance of Lock.
- #locked?(pool) ⇒ Boolean
- #mutex(pool) ⇒ Object protected
- #release(pool) ⇒ Object
- #sync(pool) ⇒ Object
Constructor Details
#initialize ⇒ Lock
Returns a new instance of Lock.
21 22 23 24 |
# File 'lib/osctld/devices/lock.rb', line 21 def initialize @main = Mutex.new @pools = {} end |
Instance Method Details
#acquire(pool) ⇒ Object
27 28 29 |
# File 'lib/osctld/devices/lock.rb', line 27 def acquire(pool) mutex(pool).lock end |
#locked?(pool) ⇒ Boolean
37 38 39 |
# File 'lib/osctld/devices/lock.rb', line 37 def locked?(pool) mutex(pool).owned? end |
#mutex(pool) ⇒ Object (protected)
59 60 61 62 63 64 65 66 67 |
# File 'lib/osctld/devices/lock.rb', line 59 def mutex(pool) @main.synchronize do if @pools.has_key?(pool.name) @pools[pool.name] else @pools[pool.name] = Mutex.new end end end |
#release(pool) ⇒ Object
32 33 34 |
# File 'lib/osctld/devices/lock.rb', line 32 def release(pool) mutex(pool).release end |