Sha256: bd9fc565365a96574da4260eca6f20f2b03ad7dad6e234b3677fbfb787639712
Contents?: true
Size: 482 Bytes
Versions: 3
Compression:
Stored size: 482 Bytes
Contents
# frozen_string_literal: true module Polyphony # Implements mutex lock for synchronizing access to a shared resource class Mutex def initialize @store = Queue.new @store << :token end def synchronize return yield if @holding_fiber == Fiber.current begin token = @store.shift @holding_fiber = Fiber.current yield ensure @holding_fiber = nil @store << token if token end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
polyphony-0.44.0 | lib/polyphony/core/sync.rb |
polyphony-0.43.11 | lib/polyphony/core/sync.rb |
polyphony-0.43.10 | lib/polyphony/core/sync.rb |