/usr/lib/ruby/vendor_ruby/rspec/support/reentrant_mutex.rb is in ruby-rspec-support 3.5.0c3e0m0s0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | module RSpec
module Support
# 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_support "mutex"
# :nocov:
end
end
end
|