Module: DEBUGGER__::MultiProcessGroup

Defined in:
lib/debug/session.rb

Instance Method Summary collapse

Instance Method Details

#after_fork(child: true) ⇒ Object



2073
2074
2075
2076
2077
2078
2079
2080
2081
# File 'lib/debug/session.rb', line 2073

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



2083
2084
2085
# File 'lib/debug/session.rb', line 2083

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

#lockObject



2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
# File 'lib/debug/session.rb', line 2125

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)


2087
2088
2089
2090
# File 'lib/debug/session.rb', line 2087

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

#multi_process!Object



2070
2071
# File 'lib/debug/session.rb', line 2070

def multi_process!
end

#sync(&b) ⇒ Object



2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
# File 'lib/debug/session.rb', line 2150

def sync &b
  info "sync"

  lock
  begin
    b.call if b
  ensure
    unlock
  end
end

#unlockObject



2141
2142
2143
2144
2145
2146
2147
2148
# File 'lib/debug/session.rb', line 2141

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