mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-30 00:53:46 +00:00
Merge branch 'master' into Playerbot
This commit is contained in:
@@ -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__
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,16 @@ LocaleConstant GetLocaleByName(const std::string& name)
|
||||
return LOCALE_enUS; // including enGB case
|
||||
}
|
||||
|
||||
const std::string GetNameByLocaleConstant(LocaleConstant localeConstant)
|
||||
{
|
||||
if (localeConstant < TOTAL_LOCALES)
|
||||
{
|
||||
return localeNames[localeConstant];
|
||||
}
|
||||
|
||||
return "enUS"; // Default value for unsupported or invalid LocaleConstant
|
||||
}
|
||||
|
||||
void CleanStringForMysqlQuery(std::string& str)
|
||||
{
|
||||
std::string::size_type n = 0;
|
||||
|
||||
@@ -84,6 +84,7 @@ enum LocaleConstant
|
||||
AC_COMMON_API extern char const* localeNames[TOTAL_LOCALES];
|
||||
|
||||
AC_COMMON_API LocaleConstant GetLocaleByName(const std::string& name);
|
||||
AC_COMMON_API const std::string GetNameByLocaleConstant(LocaleConstant localeConstant);
|
||||
AC_COMMON_API void CleanStringForMysqlQuery(std::string& str);
|
||||
|
||||
#define MAX_QUERY_LEN 32*1024
|
||||
|
||||
@@ -81,7 +81,7 @@ char const* GitRevision::GetMySQLExecutable()
|
||||
|
||||
char const* GitRevision::GetFullVersion()
|
||||
{
|
||||
return VER_COMPANYNAME_STR " rev. " VER_PRODUCTVERSION_STR " (" AZEROTH_PLATFORM_STR ", " _BUILD_DIRECTIVE ", " ACORE_LINKAGE_TYPE_STR ")";
|
||||
return VER_COMPANYNAME_STR " rev. " VER_PRODUCTVERSION_STR " (" AZEROTH_PLATFORM_STR ", " _BUILD_DIRECTIVE ", " ACORE_LINKAGE_TYPE_STR ")"; // cppcheck-suppress unknownMacro
|
||||
}
|
||||
|
||||
char const* GitRevision::GetCompanyNameStr()
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -28,10 +28,11 @@ private:
|
||||
std::mutex _queueLock;
|
||||
std::queue<T> _queue;
|
||||
std::condition_variable _condition;
|
||||
std::atomic<bool> _cancel;
|
||||
std::atomic<bool> _shutdown;
|
||||
|
||||
public:
|
||||
ProducerConsumerQueue() : _shutdown(false) { }
|
||||
ProducerConsumerQueue() : _cancel(false), _shutdown(false) { }
|
||||
|
||||
void Push(const T& value)
|
||||
{
|
||||
@@ -57,10 +58,8 @@ public:
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_queueLock);
|
||||
|
||||
if (_queue.empty() || _shutdown)
|
||||
{
|
||||
if (_queue.empty() || _cancel)
|
||||
return false;
|
||||
}
|
||||
|
||||
value = _queue.front();
|
||||
|
||||
@@ -75,21 +74,18 @@ public:
|
||||
|
||||
// we could be using .wait(lock, predicate) overload here but it is broken
|
||||
// https://connect.microsoft.com/VisualStudio/feedback/details/1098841
|
||||
while (_queue.empty() && !_shutdown)
|
||||
{
|
||||
while (_queue.empty() && !_cancel && !_shutdown)
|
||||
_condition.wait(lock);
|
||||
}
|
||||
|
||||
if (_queue.empty() || _shutdown)
|
||||
{
|
||||
if (_queue.empty() || _cancel)
|
||||
return;
|
||||
}
|
||||
|
||||
value = _queue.front();
|
||||
|
||||
_queue.pop();
|
||||
}
|
||||
|
||||
// Clears the queue and will immediately stop any consumers
|
||||
void Cancel()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_queueLock);
|
||||
@@ -103,11 +99,18 @@ public:
|
||||
_queue.pop();
|
||||
}
|
||||
|
||||
_shutdown = true;
|
||||
_cancel = true;
|
||||
|
||||
_condition.notify_all();
|
||||
}
|
||||
|
||||
// Graceful stop, will wait for queue to become empty before stopping consumers
|
||||
void Shutdown()
|
||||
{
|
||||
_shutdown = true;
|
||||
_condition.notify_all();
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename E = T>
|
||||
typename std::enable_if<std::is_pointer<E>::value>::type DeleteQueuedObject(E& obj) { delete obj; }
|
||||
|
||||
Reference in New Issue
Block a user