fix(modules): move join in a new method
This commit is contained in:
parent
e5ab7e1c00
commit
2b1eb5337c
@ -131,6 +131,7 @@ namespace modules {
|
|||||||
virtual bool input(const string& action, const string& data) = 0;
|
virtual bool input(const string& action, const string& data) = 0;
|
||||||
|
|
||||||
virtual void start() = 0;
|
virtual void start() = 0;
|
||||||
|
virtual void join() = 0;
|
||||||
virtual void stop() = 0;
|
virtual void stop() = 0;
|
||||||
virtual void halt(string error_message) = 0;
|
virtual void halt(string error_message) = 0;
|
||||||
virtual string contents() = 0;
|
virtual string contents() = 0;
|
||||||
@ -157,6 +158,7 @@ namespace modules {
|
|||||||
|
|
||||||
bool visible() const override;
|
bool visible() const override;
|
||||||
|
|
||||||
|
void join() final override;
|
||||||
void stop() override;
|
void stop() override;
|
||||||
void halt(string error_message) override;
|
void halt(string error_message) override;
|
||||||
void teardown();
|
void teardown();
|
||||||
|
@ -65,6 +65,18 @@ namespace modules {
|
|||||||
return static_cast<bool>(m_enabled);
|
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>
|
template <typename Impl>
|
||||||
bool module<Impl>::visible() const {
|
bool module<Impl>::visible() const {
|
||||||
return static_cast<bool>(m_visible);
|
return static_cast<bool>(m_visible);
|
||||||
@ -86,15 +98,6 @@ namespace modules {
|
|||||||
CAST_MOD(Impl)->wakeup();
|
CAST_MOD(Impl)->wakeup();
|
||||||
CAST_MOD(Impl)->teardown();
|
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{});
|
m_sig.emit(signals::eventqueue::check_state{});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ namespace modules {
|
|||||||
} \
|
} \
|
||||||
void start() override {} \
|
void start() override {} \
|
||||||
void stop() override {} \
|
void stop() override {} \
|
||||||
|
void join() override {} \
|
||||||
void halt(string) override {} \
|
void halt(string) override {} \
|
||||||
string contents() override { \
|
string contents() override { \
|
||||||
return ""; \
|
return ""; \
|
||||||
|
@ -74,7 +74,11 @@ controller::~controller() {
|
|||||||
m_log.trace("controller: Stop modules");
|
m_log.trace("controller: Stop modules");
|
||||||
for (auto&& module : m_modules) {
|
for (auto&& module : m_modules) {
|
||||||
auto module_name = module->name();
|
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);
|
m_log.info("Deconstruction of %s took %lu ms.", module_name, cleanup_ms);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user