diff options
-rw-r--r-- | src/shared/Database/Database.h | 2 | ||||
-rw-r--r-- | src/shared/Database/DatabaseMysql.cpp | 4 | ||||
-rw-r--r-- | src/shared/Database/DatabasePostgre.cpp | 4 | ||||
-rw-r--r-- | src/shared/Threading.cpp | 5 | ||||
-rw-r--r-- | src/shared/Threading.h | 2 | ||||
-rw-r--r-- | src/trinitycore/Master.cpp | 31 | ||||
-rw-r--r-- | src/trinityrealm/AuthSocket.cpp | 4 |
7 files changed, 36 insertions, 16 deletions
diff --git a/src/shared/Database/Database.h b/src/shared/Database/Database.h index 7f2bdaefdb7..c7390d08a1b 100644 --- a/src/shared/Database/Database.h +++ b/src/shared/Database/Database.h @@ -41,7 +41,7 @@ class TRINITY_DLL_SPEC Database TransactionQueues m_tranQueues; ///< Transaction queues from diff. threads QueryQueues m_queryQueues; ///< Query queues from diff threads - SqlDelayThread* m_threadBody; ///< Pointer to delay sql executer + SqlDelayThread* m_threadBody; ///< Pointer to delay sql executer (owned by m_delayThread) ACE_Based::Thread* m_delayThread; ///< Pointer to executer thread public: diff --git a/src/shared/Database/DatabaseMysql.cpp b/src/shared/Database/DatabaseMysql.cpp index 0189b5883f7..f08ea67cbbe 100644 --- a/src/shared/Database/DatabaseMysql.cpp +++ b/src/shared/Database/DatabaseMysql.cpp @@ -440,8 +440,8 @@ void DatabaseMysql::InitDelayThread() assert(!m_delayThread); //New delay thread for delay execute - m_threadBody = new MySQLDelayThread(this); - m_delayThread = new ACE_Based::Thread(*m_threadBody); + m_threadBody = new MySQLDelayThread(this); // will deleted at m_delayThread delete + m_delayThread = new ACE_Based::Thread(m_threadBody); } void DatabaseMysql::HaltDelayThread() diff --git a/src/shared/Database/DatabasePostgre.cpp b/src/shared/Database/DatabasePostgre.cpp index c70067dfdba..8d00285255b 100644 --- a/src/shared/Database/DatabasePostgre.cpp +++ b/src/shared/Database/DatabasePostgre.cpp @@ -366,8 +366,8 @@ void DatabasePostgre::InitDelayThread() assert(!m_delayThread); //New delay thread for delay execute - m_threadBody = new PGSQLDelayThread(this); - m_delayThread = new ACE_Based::Thread(*m_threadBody); + m_threadBody = new PGSQLDelayThread(this); // Will be deleted on m_delayThread delete + m_delayThread = new ACE_Based::Thread(m_threadBody); } void DatabasePostgre::HaltDelayThread() diff --git a/src/shared/Threading.cpp b/src/shared/Threading.cpp index 496e86353ca..25bd3120c4a 100644 --- a/src/shared/Threading.cpp +++ b/src/shared/Threading.cpp @@ -101,7 +101,7 @@ Thread::Thread() : m_task(0), m_iThreadId(0), m_hThreadHandle(0) } -Thread::Thread(Runnable& instance) : m_task(&instance), m_iThreadId(0), m_hThreadHandle(0) +Thread::Thread(Runnable* instance) : m_task(instance), m_iThreadId(0), m_hThreadHandle(0) { bool _start = start(); ASSERT (_start); @@ -110,6 +110,9 @@ Thread::Thread(Runnable& instance) : m_task(&instance), m_iThreadId(0), m_hThrea Thread::~Thread() { //Wait(); + + // deleted runnable object (owned by Thread) + delete m_task; } //initialize Thread's class static member diff --git a/src/shared/Threading.h b/src/shared/Threading.h index eac3c0e8efb..ab423696cd1 100644 --- a/src/shared/Threading.h +++ b/src/shared/Threading.h @@ -61,7 +61,7 @@ namespace ACE_Based { public: Thread(); - Thread(Runnable& instance); + explicit Thread(Runnable* instance); ~Thread(); bool start(); diff --git a/src/trinitycore/Master.cpp b/src/trinitycore/Master.cpp index 8a5fba940f1..7e48b97eb4f 100644 --- a/src/trinitycore/Master.cpp +++ b/src/trinitycore/Master.cpp @@ -238,12 +238,14 @@ int Master::Run() _HookSignals(); ///- Launch WorldRunnable thread - ACE_Based::Thread t(*new WorldRunnable); - t.setPriority ((ACE_Based::Priority )2); + ACE_Based::Thread t(new WorldRunnable); + t.setPriority(ACE_Based::Highest); // set server online loginDatabase.PExecute("UPDATE realmlist SET color = 0, population = 0 WHERE id = '%d'",realmID); + ACE_Based::Thread* cliThread = NULL; + #ifdef WIN32 if (sConfig.GetBoolDefault("Console.Enable", true) && (m_ServiceStatus == -1)/* need disable console in service mode*/) #else @@ -251,10 +253,10 @@ int Master::Run() #endif { ///- Launch CliRunnable thread - ACE_Based::Thread td1(*new CliRunnable); + cliThread = new ACE_Based::Thread(new CliRunnable); } - ACE_Based::Thread td2(*new RARunnable); + ACE_Based::Thread td2(new RARunnable); ///- Handle affinity for multiple processors and process priority on Windows #ifdef WIN32 @@ -315,8 +317,13 @@ int Master::Run() { FreezeDetectorRunnable *fdr = new FreezeDetectorRunnable(); fdr->SetDelayTime(freeze_delay*1000); +<<<<<<< HEAD:src/mangosd/Master.cpp ACE_Based::Thread t(*fdr); t.setPriority(ACE_Based::High); +======= + ACE_Based::Thread t(fdr); + t.setPriority(ACE_Based::Highest); +>>>>>>> ca55c2a9d069aaef0d3deafb4884bfd8d3884444:src/mangosd/Master.cpp } ///- Launch the world listener socket @@ -353,9 +360,10 @@ int Master::Run() sLog.outString( "Halting process..." ); - #ifdef WIN32 - if (sConfig.GetBoolDefault("Console.Enable", true)) + if(cliThread) { + #ifdef WIN32 + // this only way to terminate CLI thread exist at Win32 (alt. way exist only in Windows Vista API) //_exit(1); // send keyboard input to safely unblock the CLI thread @@ -390,8 +398,17 @@ int Master::Run() b[3].Event.KeyEvent.wRepeatCount = 1; DWORD numb; BOOL ret = WriteConsoleInput(hStdIn, b, 4, &numb); + + cliThread->wait(); + + #else + + cliThread->destroy(); + + #endif + + delete cliThread; } - #endif // for some unknown reason, unloading scripts here and not in worldrunnable // fixes a memory leak related to detaching threads from the module diff --git a/src/trinityrealm/AuthSocket.cpp b/src/trinityrealm/AuthSocket.cpp index 6a6cde45895..06c55f4955e 100644 --- a/src/trinityrealm/AuthSocket.cpp +++ b/src/trinityrealm/AuthSocket.cpp @@ -928,7 +928,7 @@ bool AuthSocket::_HandleXferResume() ibuf.Read((char*)&start,sizeof(start)); fseek(pPatch, start, 0); - ACE_Based::Thread u(*new PatcherRunnable(this)); + ACE_Based::Thread u(new PatcherRunnable(this)); return true; } @@ -961,7 +961,7 @@ bool AuthSocket::_HandleXferAccept() ibuf.Remove(1); // clear input buffer fseek(pPatch, 0, 0); - ACE_Based::Thread u(*new PatcherRunnable(this)); + ACE_Based::Thread u(new PatcherRunnable(this)); return true; } |