Class: RSpec::Support::ReentrantMutex Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | rspec-support/lib/rspec/support/reentrant_mutex.rb |
Overview
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 - 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/Mutex.html
dne - http://ruby-doc.org/core-1.9/Mutex.html
Class Method Summary
- .new ⇒ ReentrantMutex constructor Internal use only
Instance Method Summary
- #synchronize Internal use only
-
#enter
private
See additional method definition at line 35.
-
#exit
private
See additional method definition at line 40.
Instance Method Details
#enter (private)
See additional method definition at line 35.
# File 'rspec-support/lib/rspec/support/reentrant_mutex.rb', line 48
def enter @mutex.lock unless @mutex.owned? @count += 1 end
#exit (private)
See additional method definition at line 40.
# File 'rspec-support/lib/rspec/support/reentrant_mutex.rb', line 54
def exit unless @mutex.owned? raise ThreadError, "Attempt to unlock a mutex which is locked by another thread/fiber" end @count -= 1 @mutex.unlock if @count == 0 end