From ba757809d0facb1bcbcfdf15e6b418daa2fd7b36 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Fri, 23 Dec 2016 05:19:45 +0100 Subject: [PATCH] refactor(modules): Defer cache rebuild --- include/modules/meta/base.hpp | 3 ++- include/modules/meta/base.inl | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/modules/meta/base.hpp b/include/modules/meta/base.hpp index 7dffb169..0aa82690 100644 --- a/include/modules/meta/base.hpp +++ b/include/modules/meta/base.hpp @@ -153,7 +153,8 @@ namespace modules { thread m_mainthread; private: - stateflag m_enabled{true}; + atomic m_enabled{true}; + atomic m_changed{true}; string m_cache; }; diff --git a/include/modules/meta/base.inl b/include/modules/meta/base.inl index 217c93cf..9c0c6d62 100644 --- a/include/modules/meta/base.inl +++ b/include/modules/meta/base.inl @@ -77,6 +77,11 @@ namespace modules { template string module::contents() { + if (m_changed) { + m_log.info("Rebuilding cache for '%s'...", name()); + m_cache = CAST_MOD(Impl)->get_output(); + m_changed = false; + } return m_cache; } @@ -85,11 +90,7 @@ namespace modules { template void module::broadcast() { - if (!running()) { - return; - } - - m_cache = CAST_MOD(Impl)->get_output(); + m_changed = true; m_sig.emit(sig_ev::process_broadcast{}); }