WSF
WsfMultiThreadManager.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFMULTITHREADMANAGER_HPP
13#define WSFMULTITHREADMANAGER_HPP
14
15#include "wsf_export.h"
16
17#include <mutex>
18#include <queue>
19#include <vector>
20
21class UtInput;
22#include "WsfMover.hpp"
23#include "WsfPlatform.hpp"
24#include "WsfSensor.hpp"
25#include "WsfThread.hpp"
26#include "WsfThreadPool.hpp"
27
33
35{
36public:
37 WsfMultiThreadManager(unsigned int aNumberOfThreads,
38 double aBreakUpdateTime,
39 bool aDebugMultiThread,
40 WsfSimulation* aSimulationPtr);
41 virtual ~WsfMultiThreadManager();
42
43 void Initialize();
44
45 void Complete(double aSimTime);
46
48
49
50 void UpdatePlatforms(double aCurrentTime);
51 void UpdateSensors(double aCurrentTime);
52
53 bool BreakUpdate() { return mBreakUpdate; }
55
57
58
59 void AddPlatform(double aSimTime, WsfPlatform* aPlatformPtr);
60
61 inline void PlatformIntroduced(double aSimTime, WsfPlatform* aPlatformPtr) { AddPlatform(aSimTime, aPlatformPtr); }
62
63 void DeletePlatform(double aSimTime, WsfPlatform* aOldPlatformPtr);
64
65 inline void PlatformDeleted(double aSimTime, WsfPlatform* aOldPlatformPtr)
66 {
67 DeletePlatform(aSimTime, aOldPlatformPtr);
68 }
69
70 void TurnSensorOff(double aSimTime, WsfSensor* aSensorPtr);
71
72 void TurnSensorOn(double aSimTime, WsfSensor* aSensorPtr);
74
75protected:
77 {
78 public:
81 , mSimTime(0.0)
82 {
83 }
84
85 PlatformElement(size_t aPlatformIndex, double aSimTime)
86 : mPlatformIndex(aPlatformIndex)
87 , mSimTime(aSimTime)
88 {
89 }
90
91
93 double mSimTime;
94 };
95
97 {
98 public:
100 : mSensorPtr(nullptr)
101 , mSimTime(0.0)
102 , mNextUpdateTime(0.0)
103 {
104 }
105
106 SensorElement(WsfSensor* aSensorPtr, double aSimTime, double aNextUpdateTime)
107 : mSensorPtr(aSensorPtr)
108 , mSimTime(aSimTime)
109 , mNextUpdateTime(aNextUpdateTime)
110 {
111 }
112
113 bool operator<(const SensorElement& aRhs) const { return (mNextUpdateTime > aRhs.mNextUpdateTime); }
114
116 double mSimTime;
118 };
119
121
122 bool PlatformsQueued() { return (!mPlatformQueue.empty()); }
123 bool PopNextPlatformElement(PlatformElement& aPlatformElement);
124
125 bool SensorsQueued() { return (!mSensorQueue.empty()); }
126 bool PopNextSensorElement(SensorElement& aSensorElement);
128
131 {
132 public:
136
137 FunctionType DoWork() override;
138 FunctionType Pause() override { return AVAILABLE; }
139
141 bool NoWork();
142
144 };
145
147 {
148 public:
150 : mManagerPtr(aManagerPtr)
151 {
152 }
153
156 };
157
158public:
160
161private:
164
166 WsfMultiThreadManager& operator=(const WsfMultiThreadManager& aRhs) = delete;
167
168
169 WsfSimulation* mSimulationPtr;
170 std::queue<PlatformElement> mPlatformQueue;
171 std::priority_queue<SensorElement> mSensorQueue;
172
173 unsigned int mNumberOfThreads;
175
176 std::vector<size_t> mThreadedPlatforms;
177 std::vector<size_t> mNonThreadedPlatforms;
178
179 std::vector<WsfSensor*> mThreadedSensors;
180 std::vector<WsfSensor*> mNonThreadedSensors;
181
182 double mBreakUpdateTime;
183 bool mBreakUpdate;
184
185 bool mDebug;
186
187 std::recursive_mutex mMutex;
188};
189
190#endif
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
size_t mPlatformIndex
Definition WsfMultiThreadManager.hpp:92
PlatformElement(size_t aPlatformIndex, double aSimTime)
Definition WsfMultiThreadManager.hpp:85
PlatformElement()
Definition WsfMultiThreadManager.hpp:79
double mSimTime
Platform to update.
Definition WsfMultiThreadManager.hpp:93
double mNextUpdateTime
Definition WsfMultiThreadManager.hpp:117
SensorElement()
Definition WsfMultiThreadManager.hpp:99
SensorElement(WsfSensor *aSensorPtr, double aSimTime, double aNextUpdateTime)
Definition WsfMultiThreadManager.hpp:106
WsfSensor * mSensorPtr
Definition WsfMultiThreadManager.hpp:115
bool operator<(const SensorElement &aRhs) const
Definition WsfMultiThreadManager.hpp:113
double mSimTime
Definition WsfMultiThreadManager.hpp:116
Implementation of worker thread for updating a platform.
Definition WsfMultiThreadManager.hpp:131
SimulationUpdateThread(WsfMultiThreadManager *aManagerPtr)
Constructor and destructor.
Definition WsfMultiThreadManager.cpp:350
~SimulationUpdateThread() override
Definition WsfMultiThreadManager.hpp:135
WsfMultiThreadManager * mManagerPtr
Definition WsfMultiThreadManager.hpp:143
FunctionType Pause() override
Definition WsfMultiThreadManager.hpp:138
void AddPlatform(double aSimTime, WsfPlatform *aPlatformPtr)
Definition WsfMultiThreadManager.cpp:242
void DeletePlatform(double aSimTime, WsfPlatform *aOldPlatformPtr)
Definition WsfMultiThreadManager.cpp:266
bool BreakUpdate()
Definition WsfMultiThreadManager.hpp:53
void UpdatePlatforms(double aCurrentTime)
Definition WsfMultiThreadManager.cpp:89
void UpdateSensors(double aCurrentTime)
Definition WsfMultiThreadManager.cpp:145
bool PlatformsQueued()
Definition WsfMultiThreadManager.hpp:122
void PlatformDeleted(double aSimTime, WsfPlatform *aOldPlatformPtr)
Definition WsfMultiThreadManager.hpp:65
void Initialize()
Definition WsfMultiThreadManager.cpp:57
void Complete(double aSimTime)
Definition WsfMultiThreadManager.cpp:67
void PlatformIntroduced(double aSimTime, WsfPlatform *aPlatformPtr)
Definition WsfMultiThreadManager.hpp:61
WsfMultiThreadManager(unsigned int aNumberOfThreads, double aBreakUpdateTime, bool aDebugMultiThread, WsfSimulation *aSimulationPtr)
Constructor.
Definition WsfMultiThreadManager.cpp:27
bool SensorsQueued()
Definition WsfMultiThreadManager.hpp:125
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
Definition WsfSensor.hpp:92
The main controller for a simulation.
Definition WsfSimulation.hpp:109
Definition WsfThreadPool.hpp:40
WsfThread()=default
FunctionType
Definition WsfThread.hpp:26
@ AVAILABLE
Definition WsfThread.hpp:28
WsfMultiThreadManager * mManagerPtr
Definition WsfMultiThreadManager.hpp:154
SimulationUpdateThread * operator()() const
Definition WsfMultiThreadManager.cpp:406
ThreadFactory(WsfMultiThreadManager *aManagerPtr)
Definition WsfMultiThreadManager.hpp:149
Copyrights Multiple, All Rights Reserved