Class: Verneuil::ProcessGroup

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

Overview

A group of processes identified by their root process.

Defined Under Namespace

Classes: Root

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ ProcessGroup

Returns a new instance of ProcessGroup.



4
5
6
7
# File 'lib/verneuil/process_group.rb', line 4

def initialize(root)
  @root = root
  @counter = 0
end

Instance Method Details

#halted?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/verneuil/process_group.rb', line 50

def halted?
  processes.all? { |p| p.halted? }
end

#processesObject



54
55
56
# File 'lib/verneuil/process_group.rb', line 54

def processes
  [Root.new(@root)] + @root.children.map { |p| p.group }
end

#runObject

Runs this process group until all processes have halted.



44
45
46
47
48
# File 'lib/verneuil/process_group.rb', line 44

def run
  until halted?
    step
  end
end

#stepObject

Steps one of the processes in this group once. Returns true if all child process groups have made one step.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/verneuil/process_group.rb', line 24

def step
  list = processes
  idx =  @counter % list.size
  
  if list[idx].step
    # Child tree has finished 'one round' of stepping, carry over 
    @counter += 1
  end
  
  # Should we return a carry to our parent?
  if @counter >= list.size
    @counter = 0
    return true
  end
  
  return false
end