add closure queue

This commit is contained in:
2025-03-14 22:41:14 -05:00
parent 0b16f632cb
commit 0164c87481
2 changed files with 14 additions and 4 deletions

View File

@@ -41,6 +41,7 @@ void App::run() {
for(auto it = modules.begin(); it != modules.end(); it++) {
(*it)->run();
}
closeModules();
}
}
@@ -76,19 +77,25 @@ void App::load(std::string lib) {
}
void App::unload(decltype(Module::self) it) {
void* handle = (*it)->getHandle();
std::cout << "retrieved handle\nAttempting to delete module: " << (*it)->getName() << std::endl;
toClose.push_back((*it)->getHandle());
std::cout << "marked handle for closure\n";
std::cout << "Attempting to delete module: " << (*it)->getName() << std::endl;
Module* m = *it;
*it = nullptr;
modules.erase(it);
std::cout << "erased iterator\n";
delete m;
std::cout << "deleted module\n";
dlclose(handle);
std::cout << "closed handle\n";
}
void App::closeModules() {
for(auto it = toClose.begin(); it != toClose.end(); it++) {
dlclose(*it);
it = toClose.erase(it);
}
}
void App::handleArgs(const int& argc, char* argv[]) {
int i = 1;