Core/DBLayer: Optimization in transaction code, and prevent a crash and memleak on shutdown.
--HG-- branch : trunk
This commit is contained in:
@@ -48,13 +48,14 @@ class DatabaseWorker : public ACE_Task_Base
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
SQLOperation *request = NULL;
|
SQLOperation *request = NULL;
|
||||||
|
MySQLConnection* con = NULL;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
request = (SQLOperation*)(m_queue->dequeue());
|
request = (SQLOperation*)(m_queue->dequeue());
|
||||||
if (!request)
|
if (!request)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
MySQLConnection* con = m_pool->GetFreeConnection();
|
con = m_pool->GetFreeConnection();
|
||||||
request->SetConnection(con);
|
request->SetConnection(con);
|
||||||
request->call();
|
request->call();
|
||||||
con->Unlock();
|
con->Unlock();
|
||||||
@@ -62,7 +63,6 @@ class DatabaseWorker : public ACE_Task_Base
|
|||||||
delete request;
|
delete request;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_conn->Close();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +86,6 @@ class DatabaseWorker : public ACE_Task_Base
|
|||||||
private:
|
private:
|
||||||
DatabaseWorker() : ACE_Task_Base() {}
|
DatabaseWorker() : ACE_Task_Base() {}
|
||||||
ACE_Activation_Queue* m_queue;
|
ACE_Activation_Queue* m_queue;
|
||||||
MySQLConnection* m_conn;
|
|
||||||
DatabaseWorkerPool<T>* m_pool; // Databasepool we operate on
|
DatabaseWorkerPool<T>* m_pool; // Databasepool we operate on
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,11 @@ class DatabaseWorkerPool
|
|||||||
m_queue->queue()->deactivate();
|
m_queue->queue()->deactivate();
|
||||||
|
|
||||||
for (uint8 i = 0; i < m_delaythreads.size(); ++i)
|
for (uint8 i = 0; i < m_delaythreads.size(); ++i)
|
||||||
m_delaythreads[i]->wait();
|
{
|
||||||
|
DatabaseWorker<T>* worker = m_delaythreads[i];
|
||||||
|
worker->wait();
|
||||||
|
delete worker;
|
||||||
|
}
|
||||||
|
|
||||||
/// Shut down the connections
|
/// Shut down the connections
|
||||||
for (uint8 i = 0; i < m_connectionCount; ++i)
|
for (uint8 i = 0; i < m_connectionCount; ++i)
|
||||||
@@ -241,16 +245,19 @@ class DatabaseWorkerPool
|
|||||||
{
|
{
|
||||||
if (sLog.GetSQLDriverQueryLogging())
|
if (sLog.GetSQLDriverQueryLogging())
|
||||||
{
|
{
|
||||||
if (transaction->GetSize() == 0)
|
switch (transaction->GetSize())
|
||||||
{
|
{
|
||||||
|
case 0:
|
||||||
sLog.outSQLDriver("Transaction contains 0 queries. Not executing.");
|
sLog.outSQLDriver("Transaction contains 0 queries. Not executing.");
|
||||||
return;
|
return;
|
||||||
}
|
case 1:
|
||||||
if (transaction->GetSize() == 1)
|
|
||||||
{
|
|
||||||
sLog.outSQLDriver("Warning: Transaction only holds 1 query, consider removing Transaction context in code.");
|
sLog.outSQLDriver("Warning: Transaction only holds 1 query, consider removing Transaction context in code.");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Enqueue(new TransactionTask(transaction));
|
Enqueue(new TransactionTask(transaction));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user