Module: DEBUGGER__::MultiProcessGroup

Defined in:
lib/debug/session.rb

Instance Method Summary collapse

Instance Method Details

#after_fork(child: true) ⇒ Object



1882
1883
1884
1885
1886
1887
1888
# File 'lib/debug/session.rb', line 1882

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

#info(msg) ⇒ Object



1890
1891
1892
# File 'lib/debug/session.rb', line 1890

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

#lockObject



1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
# File 'lib/debug/session.rb', line 1932

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)


1894
1895
1896
1897
# File 'lib/debug/session.rb', line 1894

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

#multi_process!Object



1879
1880
# File 'lib/debug/session.rb', line 1879

def multi_process!
end

#sync(&b) ⇒ Object



1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
# File 'lib/debug/session.rb', line 1957

def sync &b
  info "sync"

  lock
  begin
    b.call if b
  ensure
    unlock
  end
end

#unlockObject



1948
1949
1950
1951
1952
1953
1954
1955
# File 'lib/debug/session.rb', line 1948

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