Skip to content

Commit

Permalink
iox-eclipse-iceoryx#2330 Add shutdown method to Systemd_service_handler
Browse files Browse the repository at this point in the history
Implemented a shutdown method in Systemd_service_handler to allow graceful termination of the watchdog thread. This enhancement ensures proper resource cleanup and improves system robustness by avoiding potential hang-ups during the shutdown process.
  • Loading branch information
khromenokroman committed Aug 23, 2024
1 parent 7abf543 commit bc13c4b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
24 changes: 18 additions & 6 deletions iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class I_systemd
I_systemd& operator=(I_systemd&& other) = default;

virtual void process_notify() = 0;
virtual void shutdown() = 0;

protected:
I_systemd() = default;
Expand All @@ -67,10 +68,9 @@ class Systemd_service_handler final : public I_systemd
public:
Systemd_service_handler() = default;
Systemd_service_handler(Systemd_service_handler const& other) = delete;
Systemd_service_handler(Systemd_service_handler&& other) = default;
Systemd_service_handler(Systemd_service_handler&& other) = delete;
Systemd_service_handler& operator=(Systemd_service_handler const& other) = delete;
Systemd_service_handler& operator=(Systemd_service_handler&& other) = default;
static constexpr uint16_t SIZE_STRING = 4096;

~Systemd_service_handler() final
{
Expand All @@ -84,6 +84,12 @@ class Systemd_service_handler final : public I_systemd
m_listen_thread_watchdog.join();
}
}

void shutdown() final
{
m_shutdown.store(true);
}

void process_notify() final
{
/*
Expand Down Expand Up @@ -134,7 +140,7 @@ class Systemd_service_handler final : public I_systemd
IOX_LOG(DEBUG, "WatchDog READY=1");

IOX_LOG(INFO, "Start watchdog");
while (true)
while (!m_shutdown.load())
{
auto result_watchdog = IOX_POSIX_CALL(sd_notify)(0, "WATCHDOG=1").successReturnValue(1).evaluate();
if (result_watchdog.has_error())
Expand All @@ -152,6 +158,10 @@ class Systemd_service_handler final : public I_systemd

private:
std::thread m_listen_thread_watchdog; // 8
public:
static constexpr uint16_t SIZE_STRING = 4096; // 2
private:
std::atomic_bool m_shutdown{false}; // 1
};
#else
class Systemd_service_handler final : public I_systemd
Expand All @@ -163,14 +173,16 @@ class Systemd_service_handler final : public I_systemd
Systemd_service_handler& operator=(Systemd_service_handler const& other) = delete;
Systemd_service_handler& operator=(Systemd_service_handler&& other) = default;

~Systemd_service_handler() final
~Systemd_service_handler() final = default;
void process_notify() final
{
// empty implementation
}
void process_notify() final
void shutdown() final
{
// empty implementation
}
}
};
#endif
} // namespace systemd

Expand Down
3 changes: 3 additions & 0 deletions iceoryx_posh/source/roudi/roudi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ void RouDi::processRuntimeMessages(runtime::IpcInterfaceCreator&& roudiIpcInterf
processMessage(message, cmd, runtimeName);
}
}
if (!m_runHandleRuntimeMessageThread.load()){
roudi_systemd.shutdown();
}
}

version::VersionInfo RouDi::parseRegisterMessage(const runtime::IpcMessage& message,
Expand Down

0 comments on commit bc13c4b

Please sign in to comment.