diff --git a/smocore/include/mind.h b/smocore/include/mind.h index 12ebccf..7999fd6 100644 --- a/smocore/include/mind.h +++ b/smocore/include/mind.h @@ -73,7 +73,8 @@ private: * This flag ensures that JOLTing happens exactly once and provides * a synchronization point for the entire system initialization. */ - bool threadsHaveBeenJolted = false; + bool threadsHaveBeenJolted = false, + bodyComponentInitialized = false; // Collection of ComponentThread instances (excluding marionette) std::vector> componentThreads; diff --git a/smocore/marionette/marionette.cpp b/smocore/marionette/marionette.cpp index a0e7fa6..8f8345b 100644 --- a/smocore/marionette/marionette.cpp +++ b/smocore/marionette/marionette.cpp @@ -218,7 +218,6 @@ void ComponentThread::marionetteMain(ComponentThread& self) if (callShutdownSalmanoff) { shutdownSalmanoff(); } - } } // namespace smo diff --git a/smocore/mind.cpp b/smocore/mind.cpp index c3731b7..60617ea 100644 --- a/smocore/mind.cpp +++ b/smocore/mind.cpp @@ -125,20 +125,10 @@ public: * otherwise they'll just enter their main loops and wait for control * messages from mrntt after processing the exit request. */ - if (!parent.threadsHaveBeenJolted) - { - parent.joltAllMindThreadsReq( - std::bind( - &MindLifetimeMgmtOp::finalizeReq2, - context.get(), context)); - } - else - { - parent.exitAllMindThreadsReq( - std::bind( - &MindLifetimeMgmtOp::finalizeReq3, - context.get(), context)); - } + parent.joltAllMindThreadsReq( + std::bind( + &MindLifetimeMgmtOp::finalizeReq2, + context.get(), context)); } void finalizeReq2( @@ -269,6 +259,7 @@ public: smo::AsynchronousLoop &results ) { + parent.bodyComponentInitialized = true; std::cout << "Mrntt: attached " << results.nSucceeded << " of " << results.nTotal << " sense devices." << "\n"; @@ -347,6 +338,14 @@ void Mind::finalizeBodyReq(mindLifetimeMgmtOpCbFn callback) + ": Must be invoked by Mrntt thread"); } + if (!bodyComponentInitialized) + { + std::cout << "Mrntt: Body component not initialized. " + << "Skipping finalization." << "\n"; + callback(true); + return; + } + auto request = std::make_shared( *this, mrntt, callback); @@ -445,6 +444,14 @@ public: void Mind::joltAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback) { + if (threadsHaveBeenJolted) + { + std::cout << "Mrntt: All mind threads already JOLTed. " + << "Skipping JOLT request." << "\n"; + callback(); + return; + } + // Create a counter to track when all threads have been jolted auto request = std::make_shared( *this, componentThreads.size(), callback);