[10865] Make DB code thread-safe. Original patch by Machiavelli and Kero99.

Signed-off-by: Ambal <pogrebniak@gala.net>
This commit is contained in:
Ambal 2010-12-12 11:34:26 +02:00
parent 9b3535f803
commit af66b470a8
8 changed files with 53 additions and 26 deletions

View file

@ -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;
}