Rewritten Threading system using c++11 std instead of ACE
It also allow full compilation with clang under all supported platforms Need tests
This commit is contained in:
@@ -24,7 +24,7 @@ class MySQL
|
|||||||
{
|
{
|
||||||
mysql_thread_init();
|
mysql_thread_init();
|
||||||
sLog->outSQLDriver("Core thread with ID [" UI64FMTD "] initializing MySQL thread.",
|
sLog->outSQLDriver("Core thread with ID [" UI64FMTD "] initializing MySQL thread.",
|
||||||
(uint64)ACE_Based::Thread::currentId());
|
ACORE::Thread::currentId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Shuts down MySQL thread and frees resources, should only be called
|
/*! Shuts down MySQL thread and frees resources, should only be called
|
||||||
@@ -35,7 +35,7 @@ class MySQL
|
|||||||
{
|
{
|
||||||
mysql_thread_end();
|
mysql_thread_end();
|
||||||
sLog->outSQLDriver("Core thread with ID [" UI64FMTD "] shutting down MySQL thread.",
|
sLog->outSQLDriver("Core thread with ID [" UI64FMTD "] shutting down MySQL thread.",
|
||||||
(uint64)ACE_Based::Thread::currentId());
|
ACORE::Thread::currentId());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Library_Init()
|
static void Library_Init()
|
||||||
@@ -49,4 +49,4 @@ class MySQL
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -80,14 +80,14 @@ int DelayExecutor::start(int num_threads, ACE_Method_Request* pre_svc_hook, ACE_
|
|||||||
queue_.queue()->activate();
|
queue_.queue()->activate();
|
||||||
|
|
||||||
// pussywizard:
|
// pussywizard:
|
||||||
ACE_Based::ThreadPriority tp;
|
//ACORE::ThreadPriority tp;
|
||||||
int _priority = tp.getPriority(ACE_Based::Highest);
|
//int _priority = tp.getPriority(ACORE::Priority_Highest);
|
||||||
if (ACE_Task_Base::activate(THR_NEW_LWP | THR_JOINABLE, num_threads, 0, _priority) == -1)
|
//if (ACE_Task_Base::activate(THR_NEW_LWP | THR_JOINABLE, num_threads, 0, _priority) == -1)
|
||||||
return -1;
|
|
||||||
|
|
||||||
//if (ACE_Task_Base::activate(THR_NEW_LWP | THR_JOINABLE | THR_INHERIT_SCHED, num_threads) == -1)
|
|
||||||
// return -1;
|
// return -1;
|
||||||
|
|
||||||
|
if (ACE_Task_Base::activate(THR_NEW_LWP | THR_JOINABLE | THR_INHERIT_SCHED, num_threads) == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
activated(true);
|
activated(true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -6,218 +6,100 @@
|
|||||||
|
|
||||||
#include "Threading.h"
|
#include "Threading.h"
|
||||||
#include "Errors.h"
|
#include "Errors.h"
|
||||||
#include <ace/OS_NS_unistd.h>
|
|
||||||
#include <ace/Sched_Params.h>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using namespace ACE_Based;
|
#include <chrono>
|
||||||
|
#include <system_error>
|
||||||
|
|
||||||
ThreadPriority::ThreadPriority()
|
using namespace ACORE;
|
||||||
|
|
||||||
|
Thread::Thread() : m_task(nullptr), m_iThreadId(), m_ThreadImp()
|
||||||
{
|
{
|
||||||
for (int i = Idle; i < MAXPRIORITYNUM; ++i)
|
|
||||||
m_priority[i] = ACE_THR_PRI_OTHER_DEF;
|
|
||||||
|
|
||||||
m_priority[Idle] = ACE_Sched_Params::priority_min(ACE_SCHED_OTHER);
|
|
||||||
m_priority[Realtime] = ACE_Sched_Params::priority_max(ACE_SCHED_OTHER);
|
|
||||||
|
|
||||||
std::vector<int> _tmp;
|
|
||||||
|
|
||||||
ACE_Sched_Params::Policy _policy = ACE_SCHED_OTHER;
|
|
||||||
ACE_Sched_Priority_Iterator pr_iter(_policy);
|
|
||||||
|
|
||||||
while (pr_iter.more())
|
|
||||||
{
|
|
||||||
_tmp.push_back(pr_iter.priority());
|
|
||||||
pr_iter.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT (!_tmp.empty());
|
|
||||||
|
|
||||||
if (_tmp.size() >= MAXPRIORITYNUM)
|
|
||||||
{
|
|
||||||
const size_t max_pos = _tmp.size();
|
|
||||||
size_t min_pos = 1;
|
|
||||||
size_t norm_pos = 0;
|
|
||||||
for (size_t i = 0; i < max_pos; ++i)
|
|
||||||
{
|
|
||||||
if (_tmp[i] == ACE_THR_PRI_OTHER_DEF)
|
|
||||||
{
|
|
||||||
norm_pos = i + 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// since we have only 7(seven) values in enum Priority
|
|
||||||
// and 3 we know already (Idle, Normal, Realtime) so
|
|
||||||
// we need to split each list [Idle...Normal] and [Normal...Realtime]
|
|
||||||
// into pieces
|
|
||||||
const size_t _divider = 4;
|
|
||||||
size_t _div = (norm_pos - min_pos) / _divider;
|
|
||||||
if (_div == 0)
|
|
||||||
_div = 1;
|
|
||||||
|
|
||||||
min_pos = (norm_pos - 1);
|
|
||||||
|
|
||||||
m_priority[Low] = _tmp[min_pos -= _div];
|
|
||||||
m_priority[Lowest] = _tmp[min_pos -= _div ];
|
|
||||||
|
|
||||||
_div = (max_pos - norm_pos) / _divider;
|
|
||||||
if (_div == 0)
|
|
||||||
_div = 1;
|
|
||||||
|
|
||||||
min_pos = norm_pos - 1;
|
|
||||||
|
|
||||||
m_priority[High] = _tmp[min_pos += _div];
|
|
||||||
m_priority[Highest] = _tmp[min_pos += _div];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ThreadPriority::getPriority(Priority p) const
|
Thread::Thread(Runnable* instance) : m_task(instance), m_ThreadImp(&Thread::ThreadTask, (void*)m_task)
|
||||||
{
|
{
|
||||||
if (p < Idle)
|
m_iThreadId = m_ThreadImp.get_id();
|
||||||
p = Idle;
|
|
||||||
|
|
||||||
if (p > Realtime)
|
|
||||||
p = Realtime;
|
|
||||||
|
|
||||||
return m_priority[p];
|
|
||||||
}
|
|
||||||
|
|
||||||
#define THREADFLAG (THR_NEW_LWP | THR_SCHED_DEFAULT| THR_JOINABLE)
|
|
||||||
|
|
||||||
Thread::Thread(): m_iThreadId(0), m_hThreadHandle(0), m_task(0)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread::Thread(Runnable* instance): m_iThreadId(0), m_hThreadHandle(0), m_task(instance)
|
|
||||||
{
|
|
||||||
// register reference to m_task to prevent it deeltion until destructor
|
// register reference to m_task to prevent it deeltion until destructor
|
||||||
if (m_task)
|
if (m_task)
|
||||||
m_task->incReference();
|
m_task->incReference();
|
||||||
|
|
||||||
bool _start = start();
|
|
||||||
ASSERT (_start);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread::~Thread()
|
Thread::~Thread()
|
||||||
{
|
{
|
||||||
//Wait();
|
// Wait();
|
||||||
|
|
||||||
// deleted runnable object (if no other references)
|
// deleted runnable object (if no other references)
|
||||||
if (m_task)
|
if (m_task)
|
||||||
m_task->decReference();
|
m_task->decReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
//initialize Thread's class static member
|
bool Thread::wait()
|
||||||
Thread::ThreadStorage Thread::m_ThreadStorage;
|
|
||||||
ThreadPriority Thread::m_TpEnum;
|
|
||||||
|
|
||||||
bool Thread::start()
|
|
||||||
{
|
{
|
||||||
if (m_task == 0 || m_iThreadId != 0)
|
if (m_iThreadId == std::thread::id() || !m_task)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// incRef before spawing the thread, otherwise Thread::ThreadTask() might call decRef and delete m_task
|
bool res = true;
|
||||||
m_task->incReference();
|
|
||||||
|
|
||||||
bool res = (ACE_Thread::spawn(&Thread::ThreadTask, (void*)m_task, THREADFLAG, &m_iThreadId, &m_hThreadHandle) == 0);
|
try
|
||||||
|
{
|
||||||
|
m_ThreadImp.join();
|
||||||
|
}
|
||||||
|
catch (std::system_error&)
|
||||||
|
{
|
||||||
|
res = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!res)
|
m_iThreadId = std::thread::id();
|
||||||
m_task->decReference();
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Thread::wait()
|
|
||||||
{
|
|
||||||
if (!m_hThreadHandle || !m_task)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ACE_THR_FUNC_RETURN _value = ACE_THR_FUNC_RETURN(-1);
|
|
||||||
int _res = ACE_Thread::join(m_hThreadHandle, &_value);
|
|
||||||
|
|
||||||
m_iThreadId = 0;
|
|
||||||
m_hThreadHandle = 0;
|
|
||||||
|
|
||||||
return (_res == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Thread::destroy()
|
void Thread::destroy()
|
||||||
{
|
{
|
||||||
if (!m_iThreadId || !m_task)
|
if (m_iThreadId == std::thread::id() || !m_task)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (ACE_Thread::kill(m_iThreadId, -1) != 0)
|
// FIXME: We need to make sure that all threads can be trusted to
|
||||||
return;
|
// halt execution on their own as this is not an interrupt
|
||||||
|
m_ThreadImp.join();
|
||||||
m_iThreadId = 0;
|
m_iThreadId = std::thread::id();
|
||||||
m_hThreadHandle = 0;
|
|
||||||
|
|
||||||
// reference set at ACE_Thread::spawn
|
|
||||||
m_task->decReference();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Thread::suspend()
|
void Thread::ThreadTask(void* param)
|
||||||
{
|
|
||||||
ACE_Thread::suspend(m_hThreadHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Thread::resume()
|
|
||||||
{
|
|
||||||
ACE_Thread::resume(m_hThreadHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
ACE_THR_FUNC_RETURN Thread::ThreadTask(void * param)
|
|
||||||
{
|
{
|
||||||
Runnable* _task = (Runnable*)param;
|
Runnable* _task = (Runnable*)param;
|
||||||
_task->run();
|
_task->run();
|
||||||
|
|
||||||
// task execution complete, free referecne added at
|
|
||||||
_task->decReference();
|
|
||||||
|
|
||||||
return (ACE_THR_FUNC_RETURN)0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ACE_thread_t Thread::currentId()
|
std::thread::id Thread::currentId()
|
||||||
{
|
{
|
||||||
return ACE_Thread::self();
|
return std::this_thread::get_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
ACE_hthread_t Thread::currentHandle()
|
void Thread::setPriority(Priority priority)
|
||||||
{
|
{
|
||||||
ACE_hthread_t _handle;
|
std::thread::native_handle_type handle = m_ThreadImp.native_handle();
|
||||||
ACE_Thread::self(_handle);
|
bool _ok = true;
|
||||||
|
#ifdef WIN32
|
||||||
|
|
||||||
return _handle;
|
switch (priority)
|
||||||
}
|
|
||||||
|
|
||||||
Thread * Thread::current()
|
|
||||||
{
|
|
||||||
Thread * _thread = m_ThreadStorage.ts_object();
|
|
||||||
if (!_thread)
|
|
||||||
{
|
{
|
||||||
_thread = new Thread();
|
case Priority_Realtime: _ok = SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL); break;
|
||||||
_thread->m_iThreadId = Thread::currentId();
|
case Priority_Highest: _ok = SetThreadPriority(handle, THREAD_PRIORITY_HIGHEST); break;
|
||||||
_thread->m_hThreadHandle = Thread::currentHandle();
|
case Priority_High: _ok = SetThreadPriority(handle, THREAD_PRIORITY_ABOVE_NORMAL); break;
|
||||||
|
case Priority_Normal: _ok = SetThreadPriority(handle, THREAD_PRIORITY_NORMAL); break;
|
||||||
Thread * _oldValue = m_ThreadStorage.ts_object(_thread);
|
case Priority_Low: _ok = SetThreadPriority(handle, THREAD_PRIORITY_BELOW_NORMAL); break;
|
||||||
if (_oldValue)
|
case Priority_Lowest: _ok = SetThreadPriority(handle, THREAD_PRIORITY_LOWEST); break;
|
||||||
delete _oldValue;
|
case Priority_Idle: _ok = SetThreadPriority(handle, THREAD_PRIORITY_IDLE); break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return _thread;
|
// remove this ASSERT in case you don't want to know is thread priority change was successful or not
|
||||||
}
|
ASSERT(_ok);
|
||||||
|
|
||||||
void Thread::setPriority(Priority type)
|
|
||||||
{
|
|
||||||
int _priority = m_TpEnum.getPriority(type);
|
|
||||||
int _ok = ACE_Thread::setprio(m_hThreadHandle, _priority);
|
|
||||||
//remove this ASSERT in case you don't want to know is thread priority change was successful or not
|
|
||||||
ASSERT (_ok == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Thread::Sleep(unsigned long msecs)
|
void Thread::Sleep(unsigned long msecs)
|
||||||
{
|
{
|
||||||
ACE_OS::sleep(ACE_Time_Value(0, 1000 * msecs));
|
std::this_thread::sleep_for(std::chrono::milliseconds(msecs));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,20 +7,18 @@
|
|||||||
#ifndef THREADING_H
|
#ifndef THREADING_H
|
||||||
#define THREADING_H
|
#define THREADING_H
|
||||||
|
|
||||||
#include "Common.h"
|
#include <thread>
|
||||||
#include <ace/ACE.h>
|
#include <atomic>
|
||||||
#include <ace/Thread.h>
|
|
||||||
#include <ace/TSS_T.h>
|
|
||||||
#include <ace/Atomic_Op.h>
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
namespace ACE_Based
|
#include <thread>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
namespace ACORE
|
||||||
{
|
{
|
||||||
|
|
||||||
class Runnable
|
class Runnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Runnable() { }
|
virtual ~Runnable() {}
|
||||||
virtual void run() = 0;
|
virtual void run() = 0;
|
||||||
|
|
||||||
void incReference() { ++m_refs; }
|
void incReference() { ++m_refs; }
|
||||||
@@ -30,30 +28,18 @@ namespace ACE_Based
|
|||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
ACE_Atomic_Op<ACE_Thread_Mutex, long> m_refs;
|
std::atomic_long m_refs;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Priority
|
enum Priority
|
||||||
{
|
{
|
||||||
Idle,
|
Priority_Idle,
|
||||||
Lowest,
|
Priority_Lowest,
|
||||||
Low,
|
Priority_Low,
|
||||||
Normal,
|
Priority_Normal,
|
||||||
High,
|
Priority_High,
|
||||||
Highest,
|
Priority_Highest,
|
||||||
Realtime
|
Priority_Realtime,
|
||||||
};
|
|
||||||
|
|
||||||
#define MAXPRIORITYNUM (Realtime + 1)
|
|
||||||
|
|
||||||
class ThreadPriority
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ThreadPriority();
|
|
||||||
int getPriority(Priority p) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
int m_priority[MAXPRIORITYNUM];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Thread
|
class Thread
|
||||||
@@ -63,36 +49,23 @@ namespace ACE_Based
|
|||||||
explicit Thread(Runnable* instance);
|
explicit Thread(Runnable* instance);
|
||||||
~Thread();
|
~Thread();
|
||||||
|
|
||||||
bool start();
|
|
||||||
bool wait();
|
bool wait();
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
void suspend();
|
|
||||||
void resume();
|
|
||||||
|
|
||||||
void setPriority(Priority type);
|
void setPriority(Priority type);
|
||||||
|
|
||||||
static void Sleep(unsigned long msecs);
|
static void Sleep(unsigned long msecs);
|
||||||
static ACE_thread_t currentId();
|
static std::thread::id currentId();
|
||||||
static ACE_hthread_t currentHandle();
|
|
||||||
static Thread * current();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Thread(const Thread&);
|
Thread(const Thread&);
|
||||||
Thread& operator=(const Thread&);
|
Thread& operator=(const Thread&);
|
||||||
|
|
||||||
static ACE_THR_FUNC_RETURN ThreadTask(void * param);
|
static void ThreadTask(void* param);
|
||||||
|
|
||||||
ACE_thread_t m_iThreadId;
|
Runnable* const m_task;
|
||||||
ACE_hthread_t m_hThreadHandle;
|
std::thread::id m_iThreadId;
|
||||||
Runnable* m_task;
|
std::thread m_ThreadImp;
|
||||||
|
|
||||||
typedef ACE_TSS<Thread> ThreadStorage;
|
|
||||||
//global object - container for Thread class representation of every thread
|
|
||||||
static ThreadStorage m_ThreadStorage;
|
|
||||||
//use this object to determine current OS thread priority values mapped to enum Priority{ }
|
|
||||||
static ThreadPriority m_TpEnum;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ typedef struct AuthHandler
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Launch a thread to transfer a patch to the client
|
// Launch a thread to transfer a patch to the client
|
||||||
class PatcherRunnable: public ACE_Based::Runnable
|
class PatcherRunnable: public ACORE::Runnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PatcherRunnable(class AuthSocket*);
|
PatcherRunnable(class AuthSocket*);
|
||||||
@@ -1010,7 +1010,7 @@ bool AuthSocket::_HandleXferResume()
|
|||||||
socket().recv((char*)&start, sizeof(start));
|
socket().recv((char*)&start, sizeof(start));
|
||||||
fseek(pPatch, long(start), 0);
|
fseek(pPatch, long(start), 0);
|
||||||
|
|
||||||
ACE_Based::Thread u(new PatcherRunnable(this));
|
ACORE::Thread u(new PatcherRunnable(this));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1042,7 +1042,7 @@ bool AuthSocket::_HandleXferAccept()
|
|||||||
socket().recv_skip(1); // clear input buffer
|
socket().recv_skip(1); // clear input buffer
|
||||||
fseek(pPatch, 0, 0);
|
fseek(pPatch, 0, 0);
|
||||||
|
|
||||||
ACE_Based::Thread u(new PatcherRunnable(this));
|
ACORE::Thread u(new PatcherRunnable(this));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include <ace/Singleton.h>
|
#include <ace/Singleton.h>
|
||||||
#include <ace/Atomic_Op.h>
|
#include <atomic>
|
||||||
|
|
||||||
#include "ObjectMgr.h"
|
#include "ObjectMgr.h"
|
||||||
#include "DBCStores.h"
|
#include "DBCStores.h"
|
||||||
@@ -1083,7 +1083,7 @@ class ScriptMgr
|
|||||||
uint32 _scriptCount;
|
uint32 _scriptCount;
|
||||||
|
|
||||||
//atomic op counter for active scripts amount
|
//atomic op counter for active scripts amount
|
||||||
ACE_Atomic_Op<ACE_Thread_Mutex, long> _scheduledScripts;
|
std::atomic_long _scheduledScripts;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class TScript>
|
template<class TScript>
|
||||||
|
|||||||
@@ -344,10 +344,10 @@ class WorldSession
|
|||||||
void SetLatency(uint32 latency) { m_latency = latency; }
|
void SetLatency(uint32 latency) { m_latency = latency; }
|
||||||
void ResetClientTimeDelay() { m_clientTimeDelay = 0; }
|
void ResetClientTimeDelay() { m_clientTimeDelay = 0; }
|
||||||
|
|
||||||
ACE_Atomic_Op<ACE_Thread_Mutex, time_t> m_timeOutTime;
|
std::atomic<time_t> m_timeOutTime;
|
||||||
void UpdateTimeOutTime(uint32 diff)
|
void UpdateTimeOutTime(uint32 diff)
|
||||||
{
|
{
|
||||||
if (time_t(diff) > m_timeOutTime.value())
|
if (time_t(diff) > m_timeOutTime)
|
||||||
m_timeOutTime = 0;
|
m_timeOutTime = 0;
|
||||||
else
|
else
|
||||||
m_timeOutTime -= diff;
|
m_timeOutTime -= diff;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#include <ace/TP_Reactor.h>
|
#include <ace/TP_Reactor.h>
|
||||||
#include <ace/Dev_Poll_Reactor.h>
|
#include <ace/Dev_Poll_Reactor.h>
|
||||||
#include <ace/Guard_T.h>
|
#include <ace/Guard_T.h>
|
||||||
#include <ace/Atomic_Op.h>
|
#include <atomic>
|
||||||
#include <ace/os_include/arpa/os_inet.h>
|
#include <ace/os_include/arpa/os_inet.h>
|
||||||
#include <ace/os_include/netinet/os_tcp.h>
|
#include <ace/os_include/netinet/os_tcp.h>
|
||||||
#include <ace/os_include/sys/os_types.h>
|
#include <ace/os_include/sys/os_types.h>
|
||||||
@@ -92,7 +92,7 @@ class ReactorRunnable : protected ACE_Task_Base
|
|||||||
|
|
||||||
long Connections()
|
long Connections()
|
||||||
{
|
{
|
||||||
return static_cast<long> (m_Connections.value());
|
return static_cast<long> (m_Connections);
|
||||||
}
|
}
|
||||||
|
|
||||||
int AddSocket (WorldSocket* sock)
|
int AddSocket (WorldSocket* sock)
|
||||||
@@ -186,7 +186,7 @@ class ReactorRunnable : protected ACE_Task_Base
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef ACE_Atomic_Op<ACE_SYNCH_MUTEX, long> AtomicInt;
|
typedef std::atomic_long AtomicInt;
|
||||||
typedef std::set<WorldSocket*> SocketSet;
|
typedef std::set<WorldSocket*> SocketSet;
|
||||||
|
|
||||||
ACE_Reactor* m_Reactor;
|
ACE_Reactor* m_Reactor;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#define __CLIRUNNABLE_H
|
#define __CLIRUNNABLE_H
|
||||||
|
|
||||||
/// Command Line Interface handling thread
|
/// Command Line Interface handling thread
|
||||||
class CliRunnable : public ACE_Based::Runnable
|
class CliRunnable : public ACORE::Runnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void run();
|
void run();
|
||||||
|
|||||||
+14
-14
@@ -71,7 +71,7 @@ class WorldServerSignalHandler : public Trinity::SignalHandler
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class FreezeDetectorRunnable : public ACE_Based::Runnable
|
class FreezeDetectorRunnable : public ACORE::Runnable
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
uint32 _loops;
|
uint32 _loops;
|
||||||
@@ -101,7 +101,7 @@ public:
|
|||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ACE_Based::Thread::Sleep(1000);
|
ACORE::Thread::Sleep(1000);
|
||||||
}
|
}
|
||||||
sLog->outString("Anti-freeze thread exiting without problems.");
|
sLog->outString("Anti-freeze thread exiting without problems.");
|
||||||
}
|
}
|
||||||
@@ -171,10 +171,10 @@ int Master::Run()
|
|||||||
//handle.register_handler(SIGSEGV, &signalSEGV);
|
//handle.register_handler(SIGSEGV, &signalSEGV);
|
||||||
|
|
||||||
///- Launch WorldRunnable thread
|
///- Launch WorldRunnable thread
|
||||||
ACE_Based::Thread worldThread(new WorldRunnable);
|
ACORE::Thread worldThread(new WorldRunnable);
|
||||||
worldThread.setPriority(ACE_Based::Highest);
|
worldThread.setPriority(ACORE::Priority_Highest);
|
||||||
|
|
||||||
ACE_Based::Thread* cliThread = NULL;
|
ACORE::Thread* cliThread = NULL;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (sConfigMgr->GetBoolDefault("Console.Enable", true) && (m_ServiceStatus == -1)/* need disable console in service mode*/)
|
if (sConfigMgr->GetBoolDefault("Console.Enable", true) && (m_ServiceStatus == -1)/* need disable console in service mode*/)
|
||||||
@@ -183,14 +183,14 @@ int Master::Run()
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
///- Launch CliRunnable thread
|
///- Launch CliRunnable thread
|
||||||
cliThread = new ACE_Based::Thread(new CliRunnable);
|
cliThread = new ACORE::Thread(new CliRunnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
ACE_Based::Thread rarThread(new RARunnable);
|
ACORE::Thread rarThread(new RARunnable);
|
||||||
|
|
||||||
// pussywizard:
|
// pussywizard:
|
||||||
ACE_Based::Thread auctionLising_thread(new AuctionListingRunnable);
|
ACORE::Thread auctionLising_thread(new AuctionListingRunnable);
|
||||||
auctionLising_thread.setPriority(ACE_Based::High);
|
auctionLising_thread.setPriority(ACORE::Priority_High);
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(__linux__)
|
#if defined(_WIN32) || defined(__linux__)
|
||||||
|
|
||||||
@@ -262,21 +262,21 @@ int Master::Run()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Start soap serving thread
|
// Start soap serving thread
|
||||||
ACE_Based::Thread* soapThread = NULL;
|
ACORE::Thread* soapThread = NULL;
|
||||||
if (sConfigMgr->GetBoolDefault("SOAP.Enabled", false))
|
if (sConfigMgr->GetBoolDefault("SOAP.Enabled", false))
|
||||||
{
|
{
|
||||||
TCSoapRunnable* runnable = new TCSoapRunnable();
|
TCSoapRunnable* runnable = new TCSoapRunnable();
|
||||||
runnable->SetListenArguments(sConfigMgr->GetStringDefault("SOAP.IP", "127.0.0.1"), uint16(sConfigMgr->GetIntDefault("SOAP.Port", 7878)));
|
runnable->SetListenArguments(sConfigMgr->GetStringDefault("SOAP.IP", "127.0.0.1"), uint16(sConfigMgr->GetIntDefault("SOAP.Port", 7878)));
|
||||||
soapThread = new ACE_Based::Thread(runnable);
|
soapThread = new ACORE::Thread(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start up freeze catcher thread
|
// Start up freeze catcher thread
|
||||||
ACE_Based::Thread* freezeThread = NULL;
|
ACORE::Thread* freezeThread = NULL;
|
||||||
if (uint32 freezeDelay = sConfigMgr->GetIntDefault("MaxCoreStuckTime", 0))
|
if (uint32 freezeDelay = sConfigMgr->GetIntDefault("MaxCoreStuckTime", 0))
|
||||||
{
|
{
|
||||||
FreezeDetectorRunnable* runnable = new FreezeDetectorRunnable(freezeDelay*1000);
|
FreezeDetectorRunnable* runnable = new FreezeDetectorRunnable(freezeDelay*1000);
|
||||||
freezeThread = new ACE_Based::Thread(runnable);
|
freezeThread = new ACORE::Thread(runnable);
|
||||||
freezeThread->setPriority(ACE_Based::Highest);
|
freezeThread->setPriority(ACORE::Priority_Highest);
|
||||||
}
|
}
|
||||||
|
|
||||||
///- Launch the world listener socket
|
///- Launch the world listener socket
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#include <ace/Reactor.h>
|
#include <ace/Reactor.h>
|
||||||
|
|
||||||
class RARunnable : public ACE_Based::Runnable
|
class RARunnable : public ACORE::Runnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RARunnable();
|
RARunnable();
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
#include <ace/Task.h>
|
#include <ace/Task.h>
|
||||||
#include <Threading.h>
|
#include <Threading.h>
|
||||||
|
|
||||||
class TCSoapRunnable : public ACE_Based::Runnable
|
class TCSoapRunnable : public ACORE::Runnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TCSoapRunnable() : _port(0) { }
|
TCSoapRunnable() : _port(0) { }
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ void WorldRunnable::run()
|
|||||||
avgDiffTracker.Update(executionTimeDiff > WORLD_SLEEP_CONST ? executionTimeDiff : WORLD_SLEEP_CONST);
|
avgDiffTracker.Update(executionTimeDiff > WORLD_SLEEP_CONST ? executionTimeDiff : WORLD_SLEEP_CONST);
|
||||||
|
|
||||||
if (executionTimeDiff < WORLD_SLEEP_CONST)
|
if (executionTimeDiff < WORLD_SLEEP_CONST)
|
||||||
ACE_Based::Thread::Sleep(WORLD_SLEEP_CONST-executionTimeDiff);
|
ACORE::Thread::Sleep(WORLD_SLEEP_CONST-executionTimeDiff);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (m_ServiceStatus == 0)
|
if (m_ServiceStatus == 0)
|
||||||
@@ -118,7 +118,7 @@ void AuctionListingRunnable::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ACE_Based::Thread::Sleep(1);
|
ACORE::Thread::Sleep(1);
|
||||||
}
|
}
|
||||||
sLog->outString("Auction House Listing thread exiting without problems.");
|
sLog->outString("Auction House Listing thread exiting without problems.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,13 @@
|
|||||||
#define __WORLDRUNNABLE_H
|
#define __WORLDRUNNABLE_H
|
||||||
|
|
||||||
/// Heartbeat thread for the World
|
/// Heartbeat thread for the World
|
||||||
class WorldRunnable : public ACE_Based::Runnable
|
class WorldRunnable : public ACORE::Runnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
class AuctionListingRunnable : public ACE_Based::Runnable
|
class AuctionListingRunnable : public ACORE::Runnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void run();
|
void run();
|
||||||
|
|||||||
Reference in New Issue
Block a user