misc: Move to steady_timer
We found that the system clock can affect the deadline timer, causing
the timer to be cancelled if it does not meet expectations, so we
replaced it with steady_timer here, which many repositories have
already done, and this should have no other effect.
Change-Id: Id0d514100cdedc718c4e9dfc328bae8476aa1aeb
Signed-off-by: Jian Zhang <zhangjian.3032@bytedance.com>
diff --git a/healthMonitor.cpp b/healthMonitor.cpp
index 6892cad..f6ab4c4 100644
--- a/healthMonitor.cpp
+++ b/healthMonitor.cpp
@@ -4,7 +4,7 @@
#include <unistd.h>
-#include <boost/asio/deadline_timer.hpp>
+#include <boost/asio/steady_timer.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <sdbusplus/asio/sd_event.hpp>
@@ -32,7 +32,7 @@
// Limit sensor recreation interval to 10s
bool needUpdate;
static constexpr int TIMER_INTERVAL = 10;
-std::shared_ptr<boost::asio::deadline_timer> sensorRecreateTimer;
+std::shared_ptr<boost::asio::steady_timer> sensorRecreateTimer;
std::shared_ptr<phosphor::health::HealthMon> healthMon;
namespace phosphor
@@ -694,9 +694,9 @@
} // namespace phosphor
void sensorRecreateTimerCallback(
- std::shared_ptr<boost::asio::deadline_timer> timer, sdbusplus::bus_t& bus)
+ std::shared_ptr<boost::asio::steady_timer> timer, sdbusplus::bus_t& bus)
{
- timer->expires_from_now(boost::posix_time::seconds(TIMER_INTERVAL));
+ timer->expires_after(std::chrono::seconds(TIMER_INTERVAL));
timer->async_wait([timer, &bus](const boost::system::error_code& ec) {
if (ec == boost::asio::error::operation_aborted)
{
@@ -761,7 +761,7 @@
sdbusplus::asio::sd_event_wrapper sdEvents(io);
- sensorRecreateTimer = std::make_shared<boost::asio::deadline_timer>(io);
+ sensorRecreateTimer = std::make_shared<boost::asio::steady_timer>(io);
// If the SystemInventory does not exist: wait for the InterfaceAdded signal
auto interfacesAddedSignalHandler =