class Polyphony::Mutex
Implements mutex lock for synchronizing access to a shared resource
Public Class Methods
new()
click to toggle source
# File lib/polyphony/core/sync.rb, line 6 def initialize @store = Queue.new @store << :token end
Public Instance Methods
conditional_reacquire()
click to toggle source
# File lib/polyphony/core/sync.rb, line 34 def conditional_reacquire @token = @store.shift @holding_fiber = Fiber.current end
conditional_release()
click to toggle source
# File lib/polyphony/core/sync.rb, line 28 def conditional_release @store << @token @token = nil @holding_fiber = nil end
locked?()
click to toggle source
# File lib/polyphony/core/sync.rb, line 43 def locked? @holding_fiber end
owned?()
click to toggle source
# File lib/polyphony/core/sync.rb, line 39 def owned? @holding_fiber == Fiber.current end
synchronize() { || ... }
click to toggle source
# File lib/polyphony/core/sync.rb, line 11 def synchronize(&block) return yield if @holding_fiber == Fiber.current synchronize_not_holding(&block) end
synchronize_not_holding() { || ... }
click to toggle source
# File lib/polyphony/core/sync.rb, line 17 def synchronize_not_holding @token = @store.shift begin @holding_fiber = Fiber.current yield ensure @holding_fiber = nil @store << @token if @token end end