class ReentrantMutex
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/reentrant_mutex.rb, line 2 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/reentrant_mutex.rb, line 20 def lock c = increase_count Thread.current super if c <= 1 end
synchronize() { || ... }
click to toggle source
# File lib/reentrant_mutex.rb, line 9 def synchronize raise ThreadError, 'Must be called with a block' unless block_given? begin lock yield ensure unlock end end
unlock()
click to toggle source
Calls superclass method
# File lib/reentrant_mutex.rb, line 25 def unlock c = decrease_count Thread.current if c <= 0 super delete_count Thread.current end end
Private Instance Methods
decrease_count(thread)
click to toggle source
# File lib/reentrant_mutex.rb, line 39 def decrease_count(thread) @count_mutex.synchronize { @counts[thread] -= 1 } end
delete_count(thread)
click to toggle source
# File lib/reentrant_mutex.rb, line 43 def delete_count(thread) @count_mutex.synchronize { @counts.delete(thread) } end
increase_count(thread)
click to toggle source
# File lib/reentrant_mutex.rb, line 35 def increase_count(thread) @count_mutex.synchronize { @counts[thread] += 1 } end