Core/Logging: Fixed log message order not being preserved when async logging was enabled and ThreadPool was greater than 1

Despite that issue, logging was still threadsafe, just not ordered properly
This commit is contained in:
Shauren
2023-08-25 10:40:47 +02:00
parent 30f57de184
commit b51afbdfb9
3 changed files with 7 additions and 3 deletions

View File

@@ -35,7 +35,11 @@ namespace Trinity
Strand(IoContext& ioContext) : boost::asio::io_context::strand(ioContext) { }
};
using boost::asio::bind_executor;
template<typename T>
inline decltype(auto) post(boost::asio::io_context::strand& strand, T&& t)
{
return boost::asio::post(strand, std::forward<T>(t));
}
}
}

View File

@@ -238,7 +238,7 @@ void Log::write(std::unique_ptr<LogMessage> msg) const
if (_ioContext)
{
std::shared_ptr<LogOperation> logOperation = std::make_shared<LogOperation>(logger, std::move(msg));
Trinity::Asio::post(*_ioContext, Trinity::Asio::bind_executor(*_strand, [logOperation]() { logOperation->call(); }));
Trinity::Asio::post(*_strand, [logOperation]() { logOperation->call(); });
}
else
logger->write(msg.get());

View File

@@ -18,8 +18,8 @@
#include "Metric.h"
#include "Config.h"
#include "DeadlineTimer.h"
#include "IoContext.h"
#include "Log.h"
#include "Strand.h"
#include "Util.h"
#include <boost/algorithm/string/replace.hpp>
#include <boost/asio/ip/tcp.hpp>