TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
 

Constructor & Destructor Documentation

DatabaseWorker::DatabaseWorker ( ProducerConsumerQueue< SQLOperation * > *  newQueue,
MySQLConnection *  connection 
)
26 {
27  _connection = connection;
28  _queue = newQueue;
29  _cancelationToken = false;
30  _workerThread = std::thread(&DatabaseWorker::WorkerThread, this);
31 }
void WorkerThread()
Definition: DatabaseWorker.cpp:42
std::thread _workerThread
Definition: DatabaseWorker.h:38
MySQLConnection * _connection
Definition: DatabaseWorker.h:35
std::atomic_bool _cancelationToken
Definition: DatabaseWorker.h:40
ProducerConsumerQueue< SQLOperation * > * _queue
Definition: DatabaseWorker.h:34

+ Here is the call graph for this function:

DatabaseWorker::~DatabaseWorker ( )
34 {
35  _cancelationToken = true;
36 
37  _queue->Cancel();
38 
39  _workerThread.join();
40 }
std::thread _workerThread
Definition: DatabaseWorker.h:38
void Cancel()
Definition: ProducerConsumerQueue.h:86
std::atomic_bool _cancelationToken
Definition: DatabaseWorker.h:40
ProducerConsumerQueue< SQLOperation * > * _queue
Definition: DatabaseWorker.h:34

+ Here is the call graph for this function:

DatabaseWorker::DatabaseWorker ( DatabaseWorker const right)
privatedelete

Member Function Documentation

DatabaseWorker& DatabaseWorker::operator= ( DatabaseWorker const right)
privatedelete
void DatabaseWorker::WorkerThread ( )
private
43 {
44  if (!_queue)
45  return;
46 
47  for (;;)
48  {
49  SQLOperation* operation = nullptr;
50 
51  _queue->WaitAndPop(operation);
52 
53  if (_cancelationToken || !operation)
54  return;
55 
56  operation->SetConnection(_connection);
57  operation->call();
58 
59  delete operation;
60  }
61 }
virtual int call()
Definition: SQLOperation.h:62
virtual void SetConnection(MySQLConnection *con)
Definition: SQLOperation.h:68
void WaitAndPop(T &value)
Definition: ProducerConsumerQueue.h:69
MySQLConnection * _connection
Definition: DatabaseWorker.h:35
Definition: SQLOperation.h:56
std::atomic_bool _cancelationToken
Definition: DatabaseWorker.h:40
ProducerConsumerQueue< SQLOperation * > * _queue
Definition: DatabaseWorker.h:34

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::atomic_bool DatabaseWorker::_cancelationToken
private
MySQLConnection* DatabaseWorker::_connection
private
ProducerConsumerQueue<SQLOperation*>* DatabaseWorker::_queue
private
std::thread DatabaseWorker::_workerThread
private

The documentation for this class was generated from the following files: