2017-09-30 23:51:01 +02:00
|
|
|
#ifndef SAPPHIRE_DBWORKER_H
|
|
|
|
#define SAPPHIRE_DBWORKER_H
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <thread>
|
2018-03-06 22:22:19 +01:00
|
|
|
#include "Util/LockedWaitQueue.h"
|
2018-10-24 12:53:26 +02:00
|
|
|
#include <memory>
|
2017-09-30 23:51:01 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
namespace Core::Db
|
2017-09-30 23:51:01 +02:00
|
|
|
{
|
2018-10-28 21:53:21 +01:00
|
|
|
class DbConnection;
|
|
|
|
class Operation;
|
2017-09-30 23:51:01 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
class DbWorker
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DbWorker( LockedWaitQueue< std::shared_ptr< Operation > >* newQueue, DbConnection* connection );
|
2017-09-30 23:51:01 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
~DbWorker();
|
2017-09-30 23:51:01 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
private:
|
|
|
|
LockedWaitQueue< std::shared_ptr< Operation > >* m_queue;
|
|
|
|
DbConnection* m_pConn;
|
2017-09-30 23:51:01 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
void workerThread();
|
2017-09-30 23:51:01 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
std::thread m_workerThread;
|
2018-08-29 21:40:59 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
std::atomic< bool > m_cancelationToken;
|
2018-08-29 21:40:59 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
DbWorker( DbWorker const& right ) = delete;
|
2017-09-30 23:51:01 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
DbWorker& operator=( DbWorker const& right ) = delete;
|
|
|
|
};
|
|
|
|
}
|
2017-09-30 23:51:01 +02:00
|
|
|
|
|
|
|
#endif //SAPPHIRE_DBWORKER_H
|