mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-24 02:46:33 +01:00
Core/DBLayer:
- Add a better way to shutdown async threads in the threadpool (with thanks to Derex) - Move mysql_library_end() to DatabaseWorkerPool destructor to prevent a crash accessing mysql context from other pools after closing one pool. - Add some debug output to Init/End_MySQL_Connection functions --HG-- branch : trunk
This commit is contained in:
@@ -33,6 +33,7 @@ class DatabaseWorker : protected ACE_Task_Base
|
||||
///- Inherited from ACE_Task_Base
|
||||
int svc();
|
||||
int activate();
|
||||
int wait() { return ACE_Task_Base::wait(); }
|
||||
|
||||
private:
|
||||
DatabaseWorker() : ACE_Task_Base() {}
|
||||
|
||||
@@ -33,6 +33,7 @@ m_connections(0)
|
||||
|
||||
DatabaseWorkerPool::~DatabaseWorkerPool()
|
||||
{
|
||||
mysql_library_end();
|
||||
}
|
||||
|
||||
bool DatabaseWorkerPool::Open(const std::string& infoString, uint8 num_threads)
|
||||
@@ -61,17 +62,14 @@ void DatabaseWorkerPool::Close()
|
||||
{
|
||||
sLog.outStaticDebug("Closing down %u connections on this DatabaseWorkerPool", (uint32)m_connections.value());
|
||||
/// Shuts down worker threads for this connection pool.
|
||||
ACE_Thread_Mutex shutdown_Mtx;
|
||||
ACE_Condition_Thread_Mutex m_condition(shutdown_Mtx);
|
||||
m_queue->queue()->deactivate();
|
||||
|
||||
for (uint8 i = 0; i < m_async_connections.size(); i++)
|
||||
{
|
||||
Enqueue(new DatabaseWorkerPoolEnd(m_condition));
|
||||
m_condition.wait();
|
||||
m_async_connections[i]->m_worker->wait();
|
||||
--m_connections;
|
||||
}
|
||||
|
||||
m_queue->queue()->deactivate();
|
||||
|
||||
delete m_bundle_conn;
|
||||
m_bundle_conn = NULL;
|
||||
--m_connections;
|
||||
@@ -83,8 +81,6 @@ void DatabaseWorkerPool::Close()
|
||||
{
|
||||
}
|
||||
sLog.outStaticDebug("Synchroneous database threads exited succesfuly.");
|
||||
|
||||
mysql_library_end();
|
||||
}
|
||||
|
||||
/*! This function creates a new MySQL connection for every MapUpdate thread
|
||||
@@ -97,6 +93,11 @@ void DatabaseWorkerPool::Init_MySQL_Connection()
|
||||
|
||||
{
|
||||
ACE_Guard<ACE_Thread_Mutex> guard(m_connectionMap_mtx);
|
||||
ConnectionMap::const_iterator itr = m_sync_connections.find(ACE_Based::Thread::current());
|
||||
#ifdef _DEBUG
|
||||
if (itr != m_sync_connections.end())
|
||||
sLog.outError("Thread ["UI64FMTD"] already started a MySQL connection", (uint64)ACE_Based::Thread::currentId());
|
||||
#endif
|
||||
m_sync_connections[ACE_Based::Thread::current()] = conn;
|
||||
}
|
||||
|
||||
@@ -112,6 +113,10 @@ void DatabaseWorkerPool::End_MySQL_Connection()
|
||||
{
|
||||
ACE_Guard<ACE_Thread_Mutex> guard(m_connectionMap_mtx);
|
||||
ConnectionMap::iterator itr = m_sync_connections.find(ACE_Based::Thread::current());
|
||||
#ifdef _DEBUG
|
||||
if (itr == m_sync_connections.end())
|
||||
sLog.outError("Thread ["UI64FMTD" already shut down their MySQL connection.", (uint64)ACE_Based::Thread::currentId());
|
||||
#endif
|
||||
conn = itr->second;
|
||||
m_sync_connections.erase(itr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user