2017-09-30 23:51:01 +02:00
|
|
|
#include "DbWorker.h"
|
|
|
|
#include "Operation.h"
|
|
|
|
#include <Server_Common/Util/LockedWaitQueue.h>
|
|
|
|
|
2017-10-07 23:10:13 +02:00
|
|
|
Core::Db::DbWorker::DbWorker( Core::LockedWaitQueue< boost::shared_ptr< Operation > >* newQueue, DbConnection* pConn )
|
2017-09-30 23:51:01 +02:00
|
|
|
{
|
|
|
|
m_pConn = pConn;
|
|
|
|
m_queue = newQueue;
|
|
|
|
m_cancelationToken = false;
|
|
|
|
m_workerThread = std::thread( &DbWorker::workerThread, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
Core::Db::DbWorker::~DbWorker()
|
|
|
|
{
|
|
|
|
m_cancelationToken = true;
|
|
|
|
m_queue->cancel();
|
|
|
|
m_workerThread.join();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Db::DbWorker::workerThread()
|
|
|
|
{
|
|
|
|
if( !m_queue )
|
|
|
|
return;
|
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2017-10-07 23:10:13 +02:00
|
|
|
boost::shared_ptr< Operation > operation = nullptr;
|
2017-09-30 23:51:01 +02:00
|
|
|
|
|
|
|
m_queue->waitAndPop( operation );
|
|
|
|
|
|
|
|
if( m_cancelationToken || !operation )
|
|
|
|
return;
|
|
|
|
|
|
|
|
operation->setConnection( m_pConn );
|
|
|
|
operation->call();
|
|
|
|
}
|
|
|
|
}
|