Core/Database: Refactor MySQLConnection constructors and async thread creation

This commit is contained in:
Shauren
2023-12-14 17:00:58 +01:00
parent 685ead8642
commit 5c59e2a248
11 changed files with 25 additions and 50 deletions

View File

@@ -47,23 +47,13 @@ MySQLConnectionInfo::MySQLConnectionInfo(std::string const& infoString)
ssl.assign(tokens[5]);
}
MySQLConnection::MySQLConnection(MySQLConnectionInfo& connInfo) :
MySQLConnection::MySQLConnection(MySQLConnectionInfo& connInfo, ConnectionFlags connectionFlags) :
m_reconnecting(false),
m_prepareError(false),
m_queue(nullptr),
m_Mysql(nullptr),
m_connectionInfo(connInfo),
m_connectionFlags(CONNECTION_SYNCH) { }
MySQLConnection::MySQLConnection(ProducerConsumerQueue<SQLOperation*>* queue, MySQLConnectionInfo& connInfo) :
m_reconnecting(false),
m_prepareError(false),
m_queue(queue),
m_Mysql(nullptr),
m_connectionInfo(connInfo),
m_connectionFlags(CONNECTION_ASYNC)
m_connectionFlags(connectionFlags)
{
m_worker = std::make_unique<DatabaseWorker>(m_queue, this);
}
MySQLConnection::~MySQLConnection()
@@ -452,6 +442,11 @@ uint32 MySQLConnection::GetLastError()
return mysql_errno(m_Mysql);
}
void MySQLConnection::StartDatabaseWorkerThread(ProducerConsumerQueue<SQLOperation*>* queue)
{
m_worker = std::make_unique<DatabaseWorker>(queue, this);
}
bool MySQLConnection::LockIfReady()
{
return m_Mutex.try_lock();