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
* a synchronization point for the entire system initialization.
*/
bool threadsHaveBeenJolted = false;
bool threadsHaveBeenJolted = false,
bodyComponentInitialized = false;
// Collection of ComponentThread instances (excluding marionette)
std::vector<std::shared_ptr<ComponentThread>> componentThreads;
-1
View File
@@ -218,7 +218,6 @@ void ComponentThread::marionetteMain(ComponentThread& self)
if (callShutdownSalmanoff) {
shutdownSalmanoff();
}
}
} // namespace smo
+21 -14
View File
@@ -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<FinalizeBodyReq>(
*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<MindThreadLifetimeMgmtOp>(
*this, componentThreads.size(), callback);