class Rbgo::ReentrantMutex
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/rbgo/reentrant_mutex.rb, line 26 def initialize @count_mutex = Mutex.new @counts = Hash.new(0) super end
Public Instance Methods
lock()
click to toggle source
Calls superclass method
# File lib/rbgo/reentrant_mutex.rb, line 44 def lock c = increase_count Thread.current super if c <= 1 self end
synchronize() { || ... }
click to toggle source
# File lib/rbgo/reentrant_mutex.rb, line 33 def synchronize raise ThreadError, 'Must be called with a block' unless block_given? begin lock yield ensure unlock end end
try_lock()
click to toggle source
Calls superclass method
# File lib/rbgo/reentrant_mutex.rb, line 59 def try_lock if owned? lock return true else ok = super increase_count Thread.current if ok return ok end end
unlock()
click to toggle source
Calls superclass method
# File lib/rbgo/reentrant_mutex.rb, line 50 def unlock c = decrease_count Thread.current if c <= 0 super delete_count Thread.current end self end
Private Instance Methods
decrease_count(thread)
click to toggle source
# File lib/rbgo/reentrant_mutex.rb, line 76 def decrease_count(thread) @count_mutex.synchronize { @counts[thread] -= 1 } end
delete_count(thread)
click to toggle source
# File lib/rbgo/reentrant_mutex.rb, line 80 def delete_count(thread) @count_mutex.synchronize { @counts.delete(thread) } end
increase_count(thread)
click to toggle source
# File lib/rbgo/reentrant_mutex.rb, line 72 def increase_count(thread) @count_mutex.synchronize { @counts[thread] += 1 } end