Class: Rbgo::RWMutex
- Inherits:
-
Object
- Object
- Rbgo::RWMutex
- Defined in:
- lib/rbgo/reentrant_rw_mutex.rb
Instance Method Summary collapse
-
#initialize ⇒ RWMutex
constructor
A new instance of RWMutex.
- #locked? ⇒ Boolean
- #owned? ⇒ Boolean
- #synchronize_r ⇒ Object
- #synchronize_w ⇒ Object
Constructor Details
#initialize ⇒ RWMutex
Returns a new instance of RWMutex.
7 8 9 10 11 12 |
# File 'lib/rbgo/reentrant_rw_mutex.rb', line 7 def initialize @lock_count = Hash.new(0) @mutex = ReentrantMutex.new @cond = ConditionVariable.new @status = :unlocked end |
Instance Method Details
#locked? ⇒ Boolean
20 21 22 23 24 25 26 27 28 |
# File 'lib/rbgo/reentrant_rw_mutex.rb', line 20 def locked? @mutex.synchronize do if @lock_count.empty? return false else return true end end end |
#owned? ⇒ Boolean
14 15 16 17 18 |
# File 'lib/rbgo/reentrant_rw_mutex.rb', line 14 def owned? @mutex.synchronize do @lock_count.key? Thread.current end end |
#synchronize_r ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rbgo/reentrant_rw_mutex.rb', line 30 def synchronize_r raise ThreadError, 'Must be called with a block' unless block_given? begin lock_r yield ensure unlock end end |
#synchronize_w ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rbgo/reentrant_rw_mutex.rb', line 41 def synchronize_w raise ThreadError, 'Must be called with a block' unless block_given? begin lock_w yield ensure unlock end end |