Enable module in start funcion (#2538)
Before it was enabled by default. That means if the constructor fails, the destructor will complain that the module was not stopped before deconstructing. We can't just call stop if module creation fails because the module is only partially initialized.
This commit is contained in:
parent
76ae61f892
commit
abd96eb089
@ -158,6 +158,7 @@ namespace modules {
|
||||
|
||||
bool visible() const override;
|
||||
|
||||
void start() override;
|
||||
void join() final override;
|
||||
void stop() override;
|
||||
void halt(string error_message) override;
|
||||
@ -218,7 +219,7 @@ namespace modules {
|
||||
bool m_handle_events{true};
|
||||
|
||||
private:
|
||||
atomic<bool> m_enabled{true};
|
||||
atomic<bool> m_enabled{false};
|
||||
atomic<bool> m_visible{true};
|
||||
atomic<bool> m_changed{true};
|
||||
string m_cache;
|
||||
|
@ -65,6 +65,11 @@ namespace modules {
|
||||
return static_cast<bool>(m_enabled);
|
||||
}
|
||||
|
||||
template <class Impl>
|
||||
void module<Impl>::start() {
|
||||
m_enabled = true;
|
||||
}
|
||||
|
||||
template <class Impl>
|
||||
void module<Impl>::join() {
|
||||
for (auto&& thread_ : m_threads) {
|
||||
|
@ -11,6 +11,7 @@ namespace modules {
|
||||
using module<Impl>::module;
|
||||
|
||||
void start() override {
|
||||
this->module<Impl>::start();
|
||||
this->m_mainthread = thread(&event_module::runner, this);
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ namespace modules {
|
||||
using module<Impl>::module;
|
||||
|
||||
void start() override {
|
||||
this->module<Impl>::start();
|
||||
this->m_mainthread = thread(&inotify_module::runner, this);
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ namespace modules {
|
||||
using module<Impl>::module;
|
||||
|
||||
void start() override {
|
||||
this->module<Impl>::start();
|
||||
CAST_MOD(Impl)->update();
|
||||
CAST_MOD(Impl)->broadcast();
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace modules {
|
||||
using module<Impl>::module;
|
||||
|
||||
void start() override {
|
||||
this->module<Impl>::start();
|
||||
this->m_mainthread = thread(&timer_module::runner, this);
|
||||
}
|
||||
|
||||
|
@ -68,6 +68,7 @@ namespace modules {
|
||||
* Start module and run first defined hook if configured to
|
||||
*/
|
||||
void ipc_module::start() {
|
||||
this->module::start();
|
||||
m_mainthread = thread([&] {
|
||||
m_log.trace("%s: Thread id = %i", this->name(), concurrency_util::thread_id(this_thread::get_id()));
|
||||
update();
|
||||
|
@ -33,6 +33,7 @@ namespace modules {
|
||||
* Start the module worker
|
||||
*/
|
||||
void script_module::start() {
|
||||
this->module::start();
|
||||
m_mainthread = thread([&] {
|
||||
try {
|
||||
while (running()) {
|
||||
|
Loading…
Reference in New Issue
Block a user