| Class | DEBUGGER__::Mutex |
| In: |
lib/debug.rb
|
| Parent: | Object |
# File lib/debug.rb, line 23
23: def initialize
24: @locker = nil
25: @waiting = []
26: @locked = false;
27: end
# File lib/debug.rb, line 33
33: def lock
34: return if Thread.critical
35: return if @locker == Thread.current
36: while (Thread.critical = true; @locked)
37: @waiting.push Thread.current
38: Thread.stop
39: end
40: @locked = true
41: @locker = Thread.current
42: Thread.critical = false
43: self
44: end
# File lib/debug.rb, line 46
46: def unlock
47: return if Thread.critical
48: return unless @locked
49: unless @locker == Thread.current
50: raise RuntimeError, "unlocked by other"
51: end
52: Thread.critical = true
53: t = @waiting.shift
54: @locked = false
55: @locker = nil
56: Thread.critical = false
57: t.run if t
58: self
59: end