CompThr: Delete shutdownInd & exceptionInd
We no longer need them because we now have mrntt::mrntt.finalizeReq(), which does a more holistic job of shutting down Marionette (and thus, ultimately, Salmanoff).
This commit is contained in:
+6
-114
@@ -94,7 +94,11 @@ void MindThread::main(MindThread& self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sendExceptionInd)
|
if (sendExceptionInd)
|
||||||
{ mrntt::thread->exceptionInd(self.shared_from_this()); }
|
{
|
||||||
|
mrntt::mrntt.finalizeReq(
|
||||||
|
std::bind(
|
||||||
|
&mrntt::marionetteFinalizeReqCb, std::placeholders::_1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << self.name << ":" << __func__ << ": Exited event loop" << "\n";
|
std::cout << self.name << ":" << __func__ << ": Exited event loop" << "\n";
|
||||||
@@ -304,119 +308,7 @@ void MindThread::resumeThreadReq(threadLifetimeMgmtOpCbFn callback)
|
|||||||
|
|
||||||
pause_io_service.post(
|
pause_io_service.post(
|
||||||
std::bind(
|
std::bind(
|
||||||
&ThreadLifetimeMgmtOp::resumeThreadReq1,
|
&ThreadLifetimeMgmtOp::resumeThreadReq1_posted,
|
||||||
request.get(), request));
|
|
||||||
}
|
|
||||||
|
|
||||||
class MindThread::MindShutdownIndOp
|
|
||||||
: public TargetedAsynchronousContinuation<mindShutdownIndOpCbFn>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MindShutdownIndOp(
|
|
||||||
const std::shared_ptr<ComponentThread> &caller,
|
|
||||||
mindShutdownIndOpCbFn callback)
|
|
||||||
: TargetedAsynchronousContinuation<mindShutdownIndOpCbFn>(
|
|
||||||
caller, callback)
|
|
||||||
{}
|
|
||||||
|
|
||||||
public:
|
|
||||||
void mindShutdownInd1_exception(
|
|
||||||
[[maybe_unused]] std::shared_ptr<MindShutdownIndOp> context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
std::cerr << "Mrntt: Exception occurred: in thread "
|
|
||||||
<< context->caller->name << ". Killing Salmanoff." << "\n";
|
|
||||||
|
|
||||||
/** EXPLANATION:
|
|
||||||
* An exception has occurred in one of a mind's threads. We need to
|
|
||||||
* shut down all of that particular mind's threads.
|
|
||||||
*/
|
|
||||||
smo::mind::globalMind->finalizeReq(
|
|
||||||
std::bind(
|
|
||||||
&MindShutdownIndOp::mindShutdownInd2,
|
|
||||||
context.get(), context));
|
|
||||||
}
|
|
||||||
|
|
||||||
void mindShutdownInd1_userShutdown(
|
|
||||||
[[maybe_unused]] std::shared_ptr<MindShutdownIndOp> context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
std::cerr << "Mrntt: User requested shutdown (SIGINT)."
|
|
||||||
<< " Killing Salmanoff." << "\n";
|
|
||||||
|
|
||||||
/** EXPLANATION:
|
|
||||||
* A user has requested a shutdown. We need to shut down all of the
|
|
||||||
* threads in all running Minds.
|
|
||||||
*
|
|
||||||
* FIXME:
|
|
||||||
* So this should ideally be a loop
|
|
||||||
* through all running Minds, calling finalizeReq on each one.
|
|
||||||
*/
|
|
||||||
smo::mind::globalMind->finalizeReq(
|
|
||||||
std::bind(
|
|
||||||
&MindShutdownIndOp::mindShutdownInd2,
|
|
||||||
context.get(), context));
|
|
||||||
}
|
|
||||||
|
|
||||||
void mindShutdownInd2(
|
|
||||||
[[maybe_unused]] std::shared_ptr<MindShutdownIndOp> context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
std::cout << "Mrntt: About to exit marionette loop." << "\n";
|
|
||||||
/** FIXME:
|
|
||||||
* When we eventually support multiple minds, we should remove this
|
|
||||||
* since it causes marionette to exit, even if there are other minds
|
|
||||||
* that are still running.
|
|
||||||
*/
|
|
||||||
smo::mrntt::exitMarionetteLoop();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/* This shouldn't take a callback because the caller shouldn't expect to
|
|
||||||
* Mrntt to send a reply signal to it. Sending this Indication means that
|
|
||||||
* Mrntt will send the calling thread an exitThreadReq. When the caller
|
|
||||||
* processes that exitThreadReq(), the caller will exit its event loop and then
|
|
||||||
* terminate.
|
|
||||||
*
|
|
||||||
* Even if Mrntt sent a RDY response, the caller shouldn't actually be executing
|
|
||||||
* any longer to receive it anyway.
|
|
||||||
*/
|
|
||||||
void ComponentThread::exceptionInd(
|
|
||||||
const std::shared_ptr<ComponentThread> &faultyThread
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if (this->id != ComponentThread::MRNTT)
|
|
||||||
{
|
|
||||||
throw std::runtime_error(std::string(__func__)
|
|
||||||
+ ": invoked on non-mrntt thread " + faultyThread->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto request = std::make_shared<MindThread::MindShutdownIndOp>(
|
|
||||||
faultyThread, nullptr);
|
|
||||||
|
|
||||||
// Post the exception to the mrntt thread.
|
|
||||||
this->getIoService().post(
|
|
||||||
std::bind(
|
|
||||||
&MindThread::MindShutdownIndOp::mindShutdownInd1_exception,
|
|
||||||
request.get(), request));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ComponentThread::userShutdownInd()
|
|
||||||
{
|
|
||||||
if (this->id != ComponentThread::MRNTT)
|
|
||||||
{
|
|
||||||
throw std::runtime_error(std::string(__func__)
|
|
||||||
+ ": invoked on non-mrntt thread " + this->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto request = std::make_shared<MindThread::MindShutdownIndOp>(
|
|
||||||
ComponentThread::getMrntt(), nullptr);
|
|
||||||
|
|
||||||
// Post the user shutdown to the mrntt thread.
|
|
||||||
this->getIoService().post(
|
|
||||||
std::bind(
|
|
||||||
&MindThread::MindShutdownIndOp::mindShutdownInd1_userShutdown,
|
|
||||||
request.get(), request));
|
request.get(), request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace mrntt {
|
|||||||
|
|
||||||
extern std::atomic<int> exitCode;
|
extern std::atomic<int> exitCode;
|
||||||
void exitMarionetteLoop();
|
void exitMarionetteLoop();
|
||||||
|
void marionetteFinalizeReqCb(bool success);
|
||||||
extern mrntt::MarionetteComponent mrntt;
|
extern mrntt::MarionetteComponent mrntt;
|
||||||
|
|
||||||
} // namespace mrntt
|
} // namespace mrntt
|
||||||
|
|||||||
Reference in New Issue
Block a user