What’s New in the Pulse Physiology Engine 4.4.0
×
PulseEngineThreadController.h
1/* Distributed under the Apache License, Version 2.0.
2 See accompanying NOTICE file for details.*/
3
4#pragma once
5
6#include "engine/CommonDefs.h"
7#include <thread>
8
9class PULSE_DECL PulseEngineThreadController : public Loggable
10{
11public:
12 PulseEngineThreadController(const std::string& logFilename) : Loggable(logFilename) {}
13 virtual ~PulseEngineThreadController() = default;
14
15 class PULSE_DECL Simulation
16 {
18 public:
19 Simulation(Logger& status);
20 virtual ~Simulation() = default;
21
22 virtual bool Execute() = 0;
23
24 bool StopRequested() const { return m_StopRequested; }
25
26 protected:
27
28 // Logic used to stop simulating, such as patient death
29 // Set m_StopRequested to true to request the stop
30 // When a stop is requested, AdvanceAndTrack will no longer advance and track.
31 virtual void StopCheck() { }
32
33 Logger& m_Status; // Only used to pass status to controller log the as simulation is executing
34 bool m_StopRequested = false;
35 std::string m_BaseName;
36 std::string m_OutputsDir = "";
37 std::string m_csvFilename = "";
38 std::string m_logFilename = "";
39 std::vector<std::string> m_Reports; // Anything you want to tell the controller after a simulation
40 std::unique_ptr<PhysiologyEngine> m_Pulse = nullptr;
41 };
42
43 bool Run(const std::vector<Simulation*>& PulseEngineThreads);
44
45protected:
46 void ControllerLoop();
47 Simulation* GetNextSimulation();
48 void Complete(Simulation*);
49
50 size_t m_TotalSimulations=0;
51 std::mutex m_Mutex;
52 std::vector<Simulation*> m_Remaining;
53 std::vector<std::thread> m_Threads;
54};
Definition: Logger.h:23
Definition: Logger.h:71
Definition: PulseEngineThreadController.h:16
std::vector< std::string > m_Reports
Definition: PulseEngineThreadController.h:39
virtual void StopCheck()
Definition: PulseEngineThreadController.h:31
friend PulseEngineThreadController
Definition: PulseEngineThreadController.h:17
std::string m_BaseName
Definition: PulseEngineThreadController.h:35
bool StopRequested() const
Definition: PulseEngineThreadController.h:24
Logger & m_Status
Definition: PulseEngineThreadController.h:33
Definition: PulseEngineThreadController.h:10
std::vector< std::thread > m_Threads
Definition: PulseEngineThreadController.h:53
std::vector< Simulation * > m_Remaining
Definition: PulseEngineThreadController.h:52
PulseEngineThreadController(const std::string &logFilename)
Definition: PulseEngineThreadController.h:12
virtual ~PulseEngineThreadController()=default
std::mutex m_Mutex
Definition: PulseEngineThreadController.h:51

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.