Implemented separate connection for SqlDelayThread

This should result in less locking when accessing database,
  and improved performance.
* Changed SqlDelay queue type to monitored queue,
  and removed 10ms check period.
thanks to Derex, mknjc, Jeniczek and Christyan for ideas and tests.

--HG--
branch : trunk
This commit is contained in:
raczman
2009-06-25 15:56:45 +02:00
parent e92f3cf01f
commit b8a1ffcf50
6 changed files with 31 additions and 22 deletions
+17 -10
View File
@@ -22,8 +22,12 @@
#include "Database/SqlOperations.h"
#include "DatabaseEnv.h"
SqlDelayThread::SqlDelayThread(Database* db) : m_dbEngine(db), m_running(true)
SqlDelayThread::SqlDelayThread(Database* db, const char* infoString) :m_running(true)
{
m_dbEngine = new DatabaseType;
((DatabaseType*)m_dbEngine)->Initialize(infoString, false);
}
void SqlDelayThread::run()
@@ -35,15 +39,17 @@ void SqlDelayThread::run()
while (m_running)
{
// if the running state gets turned off while sleeping
// empty the queue before exiting
ZThread::Thread::sleep(10);
while (!m_sqlQueue.empty())
{
s = m_sqlQueue.next();
s->Execute(m_dbEngine);
delete s;
}
try
{
s = m_sqlQueue.next();
}
catch(...)
{continue;}
if(!s)
continue;
s->Execute(m_dbEngine);
delete s;
}
#ifndef DO_POSTGRESQL
@@ -54,5 +60,6 @@ void SqlDelayThread::run()
void SqlDelayThread::Stop()
{
m_running = false;
m_sqlQueue.cancel();
}