Files
TrinityCore/src/shared/Threading.h
T
maximius 333f1c9d72 *[8475] fixed some gcc-warnings Author: balrok
*[8476] Revert some recent cleanup changes, some other fixes and cleanups. Author: VladimirMangos
*[8489] Fixed player visibility update in case view point different from player itself. Author: SilverIce
*[8493] Avoid unexpected multiply error messages at wrong `quest_template`.`RewSpell*` Author: VladimirMangos
*[8496] Resolve some #include cycles and unsafe code.
* Common.h -> Threading.h -> Errors.h -> Common.h
* Remove reduncdent #include "ByteBuffer.h" in headers
* Remove redundent #include "Auth/BigNumber.h" in headers
* Avoid multyply data copy at use some now dropped functions in BigNumber.
* Avoid copy fixed byte count from byte arrays with unknown real size created from BigNumber.
* Avoid possible problems for build mangos at different platform or compilers. Author: VladimirMangos.
*[8501] Apply code style and cleanups to some Player functions. Author: VladimirMangos.
*[8502] Disable quests related to specific game events at startup if event not active. Also rename member boolean variable. Author: NoFantasy
*[8506] Add check for IsAutoComplete() in SendPreparedQuest().
For cases where quest is repeatable but has Method!=0, QuestDetails must be sent instead of RequestItems.
Some additional code cleanup. Author: NoFantasy
*[8507] Check amount of spawned pools before decrement to avoid unexpected result. Also rename variable to more meaningful name. Signed-off-by: NoFantasy <nofantasy@nf.no>

Thanks to Stryker and onkelz28!

--HG--
branch : trunk
2009-09-18 14:10:37 -07:00

109 lines
2.7 KiB
C++

/*
* Copyright (C) 2009 MaNGOS <http://getmangos.com/>
*
* 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
*/
#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
{
class Runnable
{
public:
virtual ~Runnable() {}
virtual void run() = 0;
void incReference() { ++m_refs; }
void decReference()
{
if(!--m_refs)
delete this;
}
private:
ACE_Atomic_Op<ACE_Thread_Mutex, int> m_refs;
};
enum Priority
{
Idle,
Lowest,
Low,
Normal,
High,
Highest,
Realtime,
};
#define MAXPRIORITYNUM (Realtime + 1)
class ThreadPriority
{
public:
ThreadPriority();
int getPriority(Priority p) const;
private:
int m_priority[MAXPRIORITYNUM];
};
class Thread
{
public:
Thread();
explicit Thread(Runnable* instance);
~Thread();
bool start();
bool wait();
void destroy();
void suspend();
void resume();
void setPriority(Priority type);
static void Sleep(unsigned long msecs);
static ACE_thread_t currentId();
static ACE_hthread_t currentHandle();
static Thread * current();
private:
Thread(const Thread&);
Thread& operator=(const Thread&);
static ACE_THR_FUNC_RETURN ThreadTask(void * param);
ACE_thread_t m_iThreadId;
ACE_hthread_t m_hThreadHandle;
Runnable * m_task;
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