Class: RSpec::Support::Mutex

Inherits:
Mutex
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/mutex.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/reentrant_mutex.rb

Overview

On 1.9 and up, this is in core, so we just use the real one

Constant Summary collapse

NEW_MUTEX_METHOD =

If you mock Mutex.new you break our usage of Mutex, so instead we capture the original method to return Mutexs.

Mutex.method(:new)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMutex

Returns a new instance of Mutex.



16
17
18
19
20
21
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/mutex.rb', line 16

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

Class Method Details

.newObject



68
69
70
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/reentrant_mutex.rb', line 68

def self.new
  NEW_MUTEX_METHOD.call
end

Instance Method Details

#lockObject



24
25
26
27
28
29
30
31
32
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/mutex.rb', line 24

def lock
  while Thread.critical = true && @locked
    @waiting.push Thread.current
    Thread.stop
  end
  @locked = true
  Thread.critical = false
  self
end

#synchronizeObject



44
45
46
47
48
49
50
51
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/mutex.rb', line 44

def synchronize
  lock
  begin
    yield
  ensure
    unlock
  end
end

#unlockObject



35
36
37
38
39
40
41
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/mutex.rb', line 35

def unlock
  return unless @locked
  Thread.critical = true
  @locked = false
  wakeup_and_run_waiting_thread
  self
end