[Rel21] Stage 1 of updates for Rel21 Build System

This commit is contained in:
Antz 2015-07-28 10:59:34 +01:00 committed by Antz
parent 13292befd6
commit fdefc0869a
1951 changed files with 40474 additions and 252610 deletions

View file

@ -0,0 +1,135 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2015 MaNGOS project <http://getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#include <ace/Singleton.h>
#include <ace/Thread_Mutex.h>
#include <ace/Log_Msg.h>
#include "DelayExecutor.h"
DelayExecutor* DelayExecutor::instance()
{
return ACE_Singleton<DelayExecutor, ACE_Thread_Mutex>::instance();
}
DelayExecutor::DelayExecutor()
: pre_svc_hook_(0), post_svc_hook_(0), activated_(false)
{
}
DelayExecutor::~DelayExecutor()
{
if (pre_svc_hook_)
delete pre_svc_hook_;
if (post_svc_hook_)
delete post_svc_hook_;
deactivate();
}
int DelayExecutor::deactivate()
{
if (!activated())
return -1;
activated(false);
queue_.queue()->deactivate();
wait();
return 0;
}
int DelayExecutor::svc()
{
if (pre_svc_hook_)
pre_svc_hook_->call();
for (;;)
{
ACE_Method_Request* rq = queue_.dequeue();
if (!rq)
break;
rq->call();
delete rq;
}
if (post_svc_hook_)
post_svc_hook_->call();
return 0;
}
int DelayExecutor::activate(int num_threads, ACE_Method_Request* pre_svc_hook, ACE_Method_Request* post_svc_hook)
{
if (activated())
return -1;
if (num_threads < 1)
return -1;
if (pre_svc_hook_)
delete pre_svc_hook_;
if (post_svc_hook_)
delete post_svc_hook_;
pre_svc_hook_ = pre_svc_hook;
post_svc_hook_ = post_svc_hook;
queue_.queue()->activate();
if (ACE_Task_Base::activate(THR_NEW_LWP | THR_JOINABLE | THR_INHERIT_SCHED, num_threads) == -1)
return -1;
activated(true);
return true;
}
int DelayExecutor::execute(ACE_Method_Request* new_req)
{
if (new_req == NULL)
return -1;
if (queue_.enqueue(new_req, (ACE_Time_Value*)&ACE_Time_Value::zero) == -1)
{
delete new_req;
ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%t) %p\n"), ACE_TEXT("DelayExecutor::execute enqueue")), -1);
}
return 0;
}
bool DelayExecutor::activated()
{
return activated_;
}
void DelayExecutor::activated(bool s)
{
activated_ = s;
}

View file

@ -0,0 +1,61 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2015 MaNGOS project <http://getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#ifndef _M_DELAY_EXECUTOR_H
#define _M_DELAY_EXECUTOR_H
#include <ace/Task.h>
#include <ace/Activation_Queue.h>
#include <ace/Method_Request.h>
class DelayExecutor : protected ACE_Task_Base
{
public:
DelayExecutor();
virtual ~DelayExecutor();
static DelayExecutor* instance();
int execute(ACE_Method_Request* new_req);
int activate(int num_threads = 1, ACE_Method_Request* pre_svc_hook = NULL, ACE_Method_Request* post_svc_hook = NULL);
int deactivate();
bool activated();
virtual int svc();
private:
ACE_Activation_Queue queue_;
ACE_Method_Request* pre_svc_hook_;
ACE_Method_Request* post_svc_hook_;
bool activated_;
void activated(bool s);
};
#endif // _M_DELAY_EXECUTOR_H

View file

