refactor(modules): Defer cache rebuild

This commit is contained in:
Michael Carlberg 2016-12-23 05:19:45 +01:00
parent debb3534c7
commit ba757809d0
2 changed files with 8 additions and 6 deletions

View File

@ -153,7 +153,8 @@ namespace modules {
thread m_mainthread;
private:
stateflag m_enabled{true};
atomic<bool> m_enabled{true};
atomic<bool> m_changed{true};
string m_cache;
};

View File

@ -77,6 +77,11 @@ namespace modules {
template <typename Impl>
string module<Impl>::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 <typename Impl>
void module<Impl>::broadcast() {
if (!running()) {
return;
}
m_cache = CAST_MOD(Impl)->get_output();
m_changed = true;
m_sig.emit(sig_ev::process_broadcast{});
}