Core/Database: Replace DatabaseWorker with asio io_context

This commit is contained in:
Shauren
2023-12-15 12:06:59 +01:00
parent ee95a5e00f
commit d958bfd0f3
19 changed files with 236 additions and 402 deletions

View File

@@ -18,6 +18,7 @@
#ifndef _MYSQLCONNECTION_H
#define _MYSQLCONNECTION_H
#include "AsioHacksFwd.h"
#include "Define.h"
#include "DatabaseEnvFwd.h"
#include <memory>
@@ -25,12 +26,7 @@
#include <string>
#include <vector>
template <typename T>
class ProducerConsumerQueue;
class DatabaseWorker;
class MySQLPreparedStatement;
class SQLOperation;
enum ConnectionFlags
{
@@ -81,7 +77,8 @@ class TC_DATABASE_API MySQLConnection
uint32 GetLastError();
void StartDatabaseWorkerThread(ProducerConsumerQueue<SQLOperation*>* queue);
void StartWorkerThread(Trinity::Asio::IoContext* context);
std::thread::id GetWorkerThreadId() const;
protected:
/// Tries to acquire lock. If lock is acquired by another thread
@@ -106,7 +103,7 @@ class TC_DATABASE_API MySQLConnection
private:
bool _HandleMySQLErrno(uint32 errNo, uint8 attempts = 5);
std::unique_ptr<DatabaseWorker> m_worker; //!< Core worker task.
std::unique_ptr<std::thread> m_workerThread; //!< Core worker thread.
MySQLHandle* m_Mysql; //!< MySQL Handle.
MySQLConnectionInfo& m_connectionInfo; //!< Connection info (used for logging)
ConnectionFlags m_connectionFlags; //!< Connection flags (for preparing relevant statements)