Class: DEBUGGER__::Mutex

Inherits:
Object show all
Defined in:
lib/innate/debugger.rb

Instance Method Summary collapse

Constructor Details

#initializeMutex

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

#lockObject



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

Returns:

  • (Boolean)


29
30
31
# File 'lib/innate/debugger.rb', line 29

def locked?
  @locked
end

#unlockObject



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