Sha256: bcdf1daa9198eeeba4507b13686fa39a4ffd9daf9190cdad42c5c87e07570979
Contents?: true
Size: 450 Bytes
Versions: 3
Compression:
Stored size: 450 Bytes
Contents
# frozen_string_literal: true module Polyphony # Implements mutex lock for synchronizing access to a shared resource class Mutex def initialize @waiting_fibers = Gyro::Queue.new end def synchronize fiber = Fiber.current @waiting_fibers << fiber suspend if @waiting_fibers.size > 1 yield ensure @waiting_fibers.delete(fiber) @waiting_fibers.first&.schedule snooze end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
polyphony-0.40 | lib/polyphony/core/sync.rb |
polyphony-0.39 | lib/polyphony/core/sync.rb |
polyphony-0.38 | lib/polyphony/core/sync.rb |