fix(modules): Generic method for broadcasting handled events

This commit is contained in:
Michael Carlberg 2016-10-17 03:26:50 +02:00
parent c1acf6c05f
commit 64d578f23d

View File

@ -183,6 +183,9 @@ namespace modules {
std::lock_guard<threading_util::spin_lock> lck(this->update_lock); std::lock_guard<threading_util::spin_lock> lck(this->update_lock);
{ {
if (m_broadcast_thread.joinable())
m_broadcast_thread.join();
for (auto&& thread_ : m_threads) { for (auto&& thread_ : m_threads) {
if (thread_.joinable()) if (thread_.joinable())
thread_.join(); thread_.join();
@ -305,6 +308,16 @@ namespace modules {
} }
protected: protected:
// Called by modules after handling action events
void event_handled() {
std::lock_guard<threading_util::spin_lock> 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 output_lock;
// concurrency::SpinLock broadcast_lock; // concurrency::SpinLock broadcast_lock;
threading_util::spin_lock update_lock; threading_util::spin_lock update_lock;
@ -324,6 +337,7 @@ namespace modules {
private: private:
stateflag m_enabled{false}; stateflag m_enabled{false};
string m_cache; string m_cache;
thread m_broadcast_thread;
}; };
// }}} // }}}