mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 16:37:01 +00:00
[10865] Make DB code thread-safe. Original patch by Machiavelli and Kero99.
Signed-off-by: Ambal <pogrebniak@gala.net>
This commit is contained in:
parent
9b3535f803
commit
af66b470a8
8 changed files with 53 additions and 26 deletions
|
|
@ -264,6 +264,8 @@ bool DatabaseMysql::Execute(const char *sql)
|
|||
// don't use queued execution if it has not been initialized
|
||||
if (!m_threadBody) return DirectExecute(sql);
|
||||
|
||||
ACE_Guard<ACE_Thread_Mutex> _lock(nMutex);
|
||||
|
||||
tranThread = ACE_Based::Thread::current(); // owner of this transaction
|
||||
TransactionQueues::iterator i = m_tranQueues.find(tranThread);
|
||||
if (i != m_tranQueues.end() && i->second != NULL)
|
||||
|
|
@ -341,6 +343,8 @@ bool DatabaseMysql::BeginTransaction()
|
|||
return true; // transaction started
|
||||
}
|
||||
|
||||
ACE_Guard<ACE_Thread_Mutex> _lock(nMutex);
|
||||
|
||||
tranThread = ACE_Based::Thread::current(); // owner of this transaction
|
||||
TransactionQueues::iterator i = m_tranQueues.find(tranThread);
|
||||
if (i != m_tranQueues.end() && i->second != NULL)
|
||||
|
|
@ -369,16 +373,18 @@ bool DatabaseMysql::CommitTransaction()
|
|||
return _res;
|
||||
}
|
||||
|
||||
ACE_Guard<ACE_Thread_Mutex> _lock(nMutex);
|
||||
|
||||
tranThread = ACE_Based::Thread::current();
|
||||
TransactionQueues::iterator i = m_tranQueues.find(tranThread);
|
||||
if (i != m_tranQueues.end() && i->second != NULL)
|
||||
{
|
||||
m_threadBody->Delay(i->second);
|
||||
i->second = NULL;
|
||||
m_tranQueues.erase(i);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DatabaseMysql::RollbackTransaction()
|
||||
|
|
@ -397,13 +403,16 @@ bool DatabaseMysql::RollbackTransaction()
|
|||
return _res;
|
||||
}
|
||||
|
||||
ACE_Guard<ACE_Thread_Mutex> _lock(nMutex);
|
||||
|
||||
tranThread = ACE_Based::Thread::current();
|
||||
TransactionQueues::iterator i = m_tranQueues.find(tranThread);
|
||||
if (i != m_tranQueues.end() && i->second != NULL)
|
||||
{
|
||||
delete i->second;
|
||||
i->second = NULL;
|
||||
m_tranQueues.erase(i);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue