aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.hgtags1
-rw-r--r--src/shared/Database/Database.cpp19
-rw-r--r--src/shared/Database/Database.h3
-rw-r--r--src/shared/Database/SqlOperations.cpp23
-rw-r--r--src/shared/Database/SqlOperations.h13
5 files changed, 39 insertions, 20 deletions
diff --git a/.hgtags b/.hgtags
index f44f5f8abd4..cc1816152b3 100644
--- a/.hgtags
+++ b/.hgtags
@@ -24,3 +24,4 @@ eed51550303dd1ca6c8617711265ec573c085263 3.2.2a-last
b048ef8c4b39afb28c66f5c16a2d2cc5eb8d12d2 3.2.2a-really-last
433ffdb940c1589af6b0243fb40f74cbc12e6a18 3.3.2-last
50ede8e9dc8a83776fb6a0bfe17af9391c17b625 Teacher's & SoulForge's birthday
+e653a5b8d0100c99337e012e4b66848efd028cfb UP30
diff --git a/src/shared/Database/Database.cpp b/src/shared/Database/Database.cpp
index 40ab58fa621..73924b485ce 100644
--- a/src/shared/Database/Database.cpp
+++ b/src/shared/Database/Database.cpp
@@ -388,6 +388,7 @@ bool Database::Execute(const char *sql)
if (!m_threadBody)
return DirectExecute(sql);
+ nMutex.acquire();
tranThread = ACE_Based::Thread::current(); // owner of this transaction
TransactionQueues::iterator i = m_tranQueues.find(tranThread);
if (i != m_tranQueues.end() && i->second != NULL)
@@ -395,6 +396,7 @@ bool Database::Execute(const char *sql)
else
m_threadBody->Delay(new SqlStatement(sql)); // Simple sql statement
+ nMutex.release();
return true;
}
@@ -557,6 +559,7 @@ bool Database::BeginTransaction()
return true; // transaction started
}
+ nMutex.acquire();
tranThread = ACE_Based::Thread::current(); // owner of this transaction
TransactionQueues::iterator i = m_tranQueues.find(tranThread);
if (i != m_tranQueues.end() && i->second != NULL)
@@ -565,7 +568,7 @@ bool Database::BeginTransaction()
delete i->second;
m_tranQueues[tranThread] = new SqlTransaction();
-
+ nMutex.release();
return true;
}
@@ -574,28 +577,31 @@ bool Database::CommitTransaction()
if (!mMysql)
return false;
+ bool _res = false;
+
// don't use queued execution if it has not been initialized
if (!m_threadBody)
{
if (tranThread != ACE_Based::Thread::current())
return false;
- bool _res = _TransactionCmd("COMMIT");
+ _res = _TransactionCmd("COMMIT");
tranThread = NULL;
mMutex.release();
return _res;
}
+ nMutex.acquire();
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);
m_tranQueues.erase(i);
- return true;
+ _res = true;
}
- else
- return false;
+ nMutex.release();
+ return _res;
}
bool Database::RollbackTransaction()
@@ -615,6 +621,7 @@ bool Database::RollbackTransaction()
return _res;
}
+ nMutex.acquire();
tranThread = ACE_Based::Thread::current();
TransactionQueues::iterator i = m_tranQueues.find(tranThread);
if (i != m_tranQueues.end() && i->second != NULL)
@@ -623,7 +630,7 @@ bool Database::RollbackTransaction()
i->second = NULL;
m_tranQueues.erase(i);
}
-
+ nMutex.release();
return true;
}
diff --git a/src/shared/Database/Database.h b/src/shared/Database/Database.h
index 4a648ad2e80..4ad5d29c993 100644
--- a/src/shared/Database/Database.h
+++ b/src/shared/Database/Database.h
@@ -139,7 +139,8 @@ class Database
private:
bool m_logSQL;
std::string m_logsDir;
- ACE_Thread_Mutex mMutex;
+ ACE_Thread_Mutex mMutex; // For thread safe operations between core and mySQL server
+ ACE_Thread_Mutex nMutex; // For thread safe operations on m_transQueues
ACE_Based::Thread * tranThread;
diff --git a/src/shared/Database/SqlOperations.cpp b/src/shared/Database/SqlOperations.cpp
index 8894f896855..785c5cb84e7 100644
--- a/src/shared/Database/SqlOperations.cpp
+++ b/src/shared/Database/SqlOperations.cpp
@@ -35,35 +35,38 @@ void SqlTransaction::Execute(Database *db)
{
const char* sql;
+ m_Mutex.acquire();
if (m_queue.empty())
+ {
+ m_Mutex.release();
return;
-
+ }
+
db->DirectExecute("START TRANSACTION");
while (!m_queue.empty())
{
- sql = m_queue.peek();
- m_queue.unlock();
+ sql = m_queue.front();
+
if (!db->DirectExecute(sql))
{
free((void*)const_cast<char*>(sql));
- m_queue.pop_front();
+ m_queue.pop();
db->DirectExecute("ROLLBACK");
while (!m_queue.empty())
{
- sql = m_queue.peek();
- m_queue.unlock();
- free((void*)const_cast<char*>(sql));
- m_queue.pop_front();
+ free((void*)const_cast<char*>(m_queue.front()));
+ m_queue.pop();
}
-
+ m_Mutex.release();
return;
}
free((void*)const_cast<char*>(sql));
- m_queue.pop_front();
+ m_queue.pop();
}
db->DirectExecute("COMMIT");
+ m_Mutex.release();
}
/// ---- ASYNC QUERIES ----
diff --git a/src/shared/Database/SqlOperations.h b/src/shared/Database/SqlOperations.h
index dcdada9cb59..f2e09c0c921 100644
--- a/src/shared/Database/SqlOperations.h
+++ b/src/shared/Database/SqlOperations.h
@@ -57,12 +57,19 @@ 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;
+ ACE_Thread_Mutex m_Mutex;
public:
SqlTransaction() {}
- void DelayExecute(const char *sql) { m_queue.add(strdup(sql)); }
+ void DelayExecute(const char *sql)
+ {
+ m_Mutex.acquire();
+ char* _sql = strdup(sql);
+ if (_sql)
+ m_queue.push(_sql);
+ m_Mutex.release();
+ }
void Execute(Database *db);
};