fix(modules): move join in a new method

This commit is contained in:
Jérôme BOULMIER 2019-06-01 19:23:36 -04:00 committed by Patrick Ziegler
parent e5ab7e1c00
commit 2b1eb5337c
4 changed files with 20 additions and 10 deletions

View File

@ -131,6 +131,7 @@ namespace modules {
virtual bool input(const string& action, const string& data) = 0;
virtual void start() = 0;
virtual void join() = 0;
virtual void stop() = 0;
virtual void halt(string error_message) = 0;
virtual string contents() = 0;
@ -157,6 +158,7 @@ namespace modules {
bool visible() const override;
void join() final override;
void stop() override;
void halt(string error_message) override;
void teardown();

View File

@ -65,6 +65,18 @@ namespace modules {
return static_cast<bool>(m_enabled);
}
template <class Impl>
void module<Impl>::join() {
for (auto&& thread_ : m_threads) {
if (thread_.joinable()) {
thread_.join();
}
}
if (m_mainthread.joinable()) {
m_mainthread.join();
}
}
template <typename Impl>
bool module<Impl>::visible() const {
return static_cast<bool>(m_visible);
@ -86,15 +98,6 @@ namespace modules {
CAST_MOD(Impl)->wakeup();
CAST_MOD(Impl)->teardown();
for (auto&& thread_ : m_threads) {
if (thread_.joinable()) {
thread_.join();
}
}
if (m_mainthread.joinable()) {
m_mainthread.join();
}
m_sig.emit(signals::eventqueue::check_state{});
}
}

View File

@ -32,6 +32,7 @@ namespace modules {
} \
void start() override {} \
void stop() override {} \
void join() override {} \
void halt(string) override {} \
string contents() override { \
return ""; \

View File

@ -74,7 +74,11 @@ controller::~controller() {
m_log.trace("controller: Stop modules");
for (auto&& module : m_modules) {
auto module_name = module->name();
auto cleanup_ms = time_util::measure([&module] { module->stop(); });
auto cleanup_ms = time_util::measure([&module] {
module->stop();
module->join();
module.reset();
});
m_log.info("Deconstruction of %s took %lu ms.", module_name, cleanup_ms);
}
}