Mrntt: use keepLooping after exception; Mind: split code from mrntt
Mrntt now has the event loop structure required to orderly shut itself
down when it itself generates an exception. We can now post a message
within the catch{} blocks for Mrntt's event loop, telling Mrntt
to shut down the Mind threads and then shut itself down.
We also split the code to initialize threads etc out of mrntt and
put it into the Mind:: namespace.
This commit is contained in:
@@ -96,6 +96,13 @@ void ComponentThread::main(ComponentThread& self)
|
||||
|
||||
std::cout << self.name << ":" << __func__ << ": Entering event loop" <<"\n";
|
||||
|
||||
/* We loop here because when an exception is caught, we need to first catch
|
||||
* it in the catch blocks. We bubble the exception to mrntt in the catch
|
||||
* blocks, and then we loop here to await control messages from mrntt.
|
||||
*
|
||||
* We can't just exit on our own. Rather, we must wait for mrntt to tell us
|
||||
* to exit. When we wish to finally exit, we set keepLooping to false.
|
||||
*/
|
||||
for (self.keepLooping = true; self.keepLooping;)
|
||||
{
|
||||
try {
|
||||
@@ -118,7 +125,7 @@ void ComponentThread::main(ComponentThread& self)
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << self.name << ":" << __func__ << ": Exiting event loop" << "\n";
|
||||
std::cout << self.name << ":" << __func__ << ": Exited event loop" << "\n";
|
||||
}
|
||||
|
||||
// Thread management method implementations
|
||||
@@ -245,6 +252,8 @@ void ComponentThread::exceptionInd(ComponentThread& thread)
|
||||
|
||||
currThreadJ->thread.join();
|
||||
}
|
||||
|
||||
mrntt::mrntt->keepLooping = false;
|
||||
mrntt::mrntt->getIoService().stop();
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user