class RSpec::Support::Mutex

@private
Some formatting changes are made to appease the robot overlord:
understand (there’s quite a bit, actually) is left in.
Some methods we don’t need are deleted. Anything I don’t
So we’re transcribing/modifying it from
the test environment, causing tests to pass where they should fail.
We don’t want to load the stdlib, b/c this is a test tool, and can affect
On 1.8.7, it’s in the stdlib.

def self.new

def self.new
  NEW_MUTEX_METHOD.call
end

def initialize

def initialize
  @waiting = []
  @locked = false
  @waiting.taint
  taint
end

def lock

Other tags:
    Private: -
def lock
  while Thread.critical = true && @locked
    @waiting.push Thread.current
    Thread.stop
  end
  @locked = true
  Thread.critical = false
  self
end

def synchronize

Other tags:
    Private: -
def synchronize
  lock
  begin
    yield
  ensure
    unlock
  end
end

def unlock

Other tags:
    Private: -
def unlock
  return unless @locked
  Thread.critical = true
  @locked = false
  wakeup_and_run_waiting_thread
  self
end

def wakeup_and_run_waiting_thread

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