AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
DatabaseWorker Class Reference

#include "DatabaseWorker.h"

Public Member Functions

 DatabaseWorker (ProducerConsumerQueue< SQLOperation * > *newQueue, MySQLConnection *connection)
 
 ~DatabaseWorker ()
 

Private Member Functions

void WorkerThread ()
 
 DatabaseWorker (DatabaseWorker const &right)=delete
 
DatabaseWorkeroperator= (DatabaseWorker const &right)=delete
 

Private Attributes

ProducerConsumerQueue< SQLOperation * > * _queue
 
MySQLConnection_connection
 
std::thread _workerThread
 
std::atomic< bool > _cancelationToken
 

Detailed Description

Constructor & Destructor Documentation

◆ DatabaseWorker() [1/2]

DatabaseWorker::DatabaseWorker ( ProducerConsumerQueue< SQLOperation * > *  newQueue,
MySQLConnection connection 
)
23{
24 _connection = connection;
25 _queue = newQueue;
26 _cancelationToken = false;
27 _workerThread = std::thread(&DatabaseWorker::WorkerThread, this);
28}
MySQLConnection * _connection
Definition: DatabaseWorker.h:39
std::atomic< bool > _cancelationToken
Definition: DatabaseWorker.h:44
ProducerConsumerQueue< SQLOperation * > * _queue
Definition: DatabaseWorker.h:38
void WorkerThread()
Definition: DatabaseWorker.cpp:39
std::thread _workerThread
Definition: DatabaseWorker.h:42

References _cancelationToken, _connection, _queue, _workerThread, and WorkerThread().

◆ ~DatabaseWorker()

DatabaseWorker::~DatabaseWorker ( )
31{
32 _cancelationToken = true;
33
34 _queue->Cancel();
35
36 _workerThread.join();
37}
void Cancel()
Definition: PCQueue.h:93

References _cancelationToken, _queue, _workerThread, and ProducerConsumerQueue< T >::Cancel().

◆ DatabaseWorker() [2/2]

DatabaseWorker::DatabaseWorker ( DatabaseWorker const &  right)
privatedelete

Member Function Documentation

◆ operator=()

DatabaseWorker & DatabaseWorker::operator= ( DatabaseWorker const &  right)
privatedelete

◆ WorkerThread()

void DatabaseWorker::WorkerThread ( )
private
40{
41 if (!_queue)
42 return;
43
44 for (;;)
45 {
46 SQLOperation* operation = nullptr;
47
48 _queue->WaitAndPop(operation);
49
50 if (_cancelationToken || !operation)
51 return;
52
53 operation->SetConnection(_connection);
54 operation->call();
55
56 delete operation;
57 }
58}
void WaitAndPop(T &value)
Definition: PCQueue.h:72
Definition: SQLOperation.h:42
virtual void SetConnection(MySQLConnection *con)
Definition: SQLOperation.h:54
virtual int call()
Definition: SQLOperation.h:47

References _cancelationToken, _connection, _queue, SQLOperation::call(), SQLOperation::SetConnection(), and ProducerConsumerQueue< T >::WaitAndPop().

Referenced by DatabaseWorker().

Member Data Documentation

◆ _cancelationToken

std::atomic<bool> DatabaseWorker::_cancelationToken
private

◆ _connection

MySQLConnection* DatabaseWorker::_connection
private

Referenced by DatabaseWorker(), and WorkerThread().

◆ _queue

ProducerConsumerQueue<SQLOperation*>* DatabaseWorker::_queue
private

◆ _workerThread

std::thread DatabaseWorker::_workerThread
private

Referenced by DatabaseWorker(), and ~DatabaseWorker().