Marionette: Post initializeHarikoff() as a lambda

This commit is contained in:
2025-01-11 06:19:11 -04:00
parent bffc32519b
commit 8aa28a877e
2 changed files with 24 additions and 19 deletions
-1
View File
@@ -40,7 +40,6 @@ void ComponentThread::signalThread(std::thread::id id)
void ComponentThread::main(ComponentThread& self)
{
std::cout << __func__ << ": Entered." << std::endl;
// We sleep on spawn until the main thread tells us to continue.
{
std::unique_lock<std::mutex> lock(self.startupSync.mutex);
+24 -18
View File
@@ -21,25 +21,25 @@ int main(int argc, char **argv, char **envp)
{
try {
std::cout << __func__ << ": Entering main()" << std::endl;
boost::asio::io_service mrntLoop;
boost::asio::io_service::work work(mrntLoop);
// Validate thread IDs
// Validate thread IDs
hk::ComponentThread::validateThreadIds();
int ret = hk::initializeHarikoff(argc, argv, envp);
if (ret != 0) {
return ret;
}
// Post initializeHarikoff to mrntLoop
mrntLoop.post([&]()
{
int ret = hk::initializeHarikoff(argc, argv, envp);
if (ret != 0)
{
std::cerr << "Initialization failed with code: "
<< ret << std::endl;
std::exit(ret);
}
});
// Signal all threads
for (const auto& [id, componentThread]
: hk::ComponentThread::componentThreads) {
hk::ComponentThread::signalThread(id);
}
// Infinite loop calling yield
while (true) {
std::this_thread::yield();
}
mrntLoop.run();
}
catch (const std::exception& e)
{
@@ -47,7 +47,8 @@ int main(int argc, char **argv, char **envp)
<< std::endl;
return EXIT_FAILURE;
}
catch (...) {
catch (...)
{
std::cerr << __func__ << ": Unknown exception occurred" << std::endl;
return EXIT_FAILURE;
}
@@ -70,6 +71,7 @@ static int initializeHarikoff(int argc, char **argv, char **envp)
try {
options.parseArguments(argc, argv, envp);
std::cout << options.stringifyOptions() << std::endl;
}
catch (const std::invalid_argument& e)
{
@@ -78,18 +80,22 @@ static int initializeHarikoff(int argc, char **argv, char **envp)
return EXIT_FAILURE;
}
if (options.printUsage) {
if (options.printUsage)
{
std::cout << options.getUsage() << std::endl;
return EXIT_SUCCESS;
}
std::cout << options.stringifyOptions() << std::endl;
DeviceManager::getInstance().collateAllDeviceSpecs();
DeviceManager::getInstance().parseAllDeviceSpecs();
std::cout << DeviceManager::stringifyDeviceSpecs() << std::endl;
sense_api::SenseApiManager::getInstance().loadAllSenseApiLibsFromOptions();
/* Start the threads */
for (const auto& [id, componentThread]
: hk::ComponentThread::componentThreads) {
hk::ComponentThread::signalThread(id);
}
std::cout << __func__ << ": Exiting" << std::endl;
return 0;