Sha256: b4ecaad712a0565789bbc366352b41debd36e34b1a062c960650959a937887bf

Contents?: true

Size: 1.7 KB

Versions: 3374

Compression:

Stored size: 1.7 KB

Contents

module RSpec
  module Support
    # On 1.8.7, it's in the stdlib.
    # We don't want to load the stdlib, b/c this is a test tool, and can affect
    # the test environment, causing tests to pass where they should fail.
    #
    # So we're transcribing/modifying it from
    # https://github.com/ruby/ruby/blob/v1_8_7_374/lib/thread.rb#L56
    # Some methods we don't need are deleted. Anything I don't
    # understand (there's quite a bit, actually) is left in.
    #
    # Some formatting changes are made to appease the robot overlord:
    #   https://travis-ci.org/rspec/rspec-core/jobs/54410874
    # @private
    class Mutex
      def initialize
        @waiting = []
        @locked = false
        @waiting.taint
        taint
      end

      # @private
      def lock
        while Thread.critical = true && @locked
          @waiting.push Thread.current
          Thread.stop
        end
        @locked = true
        Thread.critical = false
        self
      end

      # @private
      def unlock
        return unless @locked
        Thread.critical = true
        @locked = false
        wakeup_and_run_waiting_thread
        self
      end

      # @private
      def synchronize
        lock
        begin
          yield
        ensure
          unlock
        end
      end

    private

      def wakeup_and_run_waiting_thread
        begin
          t = @waiting.shift
          t.wakeup if t
        rescue ThreadError
          retry
        end
        Thread.critical = false
        begin
          t.run if t
        rescue ThreadError
          :noop
        end
      end

      # Avoid warnings for library wide checks spec
    end unless defined?(::RSpec::Support::Mutex) || defined?(::Mutex)
  end
end

Version data entries

3,374 entries across 3,373 versions & 29 rubygems

Version Path
moneykit-0.1.15 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
moneykit-0.1.14 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
moneykit-0.1.13 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
moneykit-0.1.12 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
moneykit-0.1.11 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
moneykit-0.1.10 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
moneykit-0.1.9 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
moneykit-0.1.6 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
cybrid_api_id_ruby-0.113.118 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
cybrid_api_organization_ruby-0.113.118 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
cybrid_api_bank_ruby-0.113.118 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
cybrid_api_bank_ruby-0.113.117 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
cybrid_api_id_ruby-0.113.117 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
cybrid_api_organization_ruby-0.113.117 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
cybrid_api_bank_ruby-0.113.116 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
cybrid_api_id_ruby-0.113.116 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
cybrid_api_organization_ruby-0.113.116 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
cybrid_api_bank_ruby-0.113.115 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb
cybrid_api_organization_ruby-0.113.115 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/mutex.rb