Sha256: 85f2e8e82eada90af361e9114c231028aa881232fa08ec328b1296dbc5ca5276

Contents?: true

Size: 456 Bytes

Versions: 10

Compression:

Stored size: 456 Bytes

Contents

# frozen_string_literal: true

module Polyphony
  # Implements mutex lock for synchronizing access to a shared resource
  class Mutex
    def initialize
      @waiting_fibers = Polyphony::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

10 entries across 10 versions & 1 rubygems

Version Path
polyphony-0.43.8 lib/polyphony/core/sync.rb
polyphony-0.43.6 lib/polyphony/core/sync.rb
polyphony-0.43.5 lib/polyphony/core/sync.rb
polyphony-0.43.4 lib/polyphony/core/sync.rb
polyphony-0.43.3 lib/polyphony/core/sync.rb
polyphony-0.43.2 lib/polyphony/core/sync.rb
polyphony-0.43.1 lib/polyphony/core/sync.rb
polyphony-0.43 lib/polyphony/core/sync.rb
polyphony-0.42 lib/polyphony/core/sync.rb
polyphony-0.41 lib/polyphony/core/sync.rb