Sha256: 428406b7634deaa751b0da9e6ffed1d284fe3786fd554ea8cccaf5c50fe64dad

Contents?: true

Size: 1.7 KB

Versions: 1938

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 formating 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

1,938 entries across 1,853 versions & 97 rubygems

Version Path
mux_ruby-3.20.0 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.11.0/lib/rspec/support/mutex.rb
mux_ruby-3.19.0 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.11.0/lib/rspec/support/mutex.rb
mux_ruby-3.18.0 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.11.0/lib/rspec/support/mutex.rb
mux_ruby-3.17.0 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.11.0/lib/rspec/support/mutex.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.10.2/lib/rspec/support/mutex.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.10.2/lib/rspec/support/mutex.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.10.2/lib/rspec/support/mutex.rb
mux_ruby-3.15.0 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.11.0/lib/rspec/support/mutex.rb
avalara_sdk-24.2.29 vendor/bundle/ruby/2.7.0/gems/rspec-support-3.11.0/lib/rspec/support/mutex.rb
mux_ruby-3.14.0 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.11.0/lib/rspec/support/mutex.rb
mux_ruby-3.13.0 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.11.0/lib/rspec/support/mutex.rb
mux_ruby-3.12.0 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.11.0/lib/rspec/support/mutex.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rspec-support-3.11.0/lib/rspec/support/mutex.rb
mux_ruby-3.11.1 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.11.0/lib/rspec/support/mutex.rb
mux_ruby-3.11.0 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.11.0/lib/rspec/support/mutex.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rspec-support-3.11.0/lib/rspec/support/mutex.rb
primary_connect_proto-0.20.0 vendor/bundle/ruby/2.6.0/gems/rspec-support-3.10.3/lib/rspec/support/mutex.rb
primary_connect_proto-0.20.0 vendor/bundle/ruby/3.0.0/gems/rspec-support-3.10.3/lib/rspec/support/mutex.rb
mux_ruby-3.9.0 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.11.0/lib/rspec/support/mutex.rb
primary_connect_proto-0.19.0 vendor/bundle/ruby/3.0.0/gems/rspec-support-3.10.3/lib/rspec/support/mutex.rb