From 2b1eb5337c544f55a0eeb0ad57e7c8917de8d4cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20BOULMIER?= Date: Sat, 1 Jun 2019 19:23:36 -0400 Subject: [PATCH] fix(modules): move join in a new method --- include/modules/meta/base.hpp | 2 ++ include/modules/meta/base.inl | 21 ++++++++++++--------- include/modules/unsupported.hpp | 1 + src/components/controller.cpp | 6 +++++- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/include/modules/meta/base.hpp b/include/modules/meta/base.hpp index 941525da..f842e907 100644 --- a/include/modules/meta/base.hpp +++ b/include/modules/meta/base.hpp @@ -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(); diff --git a/include/modules/meta/base.inl b/include/modules/meta/base.inl index 219a35b1..ab53cb59 100644 --- a/include/modules/meta/base.inl +++ b/include/modules/meta/base.inl @@ -65,6 +65,18 @@ namespace modules { return static_cast(m_enabled); } + template + void module::join() { + for (auto&& thread_ : m_threads) { + if (thread_.joinable()) { + thread_.join(); + } + } + if (m_mainthread.joinable()) { + m_mainthread.join(); + } + } + template bool module::visible() const { return static_cast(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{}); } } diff --git a/include/modules/unsupported.hpp b/include/modules/unsupported.hpp index dda2027e..b03b3cb7 100644 --- a/include/modules/unsupported.hpp +++ b/include/modules/unsupported.hpp @@ -32,6 +32,7 @@ namespace modules { } \ void start() override {} \ void stop() override {} \ + void join() override {} \ void halt(string) override {} \ string contents() override { \ return ""; \ diff --git a/src/components/controller.cpp b/src/components/controller.cpp index be7f3bc4..ba519bd5 100644 --- a/src/components/controller.cpp +++ b/src/components/controller.cpp @@ -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); } }