2 #include <boost/asio/thread_pool.hpp> 3 #include <boost/asio/post.hpp> 6 #include "MeasurementsBuffer.h" 8 #include "ThreadPool.h" 9 #include <SimulationCycleCallback.h> 11 #include <PySimulationCycleCallback.h> 66 std::shared_ptr<std::unique_lock<std::mutex>>
pauseLock =
nullptr;
105 std::shared_ptr<MeasurementsBuffer> mbuffer = NULL;
106 std::shared_ptr<SimulationCycleCallback> callback =
nullptr;
116 Simulation(
unsigned numThreads,
double deviceAccuracy);
140 void stop() {this->mStopped =
true;}
178 void setScanner(std::shared_ptr<Scanner> scanner);
virtual void onLegComplete()=0
Handle leg completion.
std::mutex mutex
Mutex to handle simulation pause and iterations on a multi threading context.
Definition: Simulation.h:55
bool isStopped()
Check if simulation is stopped (true) or not (false)
Definition: Simulation.h:198
bool finished
Flag specifying if simulation has finished (true) or not (false)
Definition: Simulation.h:103
Class representing a simulation.
Definition: Simulation.h:17
void setSimFrequency(size_t simFrequency)
Set simulation frequency.
Definition: Simulation.h:210
unsigned int mCurrentLegIndex
Index of leg at current simulation stage.
Definition: Simulation.h:88
virtual void doSimStep()
Perform computations for current simulation step.
Definition: Simulation.cpp:23
std::condition_variable condvar
Condition variable tu handle simulation iterations on a multi threading context.
Definition: Simulation.h:60
size_t simFrequency
Simulation frequency. If it is 0 then no pause is possible.
Definition: Simulation.h:50
bool mPaused
Flag specifying if the simulation has been paused (true) or not (false)
Definition: Simulation.h:77
void shutdown()
Handle simulation shutdown.
Definition: Simulation.cpp:52
size_t getSimFrequency()
Obtain simulation frequency.
Definition: Simulation.h:204
Class representing a thread pool to deal with multi threading tasks.
Definition: ThreadPool.h:14
double getSimSpeedFactor()
Obtain simulation speed factor.
Definition: Simulation.h:171
static const long NANOSECONDS_PER_SECOND
How many nanoseconds there are in a second.
Definition: Simulation.h:24
void pause(bool pause)
Pause or unpause the simulation.
Definition: Simulation.cpp:38
std::shared_ptr< Scanner > getScanner()
Obtain simulation scanner.
Definition: Simulation.h:184
void start()
Start the simmulation.
Definition: Simulation.cpp:94
void setScanner(std::shared_ptr< Scanner > scanner)
Set scanner for the simulation.
Definition: Simulation.cpp:63
bool exportToFile
Flag specifying if simulation output must be exported to a file (true) or not (false) ...
Definition: Simulation.h:94
thread_pool threadPool
Thread pool.
Definition: Simulation.h:34
void setSimSpeedFactor(double factor)
Set the simulation speed factor.
Definition: Simulation.cpp:78
long timeStart_ms
Time corresponding to simulation start (milliseconds)
Definition: Simulation.h:82
unsigned numSysThreads
Number of threads available in the system.
Definition: Simulation.h:29
void stop()
Stop the simulation.
Definition: Simulation.h:140
std::shared_ptr< std::unique_lock< std::mutex > > pauseLock
Shared pointer to the lock used to handle the mutex for simulation pause purposes.
Definition: Simulation.h:66
bool mStopped
Flag specifying if the simulation has been stopped (true) or not (false)
Definition: Simulation.h:72
Simulation(unsigned numThreads, double deviceAccuracy)
Simulation constructor.
Definition: Simulation.cpp:14
double mSimSpeedFactor
Simulation speed factor.
Definition: Simulation.h:39
bool exitAtEnd
Flag specifying if simulation must end when current leg has been completed (true) or not (false) ...
Definition: Simulation.h:99
bool isPaused()
Check if simulation is paused (true) or not (false)
Definition: Simulation.h:192
std::shared_ptr< Scanner > mScanner
Scanner used by the simulation.
Definition: Simulation.h:45