1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-12-09 14:10:19 -05:00
polybar/include/modules/meta/event_module.inl

52 lines
1.1 KiB
Text
Raw Normal View History

2016-11-20 17:04:31 -05:00
POLYBAR_NS
namespace modules {
// public {{{
template <class Impl>
void event_module<Impl>::start() {
CAST_MOD(Impl)->m_mainthread = thread(&event_module::runner, this);
}
// }}}
// protected {{{
template <class Impl>
void event_module<Impl>::runner() {
try {
// Send initial broadcast to warmup cache
if (CONST_MOD(Impl).running()) {
CAST_MOD(Impl)->update();
CAST_MOD(Impl)->broadcast();
}
while (CONST_MOD(Impl).running()) {
CAST_MOD(Impl)->idle();
if (!CONST_MOD(Impl).running())
break;
std::lock_guard<concurrency_util::spin_lock> guard(this->m_lock);
{
if (!CAST_MOD(Impl)->has_event())
continue;
if (!CONST_MOD(Impl).running())
break;
if (!CAST_MOD(Impl)->update())
continue;
CAST_MOD(Impl)->broadcast();
}
}
} catch (const module_error& err) {
CAST_MOD(Impl)->halt(err.what());
} catch (const std::exception& err) {
CAST_MOD(Impl)->halt(err.what());
}
}
// }}}
}
POLYBAR_NS_END