diff options
author | Shauren <shauren.trinity@gmail.com> | 2023-12-15 12:06:59 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2023-12-15 12:06:59 +0100 |
commit | d958bfd0f32bfe798809b72c1b51c990edfe141c (patch) | |
tree | c9c85d770db94239bc24679f31f2c015653b8daa /src/server/database/Database/MySQLConnection.cpp | |
parent | ee95a5e00fb2ee6928a819699ab93094d916d372 (diff) |
Core/Database: Replace DatabaseWorker with asio io_context
Diffstat (limited to 'src/server/database/Database/MySQLConnection.cpp')
-rw-r--r-- | src/server/database/Database/MySQLConnection.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/server/database/Database/MySQLConnection.cpp b/src/server/database/Database/MySQLConnection.cpp index c42ca4e2903..56e384520c2 100644 --- a/src/server/database/Database/MySQLConnection.cpp +++ b/src/server/database/Database/MySQLConnection.cpp @@ -17,7 +17,7 @@ #include "MySQLConnection.h" #include "Common.h" -#include "DatabaseWorker.h" +#include "IoContext.h" #include "Log.h" #include "MySQLHacks.h" #include "MySQLPreparedStatement.h" @@ -64,7 +64,11 @@ MySQLConnection::~MySQLConnection() void MySQLConnection::Close() { // Stop the worker thread before the statements are cleared - m_worker.reset(); + if (m_workerThread) + { + m_workerThread->join(); + m_workerThread.reset(); + } m_stmts.clear(); @@ -442,9 +446,22 @@ uint32 MySQLConnection::GetLastError() return mysql_errno(m_Mysql); } -void MySQLConnection::StartDatabaseWorkerThread(ProducerConsumerQueue<SQLOperation*>* queue) +void MySQLConnection::StartWorkerThread(Trinity::Asio::IoContext* context) +{ + m_workerThread = std::make_unique<std::thread>([context] + { + boost::asio::executor_work_guard executorWorkGuard = boost::asio::make_work_guard(context->get_executor()); + + context->run(); + }); +} + +std::thread::id MySQLConnection::GetWorkerThreadId() const { - m_worker = std::make_unique<DatabaseWorker>(queue, this); + if (m_workerThread) + return m_workerThread->get_id(); + + return {}; } bool MySQLConnection::LockIfReady() |