Class: OrigenSim::Heartbeat

Inherits:
Thread
  • Object
show all
Defined in:
lib/origen_sim/heartbeat.rb

Constant Summary collapse

THREADSAFE =

Can’t use this with threads currently because Byebug pauses the sleep, during a breakpoint, which means that the simulator is killed. Currently working around via a forked process implementation instead whenever this is set to false.

false

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(simulation, socket) ⇒ Heartbeat

Returns a new instance of Heartbeat.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/origen_sim/heartbeat.rb', line 12

def initialize(simulation, socket)
  @simulation = simulation
  @socket = socket
  @continue = true
  super do
    while @continue
      begin
        socket.write("OK\n")
      rescue Errno::EPIPE => e
        exit 0 if simulation.ended
        if simulation.monitor_running?
          Origen.log.error 'Communication with the simulation monitor has been lost (though it seems to still be running)!'
        else
          Origen.log.error 'The simulation monitor has stopped unexpectedly!'
        end
        exit 1
      end
      sleep 5
    end
  end
end

Instance Attribute Details

#simulationObject (readonly)

Returns the value of attribute simulation.



4
5
6
# File 'lib/origen_sim/heartbeat.rb', line 4

def simulation
  @simulation
end

#socketObject (readonly)

Returns the value of attribute socket.



4
5
6
# File 'lib/origen_sim/heartbeat.rb', line 4

def socket
  @socket
end

Instance Method Details

#stopObject



34
35
36
# File 'lib/origen_sim/heartbeat.rb', line 34

def stop
  @continue = false
end