Class: DEBUGGER__::Mutex
Instance Method Summary collapse
-
#initialize ⇒ Mutex
constructor
A new instance of Mutex.
- #lock ⇒ Object
- #locked? ⇒ Boolean
- #unlock ⇒ Object
Constructor Details
#initialize ⇒ Mutex
Returns a new instance of Mutex.
23 24 25 26 27 |
# File 'lib/innate/debugger.rb', line 23 def initialize @locker = nil @waiting = [] @locked = false; end |
Instance Method Details
#lock ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/innate/debugger.rb', line 33 def lock return if Thread.critical return if @locker == Thread.current while (Thread.critical = true; @locked) @waiting.push Thread.current Thread.stop end @locked = true @locker = Thread.current Thread.critical = false self end |
#locked? ⇒ Boolean
29 30 31 |
# File 'lib/innate/debugger.rb', line 29 def locked? @locked end |
#unlock ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/innate/debugger.rb', line 46 def unlock return if Thread.critical return unless @locked unless @locker == Thread.current raise RuntimeError, "unlocked by other" end Thread.critical = true t = @waiting.shift @locked = false @locker = nil Thread.critical = false t.run if t self end |