Class: RSpec::Support::Mutex
- Inherits:
-
Mutex
- Object
- Mutex
- RSpec::Support::Mutex
- Defined in:
- lib/rspec/support/mutex.rb,
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 Mutexes.
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.
18 19 20 21 22 23 |
# File 'lib/rspec/support/mutex.rb', line 18 def initialize @waiting = [] @locked = false @waiting.taint taint end |
Class Method Details
.new ⇒ Object
70 71 72 |
# File 'lib/rspec/support/reentrant_mutex.rb', line 70 def self.new NEW_MUTEX_METHOD.call end |
Instance Method Details
#lock ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/rspec/support/mutex.rb', line 26 def lock while Thread.critical = true && @locked @waiting.push Thread.current Thread.stop end @locked = true Thread.critical = false self end |
#synchronize ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/rspec/support/mutex.rb', line 46 def synchronize lock begin yield ensure unlock end end |
#unlock ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/rspec/support/mutex.rb', line 37 def unlock return unless @locked Thread.critical = true @locked = false wakeup_and_run_waiting_thread self end |