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:
n0n4m3
2010-02-10 16:04:48 +03:00
parent 1e4684826e
commit 293ea07a25
3 changed files with 14 additions and 9 deletions
+2 -1
View File
@@ -32,13 +32,14 @@ void SqlDelayThread::run()
mysql_thread_init(); mysql_thread_init();
#endif #endif
SqlAsyncTask * s = NULL;
// Lets wait for next async task no more than 2 secs // Lets wait for next async task no more than 2 secs
ACE_Time_Value _time(2); ACE_Time_Value _time(2);
while (m_running) while (m_running)
{ {
// if the running state gets turned off while sleeping // if the running state gets turned off while sleeping
// empty the queue before exiting // empty the queue before exiting
SqlAsyncTask * s = (SqlAsyncTask*)m_sqlQueue.dequeue(/*&_time*/); s = dynamic_cast<SqlAsyncTask*> (m_sqlQueue.dequeue());
if(s) if(s)
{ {
s->call(); s->call();
+10 -4
View File
@@ -33,17 +33,23 @@ void SqlStatement::Execute(Database *db)
void SqlTransaction::Execute(Database *db) void SqlTransaction::Execute(Database *db)
{ {
const char *sql; if (m_queue.empty())
return;
db->DirectExecute("START TRANSACTION"); 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)) if(!db->DirectExecute(sql))
{ {
free((void*)const_cast<char*>(sql)); free((void*)const_cast<char*>(sql));
db->DirectExecute("ROLLBACK"); 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; return;
} }
+2 -4
View File
@@ -57,13 +57,11 @@ class SqlStatement : public SqlOperation
class SqlTransaction : public SqlOperation class SqlTransaction : public SqlOperation
{ {
typedef ACE_Based::LockedQueue<const char *, ACE_Thread_Mutex> LockedQueue;
private: private:
LockedQueue m_queue; std::queue<const char *> m_queue;
public: public:
SqlTransaction() {} 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); void Execute(Database *db);
}; };