Module: DEBUGGER__::MultiProcessGroup

Defined in:
lib/debug/session.rb

Instance Method Summary collapse

Instance Method Details

#after_fork(child: true) ⇒ Object



2029
2030
2031
2032
2033
2034
2035
2036
2037
# File 'lib/debug/session.rb', line 2029

def after_fork child: true
  if child || !@lock_file
    @m = Mutex.new unless @m
    @m.synchronize do
      @lock_level = 0
      @lock_file = open(@lock_tempfile.path, 'w')
    end
  end
end

#info(msg) ⇒ Object



2039
2040
2041
# File 'lib/debug/session.rb', line 2039

def info msg
  DEBUGGER__.info "#{msg} (#{@lock_level})" #  #{caller.first(1).map{|bt| bt.sub(__dir__, '')}}"
end

#lockObject



2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
# File 'lib/debug/session.rb', line 2081

def lock
  unless trylock
    @m.synchronize do
      if locked?
        lock_level_up
      else
        info "Lock: block"
        @lock_file.flock(File::LOCK_EX)
        lock_level_up
      end
    end

    info "Lock: success"
  end
end

#locked?Boolean

Returns:

  • (Boolean)


2043
2044
2045
2046
# File 'lib/debug/session.rb', line 2043

def locked?
  # DEBUGGER__.debug{ "locked? #{@lock_level}" }
  @lock_level > 0
end

#multi_process!Object



2026
2027
# File 'lib/debug/session.rb', line 2026

def multi_process!
end

#sync(&b) ⇒ Object



2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
# File 'lib/debug/session.rb', line 2106

def sync &b
  info "sync"

  lock
  begin
    b.call if b
  ensure
    unlock
  end
end

#unlockObject



2097
2098
2099
2100
2101
2102
2103
2104
# File 'lib/debug/session.rb', line 2097

def unlock
  @m.synchronize do
    raise "lock file is not opened (#{@lock_file.inspect})" if @lock_file.closed?
    lock_level_down
    @lock_file.flock(File::LOCK_UN) unless locked?
    info "Unlocked"
  end
end