Sha256: 6b928409f6fa5a3ed7ad74cc37774786234e69b9a696d7c03c20b478df3f6f31

Contents?: true

Size: 1.22 KB

Versions: 18

Compression:

Stored size: 1.22 KB

Contents

module RSpec
  module Core
    # Allows a thread to lock out other threads from a critical section of code,
    # while allowing the thread with the lock to reenter that section.
    #
    # Based on Monitor as of 2.2 - https://github.com/ruby/ruby/blob/eb7ddaa3a47bf48045d26c72eb0f263a53524ebc/lib/monitor.rb#L9
    #
    # Depends on Mutex, but Mutex is only available as part of core since 1.9.1:
    #   exists - http://ruby-doc.org/core-1.9.1/Mutex.html
    #   dne    - http://ruby-doc.org/core-1.9.0/Mutex.html
    #
    # @private
    class ReentrantMutex
      def initialize
        @owner = nil
        @count = 0
        @mutex = Mutex.new
      end

      def synchronize
        enter
        yield
      ensure
        exit
      end

    private

      def enter
        @mutex.lock if @owner != Thread.current
        @owner = Thread.current
        @count += 1
      end

      def exit
        @count -= 1
        return unless @count == 0
        @owner = nil
        @mutex.unlock
      end
    end

    if defined? ::Mutex
      # On 1.9 and up, this is in core, so we just use the real one
      Mutex = ::Mutex
    else # For 1.8.7
      # :nocov:
      RSpec::Support.require_rspec_core "mutex"
      # :nocov:
    end
  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/reentrant_mutex.rb
swift-pyrite-0.1.0 vendor/bundle/ruby/2.0.0/gems/rspec-core-3.3.2/lib/rspec/core/reentrant_mutex.rb
mastermind_adeybee-0.1.4 vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/reentrant_mutex.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/reentrant_mutex.rb
mastermind_adeybee-0.1.3 vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/reentrant_mutex.rb
mastermind_adeybee-0.1.2 vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/reentrant_mutex.rb
mastermind_adeybee-0.1.1 vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/reentrant_mutex.rb
sublimetheme-1.0.1 path/gems/rspec-core-3.3.2/lib/rspec/core/reentrant_mutex.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/rspec-core-3.3.2/lib/rspec/core/reentrant_mutex.rb
sublimetheme-1.0.0 path/gems/rspec-core-3.3.2/lib/rspec/core/reentrant_mutex.rb
geminfo-0.1.0 path/gems/rspec-core-3.3.2/lib/rspec/core/reentrant_mutex.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/rspec-core-3.3.1/lib/rspec/core/reentrant_mutex.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/rspec-core-3.3.1/lib/rspec/core/reentrant_mutex.rb
scoot-0.0.4 .bundle/gems/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/reentrant_mutex.rb
rspec-core-3.3.2 lib/rspec/core/reentrant_mutex.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/rspec-core-3.3.1/lib/rspec/core/reentrant_mutex.rb
rspec-core-3.3.1 lib/rspec/core/reentrant_mutex.rb
rspec-core-3.3.0 lib/rspec/core/reentrant_mutex.rb