Merge commit 'origin/master' into 310

This commit is contained in:
tomrus88 2009-05-11 15:11:02 +04:00
commit c86290fa50
183 changed files with 689 additions and 21043 deletions

View file

@ -21,7 +21,7 @@
#include "Platform/Define.h"
#include "Policies/Singleton.h"
#include "zthread/Mutex.h"
#include "ace/Thread_Mutex.h"
#include <list>
#include <map>
#include "Utilities/UnorderedMap.h"
@ -110,7 +110,7 @@ class InstanceSave
bool m_canReset;
};
class MANGOS_DLL_DECL InstanceSaveManager : public MaNGOS::Singleton<InstanceSaveManager, MaNGOS::ClassLevelLockable<InstanceSaveManager, ZThread::Mutex> >
class MANGOS_DLL_DECL InstanceSaveManager : public MaNGOS::Singleton<InstanceSaveManager, MaNGOS::ClassLevelLockable<InstanceSaveManager, ACE_Thread_Mutex> >
{
friend class InstanceSave;
public:

View file

@ -117,7 +117,7 @@ void Map::LoadVMap(int gx,int gy)
}
}
void Map::LoadMap(int gx,int gy)
void Map::LoadMap(int gx,int gy, bool reload)
{
if( i_InstanceId != 0 )
{
@ -135,6 +135,9 @@ void Map::LoadMap(int gx,int gy)
return;
}
if(GridMaps[gx][gy] && !reload)
return;
//map already load, delete it before reloading (Is it necessary? Do we really need the ability the reload maps during runtime?)
if(GridMaps[gx][gy])
{

View file

@ -21,9 +21,9 @@
#include "Platform/Define.h"
#include "Policies/ThreadingModel.h"
#include "zthread/Lockable.h"
#include "zthread/Mutex.h"
#include "zthread/FairReadWriteLock.h"
#include "ace/RW_Thread_Mutex.h"
#include "ace/Thread_Mutex.h"
#include "DBCStructure.h"
#include "GridDefines.h"
#include "Cell.h"
@ -42,13 +42,8 @@ class InstanceData;
class Group;
class InstanceSave;
namespace ZThread
{
class Lockable;
class ReadWriteLock;
}
typedef ZThread::FairReadWriteLock GridRWLock;
typedef ACE_RW_Thread_Mutex GridRWLock;
template<class MUTEX, class LOCK_TYPE>
struct RGuard
@ -64,8 +59,8 @@ struct WGuard
MaNGOS::GeneralLock<LOCK_TYPE> i_lock;
};
typedef RGuard<GridRWLock, ZThread::Lockable> GridReadGuard;
typedef WGuard<GridRWLock, ZThread::Lockable> GridWriteGuard;
typedef RGuard<GridRWLock, ACE_Thread_Mutex> GridReadGuard;
typedef WGuard<GridRWLock, ACE_Thread_Mutex> GridWriteGuard;
typedef MaNGOS::SingleThreaded<GridRWLock>::Lock NullGuard;
//******************************************
@ -246,7 +241,7 @@ typedef UNORDERED_MAP<Creature*, CreatureMover> CreatureMoveList;
#define INVALID_HEIGHT -100000.0f // for check, must be equal to VMAP_INVALID_HEIGHT, real value for unknown height is VMAP_INVALID_HEIGHT_VALUE
#define MIN_UNLOAD_DELAY 1 // immediate unload
class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::ObjectLevelLockable<Map, ZThread::Mutex>
class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::ObjectLevelLockable<Map, ACE_Thread_Mutex>
{
friend class MapReference;
public:
@ -409,7 +404,7 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj
private:
void LoadMapAndVMap(int gx, int gy);
void LoadVMap(int gx, int gy);
void LoadMap(int gx,int gy);
void LoadMap(int gx,int gy, bool reload = false);
GridMap *GetGrid(float x, float y);
void SetTimer(uint32 t) { i_gridExpiry = t < MIN_GRID_DELAY ? MIN_GRID_DELAY : t; }
@ -451,7 +446,7 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj
protected:
void SetUnloadReferenceLock(const GridPair &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadReferenceLock(on); }
typedef MaNGOS::ObjectLevelLockable<Map, ZThread::Mutex>::Lock Guard;
typedef MaNGOS::ObjectLevelLockable<Map, ACE_Thread_Mutex>::Lock Guard;
MapEntry const* i_mapEntry;
uint8 i_spawnMode;

View file

@ -31,9 +31,9 @@
#include "Corpse.h"
#include "ObjectMgr.h"
#define CLASS_LOCK MaNGOS::ClassLevelLockable<MapManager, ZThread::Mutex>
#define CLASS_LOCK MaNGOS::ClassLevelLockable<MapManager, ACE_Thread_Mutex>
INSTANTIATE_SINGLETON_2(MapManager, CLASS_LOCK);
INSTANTIATE_CLASS_MUTEX(MapManager, ZThread::Mutex);
INSTANTIATE_CLASS_MUTEX(MapManager, ACE_Thread_Mutex);
extern GridState* si_GridStates[]; // debugging code, should be deleted some day

View file

@ -21,14 +21,14 @@
#include "Platform/Define.h"
#include "Policies/Singleton.h"
#include "zthread/Mutex.h"
#include "ace/Thread_Mutex.h"
#include "Common.h"
#include "Map.h"
#include "GridStates.h"
class Transport;
class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::ClassLevelLockable<MapManager, ZThread::Mutex> >
class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::ClassLevelLockable<MapManager, ACE_Thread_Mutex> >
{
friend class MaNGOS::OperatorNew<MapManager>;
@ -147,7 +147,7 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::
return (iter == i_maps.end() ? NULL : iter->second);
}
typedef MaNGOS::ClassLevelLockable<MapManager, ZThread::Mutex>::Lock Guard;
typedef MaNGOS::ClassLevelLockable<MapManager, ACE_Thread_Mutex>::Lock Guard;
uint32 i_gridCleanUpDelay;
MapMapType i_maps;
IntervalTimer i_timer;

View file

@ -39,9 +39,9 @@
#include <cmath>
#define CLASS_LOCK MaNGOS::ClassLevelLockable<ObjectAccessor, ZThread::FastMutex>
#define CLASS_LOCK MaNGOS::ClassLevelLockable<ObjectAccessor, ACE_Thread_Mutex>
INSTANTIATE_SINGLETON_2(ObjectAccessor, CLASS_LOCK);
INSTANTIATE_CLASS_MUTEX(ObjectAccessor, ZThread::FastMutex);
INSTANTIATE_CLASS_MUTEX(ObjectAccessor, ACE_Thread_Mutex);
ObjectAccessor::ObjectAccessor() {}
ObjectAccessor::~ObjectAccessor() {}
@ -438,7 +438,7 @@ void ObjectAccessor::UpdateVisibilityForPlayer( Player* player )
/// Define the static member of HashMapHolder
template <class T> UNORDERED_MAP< uint64, T* > HashMapHolder<T>::m_objectMap;
template <class T> ZThread::FastMutex HashMapHolder<T>::i_lock;
template <class T> ACE_Thread_Mutex HashMapHolder<T>::i_lock;
/// Global definitions for the hashmap storage

View file

@ -21,7 +21,7 @@
#include "Platform/Define.h"
#include "Policies/Singleton.h"
#include "zthread/FastMutex.h"
#include <ace/Thread_Mutex.h>
#include "Utilities/UnorderedMap.h"
#include "Policies/ThreadingModel.h"
@ -49,7 +49,7 @@ class HashMapHolder
public:
typedef UNORDERED_MAP< uint64, T* > MapType;
typedef ZThread::FastMutex LockType;
typedef ACE_Thread_Mutex LockType;
typedef MaNGOS::GeneralLock<LockType > Guard;
static void Insert(T* o) { m_objectMap[o->GetGUID()] = o; }
@ -78,7 +78,7 @@ class HashMapHolder
static MapType m_objectMap;
};
class MANGOS_DLL_DECL ObjectAccessor : public MaNGOS::Singleton<ObjectAccessor, MaNGOS::ClassLevelLockable<ObjectAccessor, ZThread::FastMutex> >
class MANGOS_DLL_DECL ObjectAccessor : public MaNGOS::Singleton<ObjectAccessor, MaNGOS::ClassLevelLockable<ObjectAccessor, ACE_Thread_Mutex> >
{
friend class MaNGOS::OperatorNew<ObjectAccessor>;
@ -212,7 +212,7 @@ class MANGOS_DLL_DECL ObjectAccessor : public MaNGOS::Singleton<ObjectAccessor,
friend struct WorldObjectChangeAccumulator;
Player2CorpsesMapType i_player2corpse;
typedef ZThread::FastMutex LockType;
typedef ACE_Thread_Mutex LockType;
typedef MaNGOS::GeneralLock<LockType > Guard;
static void _buildChangeObjectForPlayer(WorldObject *, UpdateDataMapType &);

View file

@ -557,7 +557,7 @@ class World
static float m_VisibleObjectGreyDistance;
// CLI command holder to be thread safe
ZThread::LockedQueue<CliCommandHolder*, ZThread::FastMutex> cliCmdQueue;
ACE_Based::LockedQueue<CliCommandHolder*,ACE_Thread_Mutex> cliCmdQueue;
SqlResultQueue *m_resultQueue;
// next daily quests reset time
@ -568,7 +568,7 @@ class World
//sessions that are added async
void AddSession_(WorldSession* s);
ZThread::LockedQueue<WorldSession*, ZThread::FastMutex> addSessQueue;
ACE_Based::LockedQueue<WorldSession*, ACE_Thread_Mutex> addSessQueue;
//used versions
std::string m_DBVersion;

View file

@ -24,9 +24,9 @@
#include "Policies/SingletonImp.h"
#include "Config/ConfigEnv.h"
#define CLASS_LOCK MaNGOS::ClassLevelLockable<WorldLog, ZThread::FastMutex>
#define CLASS_LOCK MaNGOS::ClassLevelLockable<WorldLog, ACE_Thread_Mutex>
INSTANTIATE_SINGLETON_2(WorldLog, CLASS_LOCK);
INSTANTIATE_CLASS_MUTEX(WorldLog, ZThread::FastMutex);
INSTANTIATE_CLASS_MUTEX(WorldLog, ACE_Thread_Mutex);
#define WORLD_LOG_FILE_STRING "world.log"

View file

@ -30,13 +30,13 @@
#include <stdarg.h>
/// %Log packets to a file
class MANGOS_DLL_DECL WorldLog : public MaNGOS::Singleton<WorldLog, MaNGOS::ClassLevelLockable<WorldLog, ZThread::FastMutex> >
class MANGOS_DLL_DECL WorldLog : public MaNGOS::Singleton<WorldLog, MaNGOS::ClassLevelLockable<WorldLog, ACE_Thread_Mutex> >
{
friend class MaNGOS::OperatorNew<WorldLog>;
WorldLog() : i_file(NULL) { Initialize(); }
WorldLog(const WorldLog &);
WorldLog& operator=(const WorldLog &);
typedef MaNGOS::ClassLevelLockable<WorldLog, ZThread::FastMutex>::Lock Guard;
typedef MaNGOS::ClassLevelLockable<WorldLog, ACE_Thread_Mutex>::Lock Guard;
/// Close the file in destructor
~WorldLog()

View file

@ -738,8 +738,7 @@ class MANGOS_DLL_SPEC WorldSession
uint32 m_Tutorials[8];
bool m_TutorialsChanged;
AddonsList m_addonsList;
ZThread::LockedQueue<WorldPacket*,ZThread::FastMutex> _recvQueue;
ACE_Based::LockedQueue<WorldPacket*, ACE_Thread_Mutex> _recvQueue;
};
#endif
/// @}

View file

@ -24,7 +24,7 @@
#define __CLIRUNNABLE_H
/// Command Line Interface handling thread
class CliRunnable : public ZThread::Runnable
class CliRunnable : public ACE_Based::Runnable
{
public:
void run();

View file

@ -33,8 +33,8 @@ mangos_worldd_SOURCES = \
WorldRunnable.h
## Link world daemon against the shared library
mangos_worldd_LDADD = ../bindings/universal/libmangosscript.la ../game/libmangosgame.a ../shared/Database/libmangosdatabase.a ../shared/Config/libmangosconfig.a ../shared/Auth/libmangosauth.a ../shared/libmangosshared.a ../shared/vmap/libmangosvmaps.a ../framework/libmangosframework.a ../../dep/src/sockets/libmangossockets.a ../../dep/src/zthread/libZThread.la ../../dep/src/g3dlite/libg3dlite.a
mangos_worldd_LDFLAGS = -L../../dep/src/sockets -L../../dep/src/zthread -L../../dep/src/g3dlite -L../bindings/universal/ -L$(libdir) $(MANGOS_LIBS) -export-dynamic
mangos_worldd_LDADD = ../bindings/universal/libmangosscript.la ../game/libmangosgame.a ../shared/Database/libmangosdatabase.a ../shared/Config/libmangosconfig.a ../shared/Auth/libmangosauth.a ../shared/libmangosshared.a ../shared/vmap/libmangosvmaps.a ../framework/libmangosframework.a ../../dep/src/sockets/libmangossockets.a ../../dep/src/g3dlite/libg3dlite.a
mangos_worldd_LDFLAGS = -L../../dep/src/sockets -L../../dep/src/g3dlite -L../bindings/universal/ -L$(libdir) $(MANGOS_LIBS) -export-dynamic
## Additional files to include when running 'make dist'
# Include world daemon configuration

View file

@ -58,7 +58,7 @@ INSTANTIATE_SINGLETON_1( Master );
volatile uint32 Master::m_masterLoopCounter = 0;
class FreezeDetectorRunnable : public ZThread::Runnable
class FreezeDetectorRunnable : public ACE_Based::Runnable
{
public:
FreezeDetectorRunnable() { _delaytime = 0; }
@ -77,7 +77,8 @@ public:
w_lastchange = 0;
while(!World::IsStopped())
{
ZThread::Thread::sleep(1000);
ACE_Based::Thread::Sleep(1000);
uint32 curtime = getMSTime();
//DEBUG_LOG("anti-freeze: time=%u, counters=[%u; %u]",curtime,Master::m_masterLoopCounter,World::m_worldLoopCounter);
@ -113,7 +114,7 @@ public:
}
};
class RARunnable : public ZThread::Runnable
class RARunnable : public ACE_Based::Runnable
{
public:
uint32 numLoops, loopCounter;
@ -179,7 +180,7 @@ public:
{
while (!World::IsStopped())
{
ZThread::Thread::sleep (static_cast<unsigned long> (socketSelecttime / 1000));
ACE_Based::Thread::Sleep(static_cast<unsigned long> (socketSelecttime / 1000));
checkping ();
}
}
@ -222,8 +223,8 @@ int Master::Run()
_HookSignals();
///- Launch WorldRunnable thread
ZThread::Thread t(new WorldRunnable);
t.setPriority ((ZThread::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);
@ -235,10 +236,10 @@ int Master::Run()
#endif
{
///- Launch CliRunnable thread
ZThread::Thread td1(new CliRunnable);
ACE_Based::Thread td1(*new CliRunnable);
}
ZThread::Thread td2(new RARunnable);
ACE_Based::Thread td2(*new RARunnable);
///- Handle affinity for multiple processors and process priority on Windows
#ifdef WIN32
@ -299,8 +300,8 @@ int Master::Run()
{
FreezeDetectorRunnable *fdr = new FreezeDetectorRunnable();
fdr->SetDelayTime(freeze_delay*1000);
ZThread::Thread t(fdr);
t.setPriority(ZThread::High);
ACE_Based::Thread t(*fdr);
t.setPriority(ACE_Based::Highest);
}
///- Launch the world listener socket

View file

@ -72,7 +72,7 @@ void WorldRunnable::run()
if (diff <= WORLD_SLEEP_CONST+prevSleepTime)
{
prevSleepTime = WORLD_SLEEP_CONST+prevSleepTime-diff;
ZThread::Thread::sleep(prevSleepTime);
ACE_Based::Thread::Sleep(prevSleepTime);
}
else
prevSleepTime = 0;

View file

@ -24,7 +24,7 @@
#define __WORLDRUNNABLE_H
/// Heartbeat thread for the World
class WorldRunnable : public ZThread::Runnable
class WorldRunnable : public ACE_Based::Runnable
{
public:
void run();

View file

@ -171,7 +171,7 @@ typedef struct AuthHandler
#endif
/// Launch a thread to transfer a patch to the client
class PatcherRunnable: public ZThread::Runnable
class PatcherRunnable: public ACE_Based::Runnable
{
public:
PatcherRunnable(class AuthSocket *);
@ -234,7 +234,8 @@ AuthSocket::AuthSocket(ISocketHandler &h) : TcpSocket(h)
/// Close patch file descriptor before leaving
AuthSocket::~AuthSocket()
{
ZThread::Guard<ZThread::Mutex> g(patcherLock);
ACE_Guard<ACE_Thread_Mutex> g(patcherLock);
if(pPatch)
fclose(pPatch);
}
@ -910,7 +911,7 @@ bool AuthSocket::_HandleXferResume()
ibuf.Read((char*)&start,sizeof(start));
fseek(pPatch,start,0);
ZThread::Thread u(new PatcherRunnable(this));
ACE_Based::Thread u(*new PatcherRunnable(this));
return true;
}
@ -922,7 +923,6 @@ bool AuthSocket::_HandleXferCancel()
///- Close and delete the socket
ibuf.Remove(1); //clear input buffer
//ZThread::Thread::sleep(15);
SetCloseAndDelete();
return true;
@ -944,8 +944,7 @@ bool AuthSocket::_HandleXferAccept()
ibuf.Remove(1); //clear input buffer
fseek(pPatch,0,0);
ZThread::Thread u(new PatcherRunnable(this));
ACE_Based::Thread u(*new PatcherRunnable(this));
return true;
}
@ -963,7 +962,8 @@ PatcherRunnable::PatcherRunnable(class AuthSocket * as)
/// Send content of patch file to the client
void PatcherRunnable::run()
{
ZThread::Guard<ZThread::Mutex> g(mySocket->patcherLock);
ACE_Guard<ACE_Thread_Mutex> g(mySocket->patcherLock);
XFER_DATA_STRUCT xfdata;
xfdata.opcode = XFER_DATA;
@ -972,7 +972,7 @@ void PatcherRunnable::run()
///- Wait until output buffer is reasonably empty
while(mySocket->Ready() && mySocket->IsLag())
{
ZThread::Thread::sleep(1);
ACE_Based::Thread::Sleep(1);
}
///- And send content of the patch file to the client
xfdata.data_size=fread(&xfdata.data,1,ChunkSize,mySocket->pPatch);

View file

@ -31,7 +31,6 @@
#include "sockets/Utility.h"
#include "sockets/Parse.h"
#include "sockets/Socket.h"
#include "zthread/Mutex.h"
/// Handle login commands
class AuthSocket: public TcpSocket
@ -59,7 +58,7 @@ class AuthSocket: public TcpSocket
void _SetVSFields(const std::string& rI);
FILE *pPatch;
ZThread::Mutex patcherLock;
ACE_Thread_Mutex patcherLock;
bool IsLag();
private:

View file

@ -30,8 +30,8 @@ mangos_realmd_SOURCES = \
RealmList.h
## Link realm list daemon against the shared library
mangos_realmd_LDADD = ../shared/Database/libmangosdatabase.a ../shared/Config/libmangosconfig.a ../shared/Auth/libmangosauth.a ../shared/libmangosshared.a ../framework/libmangosframework.a ../../dep/src/sockets/libmangossockets.a ../../dep/src/zthread/libZThread.la
mangos_realmd_LDFLAGS = -L../../dep/src/sockets -L../../dep/src/zthread -L$(libdir) $(MANGOS_LIBS)
mangos_realmd_LDADD = ../shared/Database/libmangosdatabase.a ../shared/Config/libmangosconfig.a ../shared/Auth/libmangosauth.a ../shared/libmangosshared.a ../framework/libmangosframework.a ../../dep/src/sockets/libmangossockets.a
mangos_realmd_LDFLAGS = -L../../dep/src/sockets -L$(libdir) $(MANGOS_LIBS)
## Additional files to include when running 'make dist'
# Include realm list daemon configuration

View file

@ -79,6 +79,7 @@
#include <math.h>
#include <errno.h>
#include <signal.h>
#include <assert.h>
#if PLATFORM == PLATFORM_WINDOWS
#define STRCASECMP stricmp
@ -94,10 +95,13 @@
#include <sstream>
#include <algorithm>
#include <zthread/FastMutex.h>
#include <zthread/LockedQueue.h>
#include <zthread/Runnable.h>
#include <zthread/Thread.h>
#include "LockedQueue.h"
#include "Threading.h"
#include <ace/Guard_T.h>
#include <ace/RW_Thread_Mutex.h>
#include <ace/Thread_Mutex.h>
#if PLATFORM == PLATFORM_WINDOWS
# define FD_SETSIZE 4096

View file

@ -108,7 +108,8 @@ bool Database::PExecuteLog(const char * format,...)
void Database::SetResultQueue(SqlResultQueue * queue)
{
m_queryQueues[ZThread::ThreadImpl::current()] = queue;
m_queryQueues[ACE_Based::Thread::current()] = queue;
}
QueryResult* Database::PQuery(const char *format,...)

View file

@ -19,8 +19,7 @@
#ifndef DATABASE_H
#define DATABASE_H
#include "zthread/Thread.h"
#include "../src/zthread/ThreadImpl.h"
#include "Threading.h"
#include "Utilities/UnorderedMap.h"
#include "Database/SqlDelayThread.h"
@ -28,8 +27,8 @@ class SqlTransaction;
class SqlResultQueue;
class SqlQueryHolder;
typedef UNORDERED_MAP<ZThread::ThreadImpl*, SqlTransaction*> TransactionQueues;
typedef UNORDERED_MAP<ZThread::ThreadImpl*, SqlResultQueue*> QueryQueues;
typedef UNORDERED_MAP<ACE_Based::Thread* , SqlTransaction*> TransactionQueues;
typedef UNORDERED_MAP<ACE_Based::Thread* , SqlResultQueue*> QueryQueues;
#define MAX_QUERY_LEN 32*1024
@ -41,7 +40,7 @@ class MANGOS_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
ZThread::Thread* m_delayThread; ///< Pointer to executer thread
ACE_Based::Thread* m_delayThread; ///< Pointer to executer thread
public:

View file

@ -27,7 +27,7 @@
QueryQueues::iterator queue_itr; \
\
{ \
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); \
ACE_Based::Thread * queryThread = ACE_Based::Thread::current(); \
queue_itr = m_queryQueues.find(queryThread); \
if (queue_itr == m_queryQueues.end()) return false; \
}
@ -57,7 +57,7 @@
QueryQueues::iterator queue_itr; \
\
{ \
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); \
ACE_Based::Thread * queryThread = ACE_Based::Thread::current(); \
queue_itr = m_queryQueues.find(queryThread); \
if (queue_itr == m_queryQueues.end()) return false; \
}

View file

@ -21,7 +21,7 @@
#include "Util.h"
#include "Policies/SingletonImp.h"
#include "Platform/Define.h"
#include "../src/zthread/ThreadImpl.h"
#include "Threading.h"
#include "DatabaseEnv.h"
#include "Database/MySQLDelayThread.h"
#include "Database/SqlOperations.h"
@ -187,7 +187,7 @@ QueryResult* DatabaseMysql::Query(const char *sql)
{
// guarded block for thread-safe mySQL request
ZThread::Guard<ZThread::FastMutex> query_connection_guard(mMutex);
ACE_Guard<ACE_Thread_Mutex> query_connection_guard(mMutex);
#ifdef MANGOS_DEBUG
uint32 _s = getMSTime();
#endif
@ -235,7 +235,7 @@ bool DatabaseMysql::Execute(const char *sql)
// don't use queued execution if it has not been initialized
if (!m_threadBody) return DirectExecute(sql);
tranThread = ZThread::ThreadImpl::current(); // owner of this transaction
tranThread = ACE_Based::Thread::current(); // owner of this transaction
TransactionQueues::iterator i = m_tranQueues.find(tranThread);
if (i != m_tranQueues.end() && i->second != NULL)
{ // Statement for transaction
@ -257,7 +257,8 @@ bool DatabaseMysql::DirectExecute(const char* sql)
{
// guarded block for thread-safe mySQL request
ZThread::Guard<ZThread::FastMutex> query_connection_guard(mMutex);
ACE_Guard<ACE_Thread_Mutex> query_connection_guard(mMutex);
#ifdef MANGOS_DEBUG
uint32 _s = getMSTime();
#endif
@ -302,8 +303,9 @@ bool DatabaseMysql::BeginTransaction()
// don't use queued execution if it has not been initialized
if (!m_threadBody)
{
if (tranThread==ZThread::ThreadImpl::current())
if (tranThread == ACE_Based::Thread::current())
return false; // huh? this thread already started transaction
mMutex.acquire();
if (!_TransactionCmd("START TRANSACTION"))
{
@ -313,7 +315,7 @@ bool DatabaseMysql::BeginTransaction()
return true; // transaction started
}
tranThread = ZThread::ThreadImpl::current(); // owner of this transaction
tranThread = ACE_Based::Thread::current(); // owner of this transaction
TransactionQueues::iterator i = m_tranQueues.find(tranThread);
if (i != m_tranQueues.end() && i->second != NULL)
// If for thread exists queue and also contains transaction
@ -333,7 +335,7 @@ bool DatabaseMysql::CommitTransaction()
// don't use queued execution if it has not been initialized
if (!m_threadBody)
{
if (tranThread!=ZThread::ThreadImpl::current())
if (tranThread != ACE_Based::Thread::current())
return false;
bool _res = _TransactionCmd("COMMIT");
tranThread = NULL;
@ -341,7 +343,7 @@ bool DatabaseMysql::CommitTransaction()
return _res;
}
tranThread = ZThread::ThreadImpl::current();
tranThread = ACE_Based::Thread::current();
TransactionQueues::iterator i = m_tranQueues.find(tranThread);
if (i != m_tranQueues.end() && i->second != NULL)
{
@ -361,7 +363,7 @@ bool DatabaseMysql::RollbackTransaction()
// don't use queued execution if it has not been initialized
if (!m_threadBody)
{
if (tranThread!=ZThread::ThreadImpl::current())
if (tranThread != ACE_Based::Thread::current())
return false;
bool _res = _TransactionCmd("ROLLBACK");
tranThread = NULL;
@ -369,7 +371,7 @@ bool DatabaseMysql::RollbackTransaction()
return _res;
}
tranThread = ZThread::ThreadImpl::current();
tranThread = ACE_Based::Thread::current();
TransactionQueues::iterator i = m_tranQueues.find(tranThread);
if (i != m_tranQueues.end() && i->second != NULL)
{
@ -392,7 +394,8 @@ void DatabaseMysql::InitDelayThread()
assert(!m_delayThread);
//New delay thread for delay execute
m_delayThread = new ZThread::Thread(m_threadBody = new MySQLDelayThread(this));
m_threadBody = new MySQLDelayThread(this);
m_delayThread = new ACE_Based::Thread(*m_threadBody);
}
void DatabaseMysql::HaltDelayThread()

View file

@ -23,7 +23,8 @@
#include "Database.h"
#include "Policies/Singleton.h"
#include "zthread/FastMutex.h"
#include "ace/Thread_Mutex.h"
#include "ace/Guard_T.h"
#ifdef WIN32
#define FD_SETSIZE 1024
@ -63,9 +64,9 @@ class MANGOS_DLL_SPEC DatabaseMysql : public Database
// must be call before finish thread run
void ThreadEnd();
private:
ZThread::FastMutex mMutex;
ACE_Thread_Mutex mMutex;
ZThread::ThreadImpl* tranThread;
ACE_Based::Thread * tranThread;
MYSQL *mMysql;

View file

@ -21,7 +21,7 @@
#include "Util.h"
#include "Policies/SingletonImp.h"
#include "Platform/Define.h"
#include "../src/zthread/ThreadImpl.h"
#include "Threading.h"
#include "DatabaseEnv.h"
#include "Database/PGSQLDelayThread.h"
#include "Database/SqlOperations.h"
@ -124,7 +124,7 @@ QueryResult* DatabasePostgre::Query(const char *sql)
uint32 fieldCount = 0;
// guarded block for thread-safe request
ZThread::Guard<ZThread::FastMutex> query_connection_guard(mMutex);
ACE_Guard<ACE_Thread_Mutex> query_connection_guard(mMutex);
#ifdef MANGOS_DEBUG
uint32 _s = getMSTime();
#endif
@ -172,9 +172,10 @@ bool DatabasePostgre::Execute(const char *sql)
return false;
// don't use queued execution if it has not been initialized
if (!m_threadBody) return DirectExecute(sql);
if (!m_threadBody)
return DirectExecute(sql);
tranThread = ZThread::ThreadImpl::current(); // owner of this transaction
tranThread = ACE_Based::Thread::current(); // owner of this transaction
TransactionQueues::iterator i = m_tranQueues.find(tranThread);
if (i != m_tranQueues.end() && i->second != NULL)
{ // Statement for transaction
@ -195,7 +196,7 @@ bool DatabasePostgre::DirectExecute(const char* sql)
return false;
{
// guarded block for thread-safe request
ZThread::Guard<ZThread::FastMutex> query_connection_guard(mMutex);
ACE_Guard<ACE_Thread_Mutex> query_connection_guard(mMutex);
#ifdef MANGOS_DEBUG
uint32 _s = getMSTime();
#endif
@ -245,7 +246,7 @@ bool DatabasePostgre::BeginTransaction()
// don't use queued execution if it has not been initialized
if (!m_threadBody)
{
if (tranThread==ZThread::ThreadImpl::current())
if (tranThread == ACE_Based::Thread::current())
return false; // huh? this thread already started transaction
mMutex.acquire();
if (!_TransactionCmd("START TRANSACTION"))
@ -256,7 +257,7 @@ bool DatabasePostgre::BeginTransaction()
return true;
}
// transaction started
tranThread = ZThread::ThreadImpl::current(); // owner of this transaction
tranThread = ACE_Based::Thread::current(); // owner of this transaction
TransactionQueues::iterator i = m_tranQueues.find(tranThread);
if (i != m_tranQueues.end() && i->second != NULL)
// If for thread exists queue and also contains transaction
@ -276,14 +277,14 @@ bool DatabasePostgre::CommitTransaction()
// don't use queued execution if it has not been initialized
if (!m_threadBody)
{
if (tranThread!=ZThread::ThreadImpl::current())
if (tranThread != ACE_Based::Thread::current())
return false;
bool _res = _TransactionCmd("COMMIT");
tranThread = NULL;
mMutex.release();
return _res;
}
tranThread = ZThread::ThreadImpl::current();
tranThread = ACE_Based::Thread::current();
TransactionQueues::iterator i = m_tranQueues.find(tranThread);
if (i != m_tranQueues.end() && i->second != NULL)
{
@ -302,14 +303,14 @@ bool DatabasePostgre::RollbackTransaction()
// don't use queued execution if it has not been initialized
if (!m_threadBody)
{
if (tranThread!=ZThread::ThreadImpl::current())
if (tranThread != ACE_Based::Thread::current())
return false;
bool _res = _TransactionCmd("ROLLBACK");
tranThread = NULL;
mMutex.release();
return _res;
}
tranThread = ZThread::ThreadImpl::current();
tranThread = ACE_Based::Thread::current();
TransactionQueues::iterator i = m_tranQueues.find(tranThread);
if (i != m_tranQueues.end() && i->second != NULL)
{
@ -332,7 +333,8 @@ void DatabasePostgre::InitDelayThread()
assert(!m_delayThread);
//New delay thread for delay execute
m_delayThread = new ZThread::Thread(m_threadBody = new PGSQLDelayThread(this));
m_threadBody = new PGSQLDelayThread(this);
m_delayThread = new ACE_Based::Thread(*m_threadBody);
}
void DatabasePostgre::HaltDelayThread()

View file

@ -20,7 +20,6 @@
#define _DatabasePostgre_H
#include "Policies/Singleton.h"
#include "zthread/FastMutex.h"
#include <stdarg.h>
#ifdef WIN32
@ -61,10 +60,8 @@ class DatabasePostgre : public Database
// must be call before finish thread run
void ThreadEnd();
private:
ZThread::FastMutex mMutex;
ZThread::FastMutex tranMutex;
ZThread::ThreadImpl* tranThread;
ACE_Thread_Mutex mMutex;
ACE_Based::Thread * tranThread;
PGconn *mPGconn;

View file

@ -38,7 +38,7 @@ class MANGOS_DLL_SPEC QueryResult
if(iter->second == name)
return iter->first;
}
assert(false && "unknown field name");
ASSERT(false && "unknown field name");
return uint32(-1);
}

View file

@ -35,7 +35,7 @@ void SqlDelayThread::run()
{
// if the running state gets turned off while sleeping
// empty the queue before exiting
ZThread::Thread::sleep(10);
ACE_Based::Thread::Sleep(10);
while (!m_sqlQueue.empty())
{
s = m_sqlQueue.next();

View file

@ -19,21 +19,22 @@
#ifndef __SQLDELAYTHREAD_H
#define __SQLDELAYTHREAD_H
#include "zthread/Thread.h"
#include "zthread/Runnable.h"
#include "zthread/FastMutex.h"
#include "zthread/LockedQueue.h"
#include "ace/Thread_Mutex.h"
#include "LockedQueue.h"
#include "Threading.h"
class Database;
class SqlOperation;
class SqlDelayThread : public ZThread::Runnable
class SqlDelayThread : public ACE_Based::Runnable
{
typedef ZThread::LockedQueue<SqlOperation*, ZThread::FastMutex> SqlQueue;
typedef ACE_Based::LockedQueue<SqlOperation*, ACE_Thread_Mutex> SqlQueue;
private:
SqlQueue m_sqlQueue; ///< Queue of SQL statements
Database* m_dbEngine; ///< Pointer to used Database engine
bool m_running;
volatile bool m_running;
SqlDelayThread();
public:

View file

@ -21,9 +21,8 @@
#include "Common.h"
#include "zthread/LockedQueue.h"
#include "zthread/FastMutex.h"
#include "zthread/Thread.h"
#include "ace/Thread_Mutex.h"
#include "LockedQueue.h"
#include <queue>
#include "Utilities/Callback.h"
@ -70,7 +69,7 @@ class SqlResultQueue; /// queue for thread
class SqlQueryHolder; /// groups several async quries
class SqlQueryHolderEx; /// points to a holder, added to the delay thread
class SqlResultQueue : public ZThread::LockedQueue<MaNGOS::IQueryCallback*, ZThread::FastMutex>
class SqlResultQueue : public ACE_Based::LockedQueue<MaNGOS::IQueryCallback* , ACE_Thread_Mutex>
{
public:
SqlResultQueue() {}

144
src/shared/LockedQueue.h Normal file
View file

@ -0,0 +1,144 @@
/*
* 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 LOCKEDQUEUE_H
#define LOCKEDQUEUE_H
#include <ace/Guard_T.h>
#include <ace/Thread_Mutex.h>
#include <deque>
#include <assert.h>
#include "Errors.h"
namespace ACE_Based
{
template <class T, class LockType, typename StorageType=std::deque<T> >
class LockedQueue
{
//! Serialize access to the Queue
LockType _lock;
//! Storage backing the queue
StorageType _queue;
//! Cancellation flag
volatile bool _canceled;
public:
//! Create a LockedQueue
LockedQueue() : _canceled(false) {}
//! Destroy a LockedQueue
virtual ~LockedQueue() { }
/**
* @see Queue::add(const T& item)
*/
void add(const T& item)
{
ACE_Guard<LockType> g(_lock);
ASSERT(!_canceled);
// throw Cancellation_Exception();
_queue.push_back(item);
}
/**
* @see Queue::next()
*/
T next()
{
ACE_Guard<LockType> g(_lock);
ASSERT (!_queue.empty() || !_canceled);
// throw Cancellation_Exception();
T item = _queue.front();
_queue.pop_front();
return item;
}
T front()
{
ACE_Guard<LockType> g(_lock);
ASSERT (!_queue.empty());
// throw NoSuchElement_Exception();
return _queue.front();
}
/**
* @see Queue::cancel()
*/
void cancel()
{
ACE_Guard<LockType> g(_lock);
_canceled = true;
}
/**
* @see Queue::isCanceled()
*/
bool isCanceled()
{
// Faster check since the queue will not become un-canceled
if(_canceled)
return true;
ACE_Guard<LockType> g(_lock);
return _canceled;
}
/**
* @see Queue::size()
*/
size_t size()
{
ACE_Guard<LockType> g(_lock);
return _queue.size();
}
bool empty()
{
ACE_Guard<LockType> g(_lock);
return _queue.empty();
}
};
}
#endif

View file

@ -54,7 +54,7 @@ enum Color
const int Color_count = int(WHITE)+1;
class Log : public MaNGOS::Singleton<Log, MaNGOS::ClassLevelLockable<Log, ZThread::FastMutex> >
class Log : public MaNGOS::Singleton<Log, MaNGOS::ClassLevelLockable<Log, ACE_Thread_Mutex> >
{
friend class MaNGOS::OperatorNew<Log>;
Log();

View file

@ -36,6 +36,7 @@ libmangosshared_a_SOURCES = \
Common.cpp \
Common.h \
Errors.h \
LockedQueue.h \
Log.cpp \
Log.h \
MemoryLeaks.cpp \
@ -43,6 +44,8 @@ libmangosshared_a_SOURCES = \
ProgressBar.cpp \
ProgressBar.h \
Timer.h \
Threading.cpp \
Threading.h \
Util.cpp \
Util.h \
WorldPacket.h \

202
src/shared/Threading.cpp Normal file
View file

@ -0,0 +1,202 @@
/*
* 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
*/
#include "Threading.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();
}
ASSERT (!_tmp.empty());
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 ¹ piesces
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];
}
#define THREADFLAG (THR_NEW_LWP | THR_SCHED_DEFAULT| THR_JOINABLE)
Thread::Thread() : m_task(0), m_iThreadId(0), m_hThreadHandle(0)
{
}
Thread::Thread(Runnable& instance) : m_task(&instance), m_iThreadId(0), m_hThreadHandle(0)
{
bool _start = start();
ASSERT (_start);
}
Thread::~Thread()
{
//Wait();
}
//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;
return (ACE_Thread::spawn(&Thread::ThreadTask, (void*)m_task, THREADFLAG, &m_iThreadId, &m_hThreadHandle) == 0);
}
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()
{
ACE_Thread::kill(m_iThreadId, -1);
}
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 = (Runnable*)param;
_task->run();
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);
if(_oldValue)
delete _oldValue;
}
return _thread;
}
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)
{
ACE_OS::sleep(ACE_Time_Value(0, 1000 * msecs));
}

99
src/shared/Threading.h Normal file
View file

@ -0,0 +1,99 @@
/*
* 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 <assert.h>
#include "Errors.h"
namespace ACE_Based
{
class Runnable
{
public:
virtual ~Runnable() {}
virtual void run() = 0;
};
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();
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

View file

@ -21,40 +21,34 @@
#include "sockets/socket_include.h"
#include "utf8cpp/utf8.h"
#include "mersennetwister/MersenneTwister.h"
#include "zthread/ThreadLocal.h"
#include <ace/TSS_T.h>
typedef ZThread::ThreadLocal<MTRand> MTRandTSS;
/* NOTE: Not sure if static initialization is ok for TSS objects ,
* as I see zthread uses custom implementation of the TSS
* ,and in the consturctor there is no code ,so I suppose its ok
* If its not ok ,change it to use singleton.
*/
typedef ACE_TSS<MTRand> MTRandTSS;
static MTRandTSS mtRand;
int32 irand (int32 min, int32 max)
{
return int32 (mtRand.get ().randInt (max - min)) + min;
return int32 (mtRand->randInt (max - min)) + min;
}
uint32 urand (uint32 min, uint32 max)
{
return mtRand.get ().randInt (max - min) + min;
return mtRand->randInt (max - min) + min;
}
int32 rand32 ()
{
return mtRand.get ().randInt ();
return mtRand->randInt ();
}
double rand_norm(void)
{
return mtRand.get ().randExc ();
return mtRand->randExc ();
}
double rand_chance (void)
{
return mtRand.get ().randExc (100.0);
return mtRand->randExc (100.0);
}
Tokens StrSplit(const std::string &src, const std::string &sep)

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "7809"
#define REVISION_NR "7811"
#endif // __REVISION_NR_H__