aboutsummaryrefslogtreecommitdiff
path: root/src/server/database/Database/MySQLConnection.cpp
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2023-12-15 12:06:59 +0100
committerfunjoker <funjoker109@gmail.com>2023-12-19 14:14:23 +0100
commite0d45f6dff3afe5caa38c48646f23d966c8c03a1 (patch)
tree6d1b9fef794cec268fa86398d9bb8957cf99f5ba /src/server/database/Database/MySQLConnection.cpp
parent575fc7fde329ab47e517357d74a47316c6413544 (diff)
Core/Database: Replace DatabaseWorker with asio io_context
(cherry picked from commit d958bfd0f32bfe798809b72c1b51c990edfe141c)
Diffstat (limited to 'src/server/database/Database/MySQLConnection.cpp')
-rw-r--r--src/server/database/Database/MySQLConnection.cpp25
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()