Sha256: 9fca0f9394ae3fd87ffcec381e8b2be5670b5e54ac94428b93519b0b68c1470e

Contents?: true

Size: 1.55 KB

Versions: 18

Compression:

Stored size: 1.55 KB

Contents

module RSpec
  module Core
    # 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
        begin
          t = @waiting.shift
          t.wakeup if t
        rescue ThreadError
          retry
        end
        Thread.critical = false
        begin
          t.run if t
        rescue ThreadError
          :noop
        end
        self
      end

      # @private
      def synchronize
        lock
        begin
          yield
        ensure
          unlock
        end
      end
    end unless defined?(::RSpec::Core::Mutex) # Avoid warnings for library wide checks spec
  end
end

Version data entries

18 entries across 18 versions & 9 rubygems

Version Path
swift-pyrite-0.1.1 vendor/bundle/ruby/2.0.0/gems/rspec-core-3.3.2/lib/rspec/core/mutex.rb
swift-pyrite-0.1.0 vendor/bundle/ruby/2.0.0/gems/rspec-core-3.3.2/lib/rspec/core/mutex.rb
mastermind_adeybee-0.1.4 vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/mutex.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/mutex.rb
mastermind_adeybee-0.1.3 vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/mutex.rb
mastermind_adeybee-0.1.2 vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/mutex.rb
mastermind_adeybee-0.1.1 vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/mutex.rb
sublimetheme-1.0.1 path/gems/rspec-core-3.3.2/lib/rspec/core/mutex.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/rspec-core-3.3.2/lib/rspec/core/mutex.rb
sublimetheme-1.0.0 path/gems/rspec-core-3.3.2/lib/rspec/core/mutex.rb
geminfo-0.1.0 path/gems/rspec-core-3.3.2/lib/rspec/core/mutex.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/rspec-core-3.3.1/lib/rspec/core/mutex.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/rspec-core-3.3.1/lib/rspec/core/mutex.rb
scoot-0.0.4 .bundle/gems/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/mutex.rb
rspec-core-3.3.2 lib/rspec/core/mutex.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/rspec-core-3.3.1/lib/rspec/core/mutex.rb
rspec-core-3.3.1 lib/rspec/core/mutex.rb
rspec-core-3.3.0 lib/rspec/core/mutex.rb