Mind: Use state variables to manage shutdown

We now allow the shutdown*Req() methods of Mind:: to return early
if their aspect of the object in question hasn't actually been
initialized.
This commit is contained in:
2025-09-13 18:59:44 -04:00
parent 25a9721f92
commit 1d3d929ddd
3 changed files with 23 additions and 16 deletions
+2 -1
View File
@@ -73,7 +73,8 @@ private:
* This flag ensures that JOLTing happens exactly once and provides * This flag ensures that JOLTing happens exactly once and provides
* a synchronization point for the entire system initialization. * a synchronization point for the entire system initialization.
*/ */
bool threadsHaveBeenJolted = false; bool threadsHaveBeenJolted = false,
bodyComponentInitialized = false;
// Collection of ComponentThread instances (excluding marionette) // Collection of ComponentThread instances (excluding marionette)
std::vector<std::shared_ptr<ComponentThread>> componentThreads; std::vector<std::shared_ptr<ComponentThread>> componentThreads;
-1
View File
@@ -218,7 +218,6 @@ void ComponentThread::marionetteMain(ComponentThread& self)
if (callShutdownSalmanoff) { if (callShutdownSalmanoff) {
shutdownSalmanoff(); shutdownSalmanoff();
} }
} }
} // namespace smo } // namespace smo
+17 -10
View File
@@ -125,21 +125,11 @@ public:
* otherwise they'll just enter their main loops and wait for control * otherwise they'll just enter their main loops and wait for control
* messages from mrntt after processing the exit request. * messages from mrntt after processing the exit request.
*/ */
if (!parent.threadsHaveBeenJolted)
{
parent.joltAllMindThreadsReq( parent.joltAllMindThreadsReq(
std::bind( std::bind(
&MindLifetimeMgmtOp::finalizeReq2, &MindLifetimeMgmtOp::finalizeReq2,
context.get(), context)); context.get(), context));
} }
else
{
parent.exitAllMindThreadsReq(
std::bind(
&MindLifetimeMgmtOp::finalizeReq3,
context.get(), context));
}
}
void finalizeReq2( void finalizeReq2(
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context [[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
@@ -269,6 +259,7 @@ public:
smo::AsynchronousLoop &results smo::AsynchronousLoop &results
) )
{ {
parent.bodyComponentInitialized = true;
std::cout << "Mrntt: attached " std::cout << "Mrntt: attached "
<< results.nSucceeded << " of " << results.nTotal << results.nSucceeded << " of " << results.nTotal
<< " sense devices." << "\n"; << " sense devices." << "\n";
@@ -347,6 +338,14 @@ void Mind::finalizeBodyReq(mindLifetimeMgmtOpCbFn callback)
+ ": Must be invoked by Mrntt thread"); + ": 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<FinalizeBodyReq>( auto request = std::make_shared<FinalizeBodyReq>(
*this, mrntt, callback); *this, mrntt, callback);
@@ -445,6 +444,14 @@ public:
void Mind::joltAllMindThreadsReq(mindThreadLifetimeMgmtOpCbFn callback) 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 // Create a counter to track when all threads have been jolted
auto request = std::make_shared<MindThreadLifetimeMgmtOp>( auto request = std::make_shared<MindThreadLifetimeMgmtOp>(
*this, componentThreads.size(), callback); *this, componentThreads.size(), callback);