Class: Tracemake::Slots

Inherits:
Object
  • Object
show all
Defined in:
lib/tracemake.rb

Overview

Manages slots for process visualization

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSlots

Returns a new instance of Slots.



49
50
51
52
53
# File 'lib/tracemake.rb', line 49

def initialize
  @slot_by_pid = {}
  @busy_slots = Set.new
  @number_of_slots = 0
end

Instance Attribute Details

#busy_slotsObject (readonly)

Returns the value of attribute busy_slots.



47
48
49
# File 'lib/tracemake.rb', line 47

def busy_slots
  @busy_slots
end

#number_of_slotsObject (readonly)

Returns the value of attribute number_of_slots.



47
48
49
# File 'lib/tracemake.rb', line 47

def number_of_slots
  @number_of_slots
end

#slot_by_pidObject (readonly)

Returns the value of attribute slot_by_pid.



47
48
49
# File 'lib/tracemake.rb', line 47

def slot_by_pid
  @slot_by_pid
end

Instance Method Details

#free(pid) ⇒ Object



71
72
73
74
75
76
# File 'lib/tracemake.rb', line 71

def free(pid)
  slot_id = @slot_by_pid[pid]
  return if slot_id.nil?
  @busy_slots.delete(slot_id)
  @slot_by_pid.delete(pid)
end

#schedule(pid) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/tracemake.rb', line 55

def schedule(pid)
  @number_of_slots.times do |i|
    unless @busy_slots.include?(i)
      @busy_slots.add(i)
      @slot_by_pid[pid] = i
      return i
    end
  end

  slot_id = @number_of_slots
  @number_of_slots += 1
  @busy_slots.add(slot_id)
  @slot_by_pid[pid] = slot_id
  slot_id
end