OregonCore  revision 80751cf-git
Your Favourite TBC server
SqlDelayThread Class Reference

#include <SqlDelayThread.h>

+ Inheritance diagram for SqlDelayThread:

Public Member Functions

 SqlDelayThread (Database *db)
 
bool Delay (SqlOperation *sql)
 
void Stop ()
 
void run () override
 
- Public Member Functions inherited from ACE_Based::Runnable
virtual ~Runnable ()
 
void incReference ()
 
void decReference ()
 

Private Types

typedef ACE_Activation_Queue SqlQueue
 

Private Member Functions

 SqlDelayThread ()
 

Private Attributes

SqlQueue m_sqlQueue
 
Databasem_dbEngine
 
volatile bool m_running
 

Detailed Description

Definition at line 28 of file SqlDelayThread.h.

Member Typedef Documentation

typedef ACE_Activation_Queue SqlDelayThread::SqlQueue
private

Definition at line 30 of file SqlDelayThread.h.

Constructor & Destructor Documentation

SqlDelayThread::SqlDelayThread ( )
private
SqlDelayThread::SqlDelayThread ( Database db)

Definition at line 22 of file SqlDelayThread.cpp.

22  : m_dbEngine(db), m_running(true)
23 {
24 }
Database * m_dbEngine
volatile bool m_running

Member Function Documentation

bool SqlDelayThread::Delay ( SqlOperation sql)

Definition at line 59 of file SqlDelayThread.cpp.

References m_dbEngine, and m_sqlQueue.

Referenced by Database::AsyncQuery(), Database::CommitTransaction(), Database::Execute(), SqlQueryHolder::Execute(), and Database::PreparedExecute().

60 {
61  int res = m_sqlQueue.enqueue(new SqlAsyncTask(m_dbEngine, sql));
62  return (res != -1);
63 }
Database * m_dbEngine
SqlQueue m_sqlQueue
void SqlDelayThread::run ( void  )
overridevirtual

Implements ACE_Based::Runnable.

Definition at line 26 of file SqlDelayThread.cpp.

References SqlAsyncTask::call(), m_running, and m_sqlQueue.

27 {
28  mysql_thread_init();
29 
30  SqlAsyncTask* s = NULL;
31 
32  ACE_Time_Value _time(2);
33  while (m_running)
34  {
35  // if the running state gets turned off while sleeping
36  // empty the queue before exiting
37  s = dynamic_cast<SqlAsyncTask*> (m_sqlQueue.dequeue());
38  if (s)
39  {
40  s->call();
41  delete s;
42  }
43  }
44 
45  mysql_thread_end();
46 }
volatile bool m_running
SqlQueue m_sqlQueue
void SqlDelayThread::Stop ( )

Definition at line 48 of file SqlDelayThread.cpp.

References m_running, m_sqlQueue, and ACE_Based::Thread::Sleep().

Referenced by Database::HaltDelayThread().

49 {
50  // wait for queue to become empty, so no query
51  // will be missed and also no memory leak will be created
52  while (m_sqlQueue.method_count())
54 
55  m_running = false;
56  m_sqlQueue.queue()->deactivate();
57 }
volatile bool m_running
static void Sleep(unsigned long msecs)
Definition: Threading.cpp:237
SqlQueue m_sqlQueue

Member Data Documentation

Database* SqlDelayThread::m_dbEngine
private

Definition at line 34 of file SqlDelayThread.h.

Referenced by Delay().

volatile bool SqlDelayThread::m_running
private

Definition at line 35 of file SqlDelayThread.h.

Referenced by run(), and Stop().

SqlQueue SqlDelayThread::m_sqlQueue
private

Definition at line 33 of file SqlDelayThread.h.

Referenced by Delay(), run(), and Stop().


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