Module: DEBUGGER__::MultiProcessGroup
Relationships & Source Files | |
Defined in: | lib/debug/session.rb |
Instance Attribute Summary
- #locked? ⇒ Boolean readonly
Instance Method Summary
- #after_fork(child: true)
- #info(msg)
- #lock
- #multi_process!
- #sync(&b)
- #unlock
- #lock_level_down private
- #lock_level_up private
- #trylock private
Instance Attribute Details
#locked? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/debug/session.rb', line 2043
def locked? # DEBUGGER__.debug{ "locked? #{@lock_level}" } @lock_level > 0 end
Instance Method Details
#after_fork(child: true)
[ GitHub ]# 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)
[ GitHub ]# File 'lib/debug/session.rb', line 2039
def info msg DEBUGGER__.info "#{msg} (#{@lock_level})" # #{caller.first(1).map{|bt| bt.sub(__dir__, '')}}" end
#lock
[ GitHub ]# 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
#lock_level_down (private)
[ GitHub ]# File 'lib/debug/session.rb', line 2053
private def lock_level_down raise unless @m.owned? raise "@lock_level underflow: #{@lock_level}" if @lock_level < 1 @lock_level -= 1 end
#lock_level_up (private)
[ GitHub ]# File 'lib/debug/session.rb', line 2048
private def lock_level_up raise unless @m.owned? @lock_level += 1 end
#multi_process!
[ GitHub ]# File 'lib/debug/session.rb', line 2026
def multi_process! end
#sync(&b)
[ GitHub ]#trylock (private)
[ GitHub ]# File 'lib/debug/session.rb', line 2059
private def trylock @m.synchronize do if locked? lock_level_up info "Try lock, already locked" true else case r = @lock_file.flock(File::LOCK_EX | File::LOCK_NB) when 0 lock_level_up info "Try lock with file: success" true when false info "Try lock with file: failed" false else raise "unknown flock result: #{r.inspect}" end end end end
#unlock
[ GitHub ]# 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