mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-21 01:37:37 +01:00
Reimplement ACE_Based::LockedQueue as SQL holder for the SqlTransaction class, since std::queue is not safe when multiple threads are reading/writing to it at the same time (SqlDelayThread and a MapUpdate Thread).
Original patch by thenecromancer, was removed for ungrounded reasons. Thanks to Zor for the insight. Please give feedback on how this affects mtmaps usage. --HG-- branch : trunk
This commit is contained in:
@@ -33,23 +33,18 @@ void SqlStatement::Execute(Database *db)
|
||||
|
||||
void SqlTransaction::Execute(Database *db)
|
||||
{
|
||||
if (m_queue.empty())
|
||||
return;
|
||||
const char* sql;
|
||||
|
||||
db->DirectExecute("START TRANSACTION");
|
||||
while (!m_queue.empty())
|
||||
while (m_queue.next(sql))
|
||||
{
|
||||
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.empty())
|
||||
while (m_queue.next(sql))
|
||||
{
|
||||
free((void*)const_cast<char*>(m_queue.front()));
|
||||
m_queue.pop();
|
||||
free((void*)const_cast<char*>(sql));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -57,11 +57,12 @@ class SqlStatement : public SqlOperation
|
||||
|
||||
class SqlTransaction : public SqlOperation
|
||||
{
|
||||
typedef ACE_Based::LockedQueue<const char *, ACE_Thread_Mutex> LockedQueue;
|
||||
private:
|
||||
std::queue<const char *> m_queue;
|
||||
LockedQueue m_queue;
|
||||
public:
|
||||
SqlTransaction() {}
|
||||
void DelayExecute(const char *sql) { m_queue.push(strdup(sql)); }
|
||||
void DelayExecute(const char *sql) { m_queue.add(strdup(sql)); }
|
||||
void Execute(Database *db);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user