From 0bc70670d2eb129bc8629670420363089f9dded0 Mon Sep 17 00:00:00 2001
From: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
Date: Thu, 19 Dec 2024 18:00:03 +0100
Subject: refactor(Core/Misc): Use steady_timer instead of deadline_timer
(#20940)
---
src/common/Asio/DeadlineTimer.h | 34 ----------------------------------
src/common/Asio/IoContext.h | 5 ++---
src/common/Metric/Metric.cpp | 13 ++++++++-----
src/common/Metric/Metric.h | 6 +++---
4 files changed, 13 insertions(+), 45 deletions(-)
delete mode 100644 src/common/Asio/DeadlineTimer.h
(limited to 'src/common')
diff --git a/src/common/Asio/DeadlineTimer.h b/src/common/Asio/DeadlineTimer.h
deleted file mode 100644
index 09e377e6d4..0000000000
--- a/src/common/Asio/DeadlineTimer.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Affero General Public License as published by the
- * Free Software Foundation; either version 3 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see .
- */
-
-#ifndef DeadlineTimer_h__
-#define DeadlineTimer_h__
-
-#include
-
-#define DeadlineTimerBase boost::asio::basic_deadline_timer, boost::asio::io_context::executor_type>
-
-namespace Acore::Asio
-{
- class DeadlineTimer : public DeadlineTimerBase
- {
- public:
- using DeadlineTimerBase::basic_deadline_timer;
- };
-}
-
-#endif // DeadlineTimer_h__
diff --git a/src/common/Asio/IoContext.h b/src/common/Asio/IoContext.h
index 46dfa8516f..fa85c67155 100644
--- a/src/common/Asio/IoContext.h
+++ b/src/common/Asio/IoContext.h
@@ -19,7 +19,6 @@
#define IoContext_h__
#include
-
#include
#include
#define IoContextBaseNamespace boost::asio
@@ -52,9 +51,9 @@ namespace Acore::Asio
}
template
- inline decltype(auto) get_io_context(T&& ioObject)
+ inline boost::asio::io_context& get_io_context(T&& ioObject)
{
- return ioObject.get_executor().context();
+ return static_cast(ioObject.get_executor().context());
}
}
diff --git a/src/common/Metric/Metric.cpp b/src/common/Metric/Metric.cpp
index 8a2ecabd82..a6cd4b1f27 100644
--- a/src/common/Metric/Metric.cpp
+++ b/src/common/Metric/Metric.cpp
@@ -17,7 +17,6 @@
#include "Metric.h"
#include "Config.h"
-#include "DeadlineTimer.h"
#include "Log.h"
#include "Strand.h"
#include "Tokenize.h"
@@ -42,8 +41,8 @@ void Metric::Initialize(std::string const& realmName, Acore::Asio::IoContext& io
{
_dataStream = std::make_unique();
_realmName = FormatInfluxDBTagValue(realmName);
- _batchTimer = std::make_unique(ioContext);
- _overallStatusTimer = std::make_unique(ioContext);
+ _batchTimer = std::make_unique(ioContext);
+ _overallStatusTimer = std::make_unique(ioContext);
_overallStatusLogger = overallStatusLogger;
LoadFromConfigs();
}
@@ -247,7 +246,9 @@ void Metric::ScheduleSend()
{
if (_enabled)
{
- _batchTimer->expires_from_now(boost::posix_time::seconds(_updateInterval));
+ // Calculate the expiration time
+ auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(_updateInterval);
+ _batchTimer->expires_at(expirationTime);
_batchTimer->async_wait(std::bind(&Metric::SendBatch, this));
}
else
@@ -280,7 +281,9 @@ void Metric::ScheduleOverallStatusLog()
{
if (_enabled)
{
- _overallStatusTimer->expires_from_now(boost::posix_time::seconds(_overallStatusTimerInterval));
+ // Calculate the expiration time _overallStatusTimerInterval from now
+ auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(_overallStatusTimerInterval);
+ _overallStatusTimer->expires_at(expirationTime);
_overallStatusTimer->async_wait([this](const boost::system::error_code&)
{
_overallStatusTimerTriggered = true;
diff --git a/src/common/Metric/Metric.h b/src/common/Metric/Metric.h
index eca14f52c8..729d2f7fc5 100644
--- a/src/common/Metric/Metric.h
+++ b/src/common/Metric/Metric.h
@@ -21,6 +21,7 @@
#include "Define.h"
#include "Duration.h"
#include "MPSCQueue.h"
+#include
#include
#include // NOTE: this import is NEEDED (even though some IDEs report it as unused)
#include
@@ -30,7 +31,6 @@
namespace Acore::Asio
{
class IoContext;
- class DeadlineTimer;
}
enum MetricDataType
@@ -62,8 +62,8 @@ private:
std::iostream& GetDataStream() { return *_dataStream; }
std::unique_ptr _dataStream;
MPSCQueue _queuedData;
- std::unique_ptr _batchTimer;
- std::unique_ptr _overallStatusTimer;
+ std::unique_ptr _batchTimer;
+ std::unique_ptr _overallStatusTimer;
int32 _updateInterval = 0;
int32 _overallStatusTimerInterval = 0;
bool _enabled = false;
--
cgit v1.2.3