diff options
author | leak <leak@bitmx.net> | 2014-06-21 19:39:16 +0200 |
---|---|---|
committer | leak <leak@bitmx.net> | 2014-06-21 19:39:16 +0200 |
commit | 33dc72a812ad5fb6e17a26b14d6d7f9aaf5d34b5 (patch) | |
tree | 6b7a19cf1f50007dc332d2bd07c27f2766d9ec52 /src/server/worldserver/Master.cpp | |
parent | 55dee85ed80d43cc0d312d588652f85d9a027297 (diff) |
Replaced Threading and SFMT access related code with std::thread and boost TSS
Note: The remote access thread is currently broken due to unknown ACE fail (will be replaced at some point anyways..)
Diffstat (limited to 'src/server/worldserver/Master.cpp')
-rw-r--r-- | src/server/worldserver/Master.cpp | 104 |
1 files changed, 42 insertions, 62 deletions
diff --git a/src/server/worldserver/Master.cpp b/src/server/worldserver/Master.cpp index a5230b908ef..82c547cad40 100644 --- a/src/server/worldserver/Master.cpp +++ b/src/server/worldserver/Master.cpp @@ -20,6 +20,8 @@ \ingroup Trinityd */ +#include <thread> + #include <ace/Sig_Handler.h> #include "Common.h" @@ -78,51 +80,35 @@ class WorldServerSignalHandler : public Trinity::SignalHandler } }; -class FreezeDetectorRunnable : public ACE_Based::Runnable +void FreezeDetectorThread(uint32 delayTime) { -private: - uint32 _loops; - uint32 _lastChange; - uint32 _delaytime; -public: - FreezeDetectorRunnable() - { - _loops = 0; - _lastChange = 0; - _delaytime = 0; - } + if (!delayTime) + return; - void SetDelayTime(uint32 t) { _delaytime = t; } + TC_LOG_INFO("server.worldserver", "Starting up anti-freeze thread (%u seconds max stuck time)...", delayTime / 1000); + uint32 loops = 0; + uint32 lastChange = 0; - void run() override + while (!World::IsStopped()) { - if (!_delaytime) - return; - - TC_LOG_INFO("server.worldserver", "Starting up anti-freeze thread (%u seconds max stuck time)...", _delaytime/1000); - _loops = 0; - _lastChange = 0; - while (!World::IsStopped()) + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + uint32 curtime = getMSTime(); + // normal work + uint32 worldLoopCounter = World::m_worldLoopCounter.value(); + if (loops != worldLoopCounter) { - ACE_Based::Thread::Sleep(1000); - uint32 curtime = getMSTime(); - // normal work - uint32 worldLoopCounter = World::m_worldLoopCounter.value(); - if (_loops != worldLoopCounter) - { - _lastChange = curtime; - _loops = worldLoopCounter; - } - // possible freeze - else if (getMSTimeDiff(_lastChange, curtime) > _delaytime) - { - TC_LOG_ERROR("server.worldserver", "World Thread hangs, kicking out server!"); - ASSERT(false); - } + lastChange = curtime; + loops = worldLoopCounter; + } + // possible freeze + else if (getMSTimeDiff(lastChange, curtime) > delayTime) + { + TC_LOG_ERROR("server.worldserver", "World Thread hangs, kicking out server!"); + ASSERT(false); } - TC_LOG_INFO("server.worldserver", "Anti-freeze thread exiting without problems."); } -}; + TC_LOG_INFO("server.worldserver", "Anti-freeze thread exiting without problems."); +} /// Main function int Master::Run() @@ -182,10 +168,10 @@ int Master::Run() #endif ///- Launch WorldRunnable thread - ACE_Based::Thread worldThread(new WorldRunnable); - worldThread.setPriority(ACE_Based::Highest); - ACE_Based::Thread* cliThread = NULL; + std::thread worldThread(WorldThread); + + std::thread* cliThread = NULL; #ifdef _WIN32 if (sConfigMgr->GetBoolDefault("Console.Enable", true) && (m_ServiceStatus == -1)/* need disable console in service mode*/) @@ -194,10 +180,10 @@ int Master::Run() #endif { ///- Launch CliRunnable thread - cliThread = new ACE_Based::Thread(new CliRunnable); + cliThread = new std::thread(CliThread); } - ACE_Based::Thread rarThread(new RARunnable); + std::thread rarThread(RemoteAccessThread); #if defined(_WIN32) || defined(__linux__) @@ -268,22 +254,19 @@ int Master::Run() #endif //Start soap serving thread - ACE_Based::Thread* soapThread = NULL; + std::thread* soapThread = nullptr; if (sConfigMgr->GetBoolDefault("SOAP.Enabled", false)) { - TCSoapRunnable* runnable = new TCSoapRunnable(); - runnable->SetListenArguments(sConfigMgr->GetStringDefault("SOAP.IP", "127.0.0.1"), uint16(sConfigMgr->GetIntDefault("SOAP.Port", 7878))); - soapThread = new ACE_Based::Thread(runnable); + soapThread = new std::thread(TCSoapThread, sConfigMgr->GetStringDefault("SOAP.IP", "127.0.0.1"), uint16(sConfigMgr->GetIntDefault("SOAP.Port", 7878))); } + std::thread* freezeDetectorThread = nullptr; + ///- Start up freeze catcher thread if (uint32 freezeDelay = sConfigMgr->GetIntDefault("MaxCoreStuckTime", 0)) { - FreezeDetectorRunnable* fdr = new FreezeDetectorRunnable(); - fdr->SetDelayTime(freezeDelay * 1000); - ACE_Based::Thread freezeThread(fdr); - freezeThread.setPriority(ACE_Based::Highest); + freezeDetectorThread = new std::thread(FreezeDetectorThread, freezeDelay); } ///- Launch the world listener socket @@ -304,13 +287,12 @@ int Master::Run() // when the main thread closes the singletons get unloaded // since worldrunnable uses them, it will crash if unloaded after master - worldThread.wait(); - rarThread.wait(); + worldThread.join(); + //rarThread.join(); - if (soapThread) + if (soapThread != nullptr) { - soapThread->wait(); - soapThread->destroy(); + soapThread->join(); delete soapThread; } @@ -324,7 +306,7 @@ int Master::Run() TC_LOG_INFO("server.worldserver", "Halting process..."); - if (cliThread) + if (cliThread != nullptr) { #ifdef _WIN32 @@ -363,17 +345,15 @@ int Master::Run() DWORD numb; WriteConsoleInput(hStdIn, b, 4, &numb); - cliThread->wait(); - - #else - - cliThread->destroy(); + cliThread->join(); #endif delete cliThread; } + delete freezeDetectorThread; + // for some unknown reason, unloading scripts here and not in worldrunnable // fixes a memory leak related to detaching threads from the module //UnloadScriptingModule(); |