module Salus::Lockable
Based on code from github.com/ruby-concurrency/concurrent-ruby/
Public Instance Methods
broadcast()
click to toggle source
# File lib/salus/thread/lockable.rb, line 17 def broadcast __condition.broadcast self end
signal()
click to toggle source
# File lib/salus/thread/lockable.rb, line 12 def signal __condition.signal self end
synchronize() { || ... }
click to toggle source
# File lib/salus/thread/lockable.rb, line 4 def synchronize if __lock.owned? yield else __lock.synchronize { yield } end end
wait(timeout=nil)
click to toggle source
# File lib/salus/thread/lockable.rb, line 37 def wait(timeout=nil) __wait(timeout) end
wait_until(timeout=nil, &condition)
click to toggle source
# File lib/salus/thread/lockable.rb, line 22 def wait_until(timeout=nil, &condition) if timeout wait_until = MonotonicTime.get + timeout loop do now = MonotonicTime.get res = condition.call return res if now >= wait_until || res __wait(wait_until - now) end else __wait(timeout) until condition.call true end end
Protected Instance Methods
__condition()
click to toggle source
# File lib/salus/thread/lockable.rb, line 47 def __condition @__condition__ ||= ::ConditionVariable.new @__condition__ end
__lock()
click to toggle source
# File lib/salus/thread/lockable.rb, line 42 def __lock @__lock__ ||= ::Mutex.new @__lock__ end
__wait(timeout=nil)
click to toggle source
# File lib/salus/thread/lockable.rb, line 52 def __wait(timeout=nil) __condition.wait __lock, timeout end