@ -0,0 +1,247 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2015 MaNGOS project <http://getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#include "Threading.h"
#include "Utilities/Errors.h"
#include <ace/OS_NS_unistd.h>
#include <ace/Sched_Params.h>
#include <vector>
using namespace ACE_Based;
ThreadPriority::ThreadPriority()
{
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();
}
MANGOS_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
{
if (p < Idle)
{ p = Idle; }
if (p > Realtime)
{ p = Realtime; }
return m_priority[p];
}
#ifndef __sun__
# define THREADFLAG (THR_NEW_LWP | THR_JOINABLE | THR_SCHED_DEFAULT)
#else
# define THREADFLAG (THR_NEW_LWP | THR_JOINABLE)
#endif
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
if (m_task)
{ m_task->incReference(); }
bool _start = start();
MANGOS_ASSERT(_start);
}
Thread::~Thread()
{
// Wait();
// deleted runnable object (if no other references)
if (m_task)
{ m_task->decReference(); }
}
// initialize Thread's class static member
Thread::ThreadStorage Thread::m_ThreadStorage;
ThreadPriority Thread::m_TpEnum;
bool Thread::start()
{
if (m_task == 0 || m_iThreadId != 0)
{ return false; }
// incRef before spawing the thread, otherwise Thread::ThreadTask() might call decRef and delete m_task
m_task->incReference();
bool res = (ACE_Thread::spawn(&Thread::ThreadTask, (void*)m_task, THREADFLAG, &m_iThreadId, &m_hThreadHandle) == 0);
if (res)
{ m_task->decReference(); }
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()
{
if (!m_iThreadId || !m_task)
{ return; }
if (ACE_Thread::kill(m_iThreadId, -1) != 0)
{ return; }
m_iThreadId = 0;
m_hThreadHandle = 0;
// reference set at ACE_Thread::spawn
m_task->decReference();
}
void Thread::suspend()
{
ACE_Thread::suspend(m_hThreadHandle);
}
void Thread::resume()
{
ACE_Thread::resume(m_hThreadHandle);
}
ACE_THR_FUNC_RETURN Thread::ThreadTask(void* param)
{
Runnable* _task = static_cast<Runnable*>(param);
_task->incReference();
_task->run();
// task execution complete, free referecne added at
_task->decReference();
return (ACE_THR_FUNC_RETURN)0;
}
ACE_thread_t Thread::currentId()
{
return ACE_Thread::self();
}
ACE_hthread_t Thread::currentHandle()
{
ACE_hthread_t _handle;
ACE_Thread::self(_handle);
return _handle;
}
Thread* Thread::current()
{
Thread* _thread = m_ThreadStorage.ts_object();
if (!_thread)
{
_thread = new Thread();
_thread->m_iThreadId = Thread::currentId();
_thread->m_hThreadHandle = Thread::currentHandle();
Thread* _oldValue = m_ThreadStorage.ts_object(_thread);
delete _oldValue;
}
return _thread;
}
void Thread::setPriority(Priority type)
{
#ifndef __sun__
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
MANGOS_ASSERT(_ok == 0);
#endif
}
void Thread::Sleep(unsigned long msecs)
{
ACE_OS::sleep(ACE_Time_Value(0, 1000 * msecs));
}

View file

@ -0,0 +1,233 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2015 MaNGOS project <http://getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#ifndef THREADING_H
#define THREADING_H
#include <ace/Thread.h>
#include <ace/TSS_T.h>
#include <ace/Atomic_Op.h>
#include <assert.h>
namespace ACE_Based
{
/**
* @brief
*
*/
class Runnable
{
public:
/**
* @brief
*
*/
virtual ~Runnable() {}
/**
* @brief
*
*/
virtual void run() = 0;
/**
* @brief
*
*/
void incReference() { ++m_refs; }
/**
* @brief
*
*/
void decReference()
{
if (!--m_refs)
{ delete this; }
}
private:
ACE_Atomic_Op<ACE_Thread_Mutex, long> m_refs; /**< TODO */
};
/**
* @brief
*
*/
enum Priority
{
Idle,
Lowest,
Low,
Normal,
High,
Highest,
Realtime
};
#define MAXPRIORITYNUM (Realtime + 1)
/**
* @brief
*
*/
class ThreadPriority
{
public:
/**
* @brief
*
*/
ThreadPriority();
/**
* @brief
*
* @param p
* @return int
*/
int getPriority(Priority p) const;
private:
int m_priority[MAXPRIORITYNUM]; /**< TODO */
};
/**
* @brief
*
*/
class Thread
{
public:
/**
* @brief
*
*/
Thread();
/**
* @brief
*
* @param instance
*/
explicit Thread(Runnable* instance);
/**
* @brief
*
*/
~Thread();
/**
* @brief
*
* @return bool
*/
bool start();
/**
* @brief
*
* @return bool
*/
bool wait();
/**
* @brief
*
*/
void destroy();
/**
* @brief
*
*/
void suspend();
/**
* @brief
*
*/
void resume();
/**
* @brief
*
* @param type
*/
void setPriority(Priority type);
/**
* @brief
*
* @param msecs
*/
static void Sleep(unsigned long msecs);
/**
* @brief
*
* @return ACE_thread_t
*/
static ACE_thread_t currentId();
/**
* @brief
*
* @return ACE_hthread_t
*/
static ACE_hthread_t currentHandle();
/**
* @brief
*
* @return Thread
*/
static Thread* current();
private:
/**
* @brief
*
* @param
*/
Thread(const Thread&);
/**
* @brief
*
* @param
* @return Thread &operator
*/
Thread& operator=(const Thread&);
/**
* @brief
*
* @param param
* @return ACE_THR_FUNC_RETURN
*/
static ACE_THR_FUNC_RETURN ThreadTask(void* param);
ACE_thread_t m_iThreadId; /**< TODO */
ACE_hthread_t m_hThreadHandle; /**< TODO */
Runnable* m_task; /**< TODO */
/**
* @brief
*
*/
typedef ACE_TSS<Thread> ThreadStorage;
static ThreadStorage m_ThreadStorage; /**< global object - container for Thread class representation of every thread */
static ThreadPriority m_TpEnum; /**< use this object to determine current OS thread priority values mapped to enum Priority{} */
};
}
#endif