Moved JOLT state tracking into ComponentThread::
This commit is contained in:
@@ -65,6 +65,9 @@ std::shared_ptr<ComponentThread> world =
|
||||
std::make_shared<ComponentThread>(ComponentThread::WORLD);
|
||||
}
|
||||
|
||||
// Initialize static state
|
||||
std::atomic<bool> ComponentThread::threadsHaveBeenJolted{false};
|
||||
|
||||
std::array<std::shared_ptr<ComponentThread>, ComponentThread::N_ITEMS>
|
||||
ComponentThread::componentThreads =
|
||||
{
|
||||
|
||||
@@ -120,6 +120,8 @@ public:
|
||||
boost::asio::io_service::work pause_work;
|
||||
std::atomic<bool> keepLooping;
|
||||
int pinnedCpuId;
|
||||
// Indicates whether all mind threads have been JOLTed at least once
|
||||
static std::atomic<bool> threadsHaveBeenJolted;
|
||||
|
||||
/* Always ensure that this is last so that the thread is spawned after
|
||||
* everything else is constructed.
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace smo {
|
||||
class Mind
|
||||
{
|
||||
public:
|
||||
Mind(void) : threadsHaveBeenJolted(false) {}
|
||||
Mind(void) {}
|
||||
|
||||
void initialize(void);
|
||||
void execute(void);
|
||||
@@ -26,9 +26,6 @@ public:
|
||||
|
||||
director::Director director;
|
||||
simulator::Simulator canvas;
|
||||
|
||||
private:
|
||||
bool threadsHaveBeenJolted;
|
||||
};
|
||||
|
||||
extern Mind mind;
|
||||
|
||||
+5
-5
@@ -22,9 +22,9 @@ void Mind::initialize()
|
||||
|
||||
/* Jolt the threads, then start them */
|
||||
ComponentThread::joltAllMindThreadsReq(
|
||||
[this]()
|
||||
[]()
|
||||
{
|
||||
this->threadsHaveBeenJolted = true;
|
||||
ComponentThread::threadsHaveBeenJolted.store(true);
|
||||
std::cout << "Mrntt: All mind threads JOLTed." << "\n";
|
||||
ComponentThread::startAllMindThreadsReq(
|
||||
[]()
|
||||
@@ -42,12 +42,12 @@ void Mind::finalizeReq(std::function<void()> callback)
|
||||
* otherwise they'll just enter their main loops and wait for control
|
||||
* messages from mrntt after processing the exit request.
|
||||
*/
|
||||
if (!threadsHaveBeenJolted)
|
||||
if (!ComponentThread::threadsHaveBeenJolted.load())
|
||||
{
|
||||
ComponentThread::joltAllMindThreadsReq(
|
||||
[this, callback]()
|
||||
[callback]()
|
||||
{
|
||||
this->threadsHaveBeenJolted = true;
|
||||
ComponentThread::threadsHaveBeenJolted.store(true);
|
||||
ComponentThread::exitAllMindThreadsReq(
|
||||
[callback]()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user