mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-21 09:44:45 +01:00
Revert revision: 053bfe8ad9, this cause some crash.
Use dynamic_cast more is safer. I think no more crash on db code. --HG-- branch : trunk
This commit is contained in:
@@ -32,13 +32,14 @@ void SqlDelayThread::run()
|
||||
mysql_thread_init();
|
||||
#endif
|
||||
|
||||
SqlAsyncTask * s = NULL;
|
||||
// Lets wait for next async task no more than 2 secs
|
||||
ACE_Time_Value _time(2);
|
||||
while (m_running)
|
||||
{
|
||||
// if the running state gets turned off while sleeping
|
||||
// empty the queue before exiting
|
||||
SqlAsyncTask * s = (SqlAsyncTask*)m_sqlQueue.dequeue(/*&_time*/);
|
||||
s = dynamic_cast<SqlAsyncTask*> (m_sqlQueue.dequeue());
|
||||
if(s)
|
||||
{
|
||||
s->call();
|
||||
|
||||
@@ -33,17 +33,23 @@ void SqlStatement::Execute(Database *db)
|
||||
|
||||
void SqlTransaction::Execute(Database *db)
|
||||
{
|
||||
const char *sql;
|
||||
if (m_queue.empty())
|
||||
return;
|
||||
|
||||
db->DirectExecute("START TRANSACTION");
|
||||
while(m_queue.next(sql))
|
||||
while(!m_queue.empty())
|
||||
{
|
||||
char const *sql = m_queue.front();
|
||||
m_queue.pop();
|
||||
|
||||
if(!db->DirectExecute(sql))
|
||||
{
|
||||
free((void*)const_cast<char*>(sql));
|
||||
db->DirectExecute("ROLLBACK");
|
||||
while(m_queue.next(sql))
|
||||
while(!m_queue.empty())
|
||||
{
|
||||
free((void*)const_cast<char*>(sql));
|
||||
free((void*)const_cast<char*>(m_queue.front()));
|
||||
m_queue.pop();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -57,13 +57,11 @@ class SqlStatement : public SqlOperation
|
||||
|
||||
class SqlTransaction : public SqlOperation
|
||||
{
|
||||
typedef ACE_Based::LockedQueue<const char *, ACE_Thread_Mutex> LockedQueue;
|
||||
|
||||
private:
|
||||
LockedQueue m_queue;
|
||||
std::queue<const char *> m_queue;
|
||||
public:
|
||||
SqlTransaction() {}
|
||||
void DelayExecute(const char *sql) { m_queue.add(strdup(sql)); }
|
||||
void DelayExecute(const char *sql) { m_queue.push(strdup(sql)); }
|
||||
void Execute(Database *db);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user