ComponentThreads: now basics are working.
Next step is to get the unified event loops working generically and then we can begin region-splitting up the data in harikoff. We'll assign all the global resource managers to Marionette and then assign the Mind components to the respective component threads.
This commit is contained in:
@@ -14,8 +14,6 @@
|
||||
namespace hk {
|
||||
|
||||
static int initializeHarikoff(int argc, char **argv, char **envp);
|
||||
void startThreads();
|
||||
void signalThreads();
|
||||
|
||||
} // namespace hk
|
||||
|
||||
@@ -24,20 +22,29 @@ int main(int argc, char **argv, char **envp)
|
||||
try {
|
||||
std::cout << __func__ << ": Entering main()" << std::endl;
|
||||
|
||||
// Print out the keys for each index in the map
|
||||
for (const auto& [id, componentThread]
|
||||
: hk::ComponentThread::componentThreads)
|
||||
{
|
||||
std::cout << __func__ << ": Thread ID: " << id << std::endl;
|
||||
}
|
||||
// Validate thread IDs
|
||||
hk::ComponentThread::validateThreadIds();
|
||||
|
||||
int ret = hk::initializeHarikoff(argc, argv, envp);
|
||||
if (ret != 0) {
|
||||
return 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();
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << __func__ << ": Exception occurred: " << e.what() << std::endl;
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::cerr << __func__ << ": Exception occurred: " << e.what()
|
||||
<< std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -64,8 +71,10 @@ static int initializeHarikoff(int argc, char **argv, char **envp)
|
||||
try {
|
||||
options.parseArguments(argc, argv, envp);
|
||||
}
|
||||
catch (const std::invalid_argument& e) {
|
||||
std::cerr << __func__ << ": Exception occurred: " << e.what() << '\n' << options.getUsage() << '\n';
|
||||
catch (const std::invalid_argument& e)
|
||||
{
|
||||
std::cerr << __func__ << ": Exception occurred: " << e.what() << '\n'
|
||||
<< options.getUsage() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -80,38 +89,10 @@ static int initializeHarikoff(int argc, char **argv, char **envp)
|
||||
std::cout << DeviceManager::stringifyDeviceSpecs() << std::endl;
|
||||
sense_api::SenseApiManager::getInstance().loadAllSenseApiLibsFromOptions();
|
||||
|
||||
/* Start the threads */
|
||||
|
||||
std::cout << __func__ << ": Exiting" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void startThreads()
|
||||
{
|
||||
for (auto& [id, componentThread] : ComponentThread::componentThreads) {
|
||||
componentThread.thread = std::thread([&componentThread]() {
|
||||
// We sleep on spawn until the marionette tells us to continue.
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(
|
||||
componentThread.startupSync.mutex);
|
||||
|
||||
componentThread.startupSync.cv.wait(lock, [&componentThread]() {
|
||||
return componentThread.startupSync.ready;
|
||||
});
|
||||
}
|
||||
|
||||
componentThread.getIoService().run();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void signalThreads()
|
||||
{
|
||||
for (auto& [id, componentThread] : ComponentThread::componentThreads) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(componentThread.startupSync.mutex);
|
||||
componentThread.startupSync.ready = true;
|
||||
}
|
||||
componentThread.startupSync.cv.notify_one();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace hk
|
||||
|
||||
Reference in New Issue
Block a user