Make [at|de]tachAllSenseDevices[FromSpecs] and initializeSalmanoff async

This is the culmination of a lot of changes over the last week. We're
making SMO basically fully async in many areas, and then preparing to
implement the spinqueueing mechanism for locking.
This commit is contained in:
2025-09-10 18:12:08 -04:00
parent 81842e4571
commit e08dc0678b
5 changed files with 236 additions and 120 deletions
+32 -9
View File
@@ -5,6 +5,7 @@
#include <opts.h>
#include <typeinfo>
#include <boost/asio/signal_set.hpp>
#include <asynchronousBridge.h>
#include <mind.h>
#include <componentThread.h>
#include <marionette/marionette.h>
@@ -46,7 +47,7 @@ void ComponentThread::marionetteMain(ComponentThread& self)
self.initializeTls();
mrntt::exitCode = EXIT_SUCCESS;
static boost::asio::signal_set signals(self.getIoService(), SIGINT);
bool callFinalizeReq = false;
bool callFinalizeReq = false, callShutdownSalmanoff = false;
try {
// Register SIGINT (Ctrl+C) and SIGSEGV handlers
@@ -88,9 +89,15 @@ void ComponentThread::marionetteMain(ComponentThread& self)
self.getIoService().post([]()
{
// Initialize Salmanoff first
initializeSalmanoff(mrntt::mrntt);
// Then initialize the global Mind object
globalMind->initialize();
initializeSalmanoff([](bool success)
{
if (success) {
// Then initialize the global Mind object
globalMind->initialize();
} else {
std::cerr << "Failed to initialize Salmanoff" << std::endl;
}
});
});
std::cout << __func__ << ": Entering event loop" << "\n";
@@ -154,20 +161,38 @@ void ComponentThread::marionetteMain(ComponentThread& self)
}
*out << outUsageMsg << e.what() << std::endl;
callFinalizeReq = true;
callShutdownSalmanoff = callFinalizeReq = true;
}
catch (const std::exception& e)
{
std::cerr << __func__ << ": Exception occurred: " << e.what()
<< std::endl;
mrntt::exitCode = EXIT_FAILURE;
callFinalizeReq = true;
callShutdownSalmanoff = callFinalizeReq = true;
}
catch (...)
{
std::cerr << __func__ << ": Unknown exception occurred" << std::endl;
mrntt::exitCode = EXIT_FAILURE;
callFinalizeReq = true;
callShutdownSalmanoff = callFinalizeReq = true;
}
if (callShutdownSalmanoff)
{
shutdownSalmanoff(
[](bool success)
{
if (success) {
std::cout << "Salmanoff shutdown completed successfully"
<< std::endl;
} else {
std::cerr << "Salmanoff shutdown failed" << std::endl;
}
mrntt::mrntt->getIoService().stop();
}
);
self.getIoService().reset();
self.getIoService().run();
}
if (callFinalizeReq)
@@ -178,8 +203,6 @@ void ComponentThread::marionetteMain(ComponentThread& self)
self.getIoService().reset();
self.getIoService().run();
}
shutdownSalmanoff();
}
} // namespace smo