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;
|
||||
|
||||
SQLOperation *request = NULL;
|
||||
MySQLConnection* con = NULL;
|
||||
while (1)
|
||||
{
|
||||
request = (SQLOperation*)(m_queue->dequeue());
|
||||
if (!request)
|
||||
break;
|
||||
|
||||
MySQLConnection* con = m_pool->GetFreeConnection();
|
||||
con = m_pool->GetFreeConnection();
|
||||
request->SetConnection(con);
|
||||
request->call();
|
||||
con->Unlock();
|
||||
@@ -62,7 +63,6 @@ class DatabaseWorker : public ACE_Task_Base
|
||||
delete request;
|
||||
}
|
||||
|
||||
m_conn->Close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,6 @@ class DatabaseWorker : public ACE_Task_Base
|
||||
private:
|
||||
DatabaseWorker() : ACE_Task_Base() {}
|
||||
ACE_Activation_Queue* m_queue;
|
||||
MySQLConnection* m_conn;
|
||||
DatabaseWorkerPool<T>* m_pool; // Databasepool we operate on
|
||||
};
|
||||
|
||||
|
||||
@@ -98,7 +98,11 @@ class DatabaseWorkerPool
|
||||
m_queue->queue()->deactivate();
|
||||
|
||||
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
|
||||
for (uint8 i = 0; i < m_connectionCount; ++i)
|
||||
@@ -241,16 +245,19 @@ class DatabaseWorkerPool
|
||||
{
|
||||
if (sLog.GetSQLDriverQueryLogging())
|
||||
{
|
||||
if (transaction->GetSize() == 0)
|
||||
switch (transaction->GetSize())
|
||||
{
|
||||
sLog.outSQLDriver("Transaction contains 0 queries. Not executing.");
|
||||
return;
|
||||
}
|
||||
if (transaction->GetSize() == 1)
|
||||
{
|
||||
sLog.outSQLDriver("Warning: Transaction only holds 1 query, consider removing Transaction context in code.");
|
||||
case 0:
|
||||
sLog.outSQLDriver("Transaction contains 0 queries. Not executing.");
|
||||
return;
|
||||
case 1:
|
||||
sLog.outSQLDriver("Warning: Transaction only holds 1 query, consider removing Transaction context in code.");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Enqueue(new TransactionTask(transaction));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user