From 64d578f23d9568bc7798970935cf0814f9637509 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Mon, 17 Oct 2016 03:26:50 +0200 Subject: [PATCH] fix(modules): Generic method for broadcasting handled events --- include/modules/meta.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/modules/meta.hpp b/include/modules/meta.hpp index 8b4768df..33998389 100644 --- a/include/modules/meta.hpp +++ b/include/modules/meta.hpp @@ -183,6 +183,9 @@ namespace modules { std::lock_guard lck(this->update_lock); { + if (m_broadcast_thread.joinable()) + m_broadcast_thread.join(); + for (auto&& thread_ : m_threads) { if (thread_.joinable()) thread_.join(); @@ -305,6 +308,16 @@ namespace modules { } protected: + // Called by modules after handling action events + void event_handled() { + std::lock_guard lck(this->update_lock); + { + if (m_broadcast_thread.joinable()) + m_broadcast_thread.join(); + m_broadcast_thread = thread(&module::broadcast, this); + } + } + // concurrency::SpinLock output_lock; // concurrency::SpinLock broadcast_lock; threading_util::spin_lock update_lock; @@ -324,6 +337,7 @@ namespace modules { private: stateflag m_enabled{false}; string m_cache; + thread m_broadcast_thread; }; // }}}