diff options
author | Kitzunu <24550914+Kitzunu@users.noreply.github.com> | 2024-12-19 18:00:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-19 18:00:03 +0100 |
commit | 0bc70670d2eb129bc8629670420363089f9dded0 (patch) | |
tree | c06a60ff0f56eb6cc4c62b8d1ceb0f47e5227da9 /src/common | |
parent | ea02be964b7b57155bdceb4c0996cc92cc45b887 (diff) |
refactor(Core/Misc): Use steady_timer instead of deadline_timer (#20940)
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/Asio/DeadlineTimer.h | 34 | ||||
-rw-r--r-- | src/common/Asio/IoContext.h | 5 | ||||
-rw-r--r-- | src/common/Metric/Metric.cpp | 13 | ||||
-rw-r--r-- | src/common/Metric/Metric.h | 6 |
4 files changed, 13 insertions, 45 deletions
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 <http://www.gnu.org/licenses/>. - */ - -#ifndef DeadlineTimer_h__ -#define DeadlineTimer_h__ - -#include <boost/asio/deadline_timer.hpp> - -#define DeadlineTimerBase boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, 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 <boost/version.hpp> - #include <boost/asio/io_context.hpp> #include <boost/asio/post.hpp> #define IoContextBaseNamespace boost::asio @@ -52,9 +51,9 @@ namespace Acore::Asio } template<typename T> - 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<boost::asio::io_context&>(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<boost::asio::ip::tcp::iostream>(); _realmName = FormatInfluxDBTagValue(realmName); - _batchTimer = std::make_unique<Acore::Asio::DeadlineTimer>(ioContext); - _overallStatusTimer = std::make_unique<Acore::Asio::DeadlineTimer>(ioContext); + _batchTimer = std::make_unique<boost::asio::steady_timer>(ioContext); + _overallStatusTimer = std::make_unique<boost::asio::steady_timer>(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 <boost/asio/steady_timer.hpp> #include <functional> #include <memory> // NOTE: this import is NEEDED (even though some IDEs report it as unused) #include <string> @@ -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<std::iostream> _dataStream; MPSCQueue<MetricData> _queuedData; - std::unique_ptr<Acore::Asio::DeadlineTimer> _batchTimer; - std::unique_ptr<Acore::Asio::DeadlineTimer> _overallStatusTimer; + std::unique_ptr<boost::asio::steady_timer> _batchTimer; + std::unique_ptr<boost::asio::steady_timer> _overallStatusTimer; int32 _updateInterval = 0; int32 _overallStatusTimerInterval = 0; bool _enabled = false; |