Class: RSpec::Support::Mutex
- 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
-
#initialize ⇒ Mutex
constructor
A new instance of Mutex.
- #lock ⇒ Object
- #synchronize ⇒ Object
- #unlock ⇒ Object
Constructor Details
#initialize ⇒ Mutex
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
.new ⇒ Object
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
#lock ⇒ Object
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 |
#synchronize ⇒ Object
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 |
#unlock ⇒ Object
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 |