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
1 changed files with 14 additions and 0 deletions

View File

@ -183,6 +183,9 @@ namespace modules {
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) {
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<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 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;
};
// }}}