diff options
author | Machiavelli <none@none> | 2010-05-26 19:04:13 +0200 |
---|---|---|
committer | Machiavelli <none@none> | 2010-05-26 19:04:13 +0200 |
commit | 6da6879effad0e7b86c908fe01f14b8448da6db1 (patch) | |
tree | d5a999f0df9331a57167149ebe1dd3a0ac17e492 /src/shared/Database/Database.cpp | |
parent | 3cd4626dacddf9ba34473f2dac511ea0c07bd048 (diff) |
Add another ACE_Thread_Mutex in Database class for threadsafe operations on m_transQueues.
Fixes crash specified in comment #8 on issue #2214
--HG--
branch : trunk
Diffstat (limited to 'src/shared/Database/Database.cpp')
-rw-r--r-- | src/shared/Database/Database.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
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; } |