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:
@@ -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;
|
||||
|
||||
|
||||
@@ -218,7 +218,6 @@ void ComponentThread::marionetteMain(ComponentThread& self)
|
||||
if (callShutdownSalmanoff) {
|
||||
shutdownSalmanoff();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace smo
|
||||
|
||||
+21
-14
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user