From 8fc07d443acb86ca436caa05b435c86ea6e9071d Mon Sep 17 00:00:00 2001 From: megamage Date: Mon, 11 May 2009 13:27:10 -0500 Subject: *Change waypoint data structure. Use creature db guid as path id. If a creature uses waypoint movement as default movement type, the path id should be DBGUID*10. For paths of script use, the path id should be DBGUID*10+1 ~ DBGUID*10+9. *Two sql queries are included. Converter is used to convert the existing path id to new path id. "...creature_add..." is used to change table structure. You can first run the converter, then run the other one. Or run the other one directly and get the new data from the db team. Because it may take hours to run the converter. *If you have custom data, you may need to run the converter. We suggest you use console to run it It is extremely slow to run the query. If you have multiple paths for a creature in your db, you need to do more work to convert it. However, if you know how to use multiple paths, you should already have more db knowledge than I do and you should know how to convert it. *There may be a faster query to convert the db. If you know, please tell us. I am no sql expert. *Backup your db first! *Thanks to X-Savior and subhuman_bob. --HG-- branch : trunk --- src/shared/Database/SQLStorage.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/shared/Database') diff --git a/src/shared/Database/SQLStorage.cpp b/src/shared/Database/SQLStorage.cpp index 8561afc4a33..67091174c77 100644 --- a/src/shared/Database/SQLStorage.cpp +++ b/src/shared/Database/SQLStorage.cpp @@ -29,9 +29,9 @@ extern DatabaseMysql WorldDatabase; const char CreatureInfosrcfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiiiiiiisiifflliiis"; const char CreatureInfodstfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiiiiiiisiifflliiii"; -const char CreatureDataAddonInfofmt[]="iiiiiiiis"; +const char CreatureDataAddonInfofmt[]="iiiiiiis"; const char CreatureModelfmt[]="iffbi"; -const char CreatureInfoAddonInfofmt[]="iiiiiiiis"; +const char CreatureInfoAddonInfofmt[]="iiiiiiis"; const char EquipmentInfofmt[]="iiii"; const char GameObjectInfosrcfmt[]="iiisssiifiiiiiiiiiiiiiiiiiiiiiiiis"; const char GameObjectInfodstfmt[]="iiisssiifiiiiiiiiiiiiiiiiiiiiiiiii"; -- cgit v1.2.3 From 25e5c99dec793dfcc45a41873af1760392ee8844 Mon Sep 17 00:00:00 2001 From: megamage Date: Wed, 13 May 2009 18:22:21 -0500 Subject: [7810] Moved ZThread related code on ACE framework. Author: Ambal Remove ZThread source code from mangos. --HG-- branch : trunk --- Makefile.am | 9 +- configure.ac | 1 - dep/include/Makefile.am | 48 -- dep/src/Makefile.am | 2 +- dep/src/zthread/AtomicCount.cxx | 57 -- src/bindings/scripts/VC80/80ScriptDev2.vcproj | 16 +- src/bindings/scripts/VC90/90ScriptDev2.vcproj | 16 +- src/framework/Platform/Define.h | 6 + src/game/InstanceSaveMgr.h | 4 +- src/game/Map.h | 23 +- src/game/MapManager.cpp | 4 +- src/game/MapManager.h | 6 +- src/game/ObjectAccessor.cpp | 6 +- src/game/ObjectAccessor.h | 12 +- src/game/SharedDefines.h | 3 - src/game/World.h | 4 +- src/game/WorldLog.cpp | 4 +- src/game/WorldLog.h | 4 +- src/game/WorldSession.h | 3 +- src/shared/Common.h | 12 +- src/shared/Database/Database.cpp | 3 +- src/shared/Database/Database.h | 9 +- src/shared/Database/DatabaseImpl.h | 4 +- src/shared/Database/DatabaseMysql.cpp | 29 +- src/shared/Database/DatabaseMysql.h | 7 +- src/shared/Database/DatabasePostgre.cpp | 31 +- src/shared/Database/DatabasePostgre.h | 7 +- src/shared/Database/QueryResult.h | 2 +- src/shared/Database/SqlDelayThread.cpp | 2 +- src/shared/Database/SqlDelayThread.h | 15 +- src/shared/Database/SqlOperations.h | 7 +- src/shared/Log.h | 2 +- src/shared/Makefile.am | 3 + src/shared/Util.cpp | 20 +- src/trinitycore/CliRunnable.cpp | 4 +- src/trinitycore/CliRunnable.h | 2 +- src/trinitycore/Makefile.am | 5 + src/trinitycore/Master.cpp | 20 +- src/trinitycore/WorldRunnable.cpp | 2 +- src/trinitycore/WorldRunnable.h | 2 +- src/trinityrealm/AuthSocket.cpp | 16 +- src/trinityrealm/AuthSocket.h | 3 +- src/trinityrealm/Makefile.am | 5 + win/TrinityCore&Script VC71.sln | 4 - win/TrinityCore&Script VC80.sln | 2 - win/TrinityCore&Script VC90.sln | 2 - win/VC71/ScriptsInterfaces.vcproj | 14 + win/VC71/TrinityCore.vcproj | 6 +- win/VC71/TrinityRealm.vcproj | 45 +- win/VC71/shared.vcproj | 41 ++ win/VC71/zthread.vcproj | 381 ------------ win/VC80/ScriptsInterfaces.vcproj | 44 +- win/VC80/TrinityCore.vcproj | 58 +- win/VC80/TrinityRealm.vcproj | 94 +-- win/VC80/shared.vcproj | 18 + win/VC90/ScriptsInterfaces.vcproj | 40 +- win/VC90/TrinityCore.vcproj | 58 +- win/VC90/TrinityRealm.vcproj | 94 +-- win/VC90/shared.vcproj | 18 + win/VC90/zthread.vcproj | 799 -------------------------- 60 files changed, 489 insertions(+), 1669 deletions(-) delete mode 100644 dep/src/zthread/AtomicCount.cxx delete mode 100644 win/VC71/zthread.vcproj delete mode 100644 win/VC90/zthread.vcproj (limited to 'src/shared/Database') diff --git a/Makefile.am b/Makefile.am index c7da2a438ef..eb58ac488f2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,8 +31,7 @@ EXTRA_DIST = \ win/VC71/realmd.vcproj \ win/VC71/shared.vcproj \ win/VC71/zlib.vcproj \ - win/VC71/g3dlite.vcproj \ - win/VC71/zthread.vcproj + win/VC71/g3dlite.vcproj # Win32 project workspace for Visual Studio .NET 2005 EXTRA_DIST += \ @@ -43,8 +42,7 @@ EXTRA_DIST += \ win/VC80/realmd.vcproj \ win/VC80/shared.vcproj \ win/VC80/zlib.vcproj \ - win/VC80/g3dlite.vcproj \ - win/VC80/zthread.vcproj + win/VC80/g3dlite.vcproj # Win32 project workspace for Visual Studio .NET 2008 EXTRA_DIST += \ @@ -55,6 +53,5 @@ EXTRA_DIST += \ win/VC90/realmd.vcproj \ win/VC90/shared.vcproj \ win/VC90/zlib.vcproj \ - win/VC90/g3dlite.vcproj \ - win/VC90/zthread.vcproj + win/VC90/g3dlite.vcproj diff --git a/configure.ac b/configure.ac index ede1118be95..d1ec818ac99 100644 --- a/configure.ac +++ b/configure.ac @@ -340,7 +340,6 @@ AC_CONFIG_FILES([ dep/src/g3dlite/Makefile dep/src/sockets/Makefile dep/src/zlib/Makefile - dep/src/zthread/Makefile dep/Makefile doc/Doxyfile doc/Makefile diff --git a/dep/include/Makefile.am b/dep/include/Makefile.am index 3991d1e6274..455f0a81307 100644 --- a/dep/include/Makefile.am +++ b/dep/include/Makefile.am @@ -199,54 +199,6 @@ EXTRA_DIST += \ zlib/zconf.h \ zlib/zlib.h -# ZThread header files for Win32 builds -EXTRA_DIST += \ - zthread/AtomicCount.h \ - zthread/Barrier.h \ - zthread/BiasedReadWriteLock.h \ - zthread/BlockingQueue.h \ - zthread/BoundedQueue.h \ - zthread/Cancelable.h \ - zthread/ClassLockable.h \ - zthread/ConcurrentExecutor.h \ - zthread/Condition.h \ - zthread/Config.h \ - zthread/CountedPtr.h \ - zthread/CountingSemaphore.h \ - zthread/Exceptions.h \ - zthread/Executor.h \ - zthread/FairReadWriteLock.h \ - zthread/FastMutex.h \ - zthread/FastRecursiveMutex.h \ - zthread/Guard.h \ - zthread/GuardedClass.h \ - zthread/Lockable.h \ - zthread/LockedQueue.h \ - zthread/MonitoredQueue.h \ - zthread/Mutex.h \ - zthread/NonCopyable.h \ - zthread/PoolExecutor.h \ - zthread/Priority.h \ - zthread/PriorityCondition.h \ - zthread/PriorityInheritanceMutex.h \ - zthread/PriorityMutex.h \ - zthread/PrioritySemaphore.h \ - zthread/Queue.h \ - zthread/ReadWriteLock.h \ - zthread/RecursiveMutex.h \ - zthread/Runnable.h \ - zthread/Semaphore.h \ - zthread/Singleton.h \ - zthread/SynchronousExecutor.h \ - zthread/Task.h \ - zthread/Thread.h \ - zthread/ThreadLocal.h \ - zthread/ThreadLocalImpl.h \ - zthread/ThreadedExecutor.h \ - zthread/Time.h \ - zthread/Waitable.h \ - zthread/ZThread.h - # Mersenne Twister random number generator header files EXTRA_DIST += \ mersennetwister/MersenneTwister.h diff --git a/dep/src/Makefile.am b/dep/src/Makefile.am index 6ae2808895c..50814f8ff13 100644 --- a/dep/src/Makefile.am +++ b/dep/src/Makefile.am @@ -19,7 +19,7 @@ ## Process this file with automake to produce Makefile.in ## Sub-directories to parse -SUBDIRS = g3dlite sockets zlib zthread +SUBDIRS = g3dlite sockets zlib ## Additional files to include when running 'make dist' # Nothing yet. diff --git a/dep/src/zthread/AtomicCount.cxx b/dep/src/zthread/AtomicCount.cxx deleted file mode 100644 index ac0d0773b12..00000000000 --- a/dep/src/zthread/AtomicCount.cxx +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2005, Eric Crahen - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#ifndef __ZTATOMICCOUNTSELECT_H__ -#define __ZTATOMICCOUNTSELECT_H__ - -#include "zthread/AtomicCount.h" -#include "zthread/Config.h" - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -/* -// Select the correct AtomicCount implementation based on -// what the compilation environment has defined - -#ifndef ZT_VANILLA - -#if defined(HAVE_ATOMIC_LINUX) -# include "linux/AtomicCount.cxx" -#elif defined(ZT_WIN32) -# include "win32/AtomicCount.cxx" -#elif defined(ZT_WIN9X) -# include "win9x/AtomicCount.cxx" -#endif - -#endif - -// Default to an AtomicCount that just uses a FastLock -#ifndef __ZTATOMICCOUNTIMPL_H__ -# include "vanilla/SimpleAtomicCount.cxx" -#endif -*/ - -# include "vanilla/SimpleAtomicCount.cxx" - -#endif // __ZTATOMICCOUNTSELECT_H__ diff --git a/src/bindings/scripts/VC80/80ScriptDev2.vcproj b/src/bindings/scripts/VC80/80ScriptDev2.vcproj index c442ae52a2d..28875c526ab 100644 --- a/src/bindings/scripts/VC80/80ScriptDev2.vcproj +++ b/src/bindings/scripts/VC80/80ScriptDev2.vcproj @@ -68,10 +68,10 @@ /> #include #include "Utilities/UnorderedMap.h" @@ -113,7 +113,7 @@ class InstanceSave bool m_canReset; }; -class TRINITY_DLL_DECL InstanceSaveManager : public Trinity::Singleton > +class MANGOS_DLL_DECL InstanceSaveManager : public MaNGOS::Singleton > { friend class InstanceSave; public: diff --git a/src/game/Map.h b/src/game/Map.h index d85eb459171..a4309504435 100644 --- a/src/game/Map.h +++ b/src/game/Map.h @@ -23,9 +23,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" @@ -46,13 +46,8 @@ class WorldObject; class TempSummon; class CreatureGroup; -namespace ZThread -{ - class Lockable; - class ReadWriteLock; -} -typedef ZThread::FairReadWriteLock GridRWLock; +typedef ACE_RW_Thread_Mutex GridRWLock; template struct RGuard @@ -68,9 +63,9 @@ struct WGuard Trinity::GeneralLock i_lock; }; -typedef RGuard GridReadGuard; -typedef WGuard GridWriteGuard; -typedef Trinity::SingleThreaded::Lock NullGuard; +typedef RGuard GridReadGuard; +typedef WGuard GridWriteGuard; +typedef MaNGOS::SingleThreaded::Lock NullGuard; //****************************************** // Map file format defines @@ -251,7 +246,7 @@ typedef UNORDERED_MAP CreatureMoveList; typedef std::map CreatureGroupHolderType; -class TRINITY_DLL_SPEC Map : public GridRefManager, public Trinity::ObjectLevelLockable +class MANGOS_DLL_SPEC Map : public GridRefManager, public MaNGOS::ObjectLevelLockable { friend class MapReference; public: @@ -466,7 +461,7 @@ class TRINITY_DLL_SPEC Map : public GridRefManager, public Trinity::O protected: void SetUnloadReferenceLock(const GridPair &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadReferenceLock(on); } - typedef Trinity::ObjectLevelLockable::Lock Guard; + typedef MaNGOS::ObjectLevelLockable::Lock Guard; MapEntry const* i_mapEntry; uint8 i_spawnMode; diff --git a/src/game/MapManager.cpp b/src/game/MapManager.cpp index 061e0252a13..d75ba22b19a 100644 --- a/src/game/MapManager.cpp +++ b/src/game/MapManager.cpp @@ -34,9 +34,9 @@ #include "ObjectMgr.h" #include "Language.h" -#define CLASS_LOCK Trinity::ClassLevelLockable +#define CLASS_LOCK MaNGOS::ClassLevelLockable 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 diff --git a/src/game/MapManager.h b/src/game/MapManager.h index 143248de162..b54c1cfbfa1 100644 --- a/src/game/MapManager.h +++ b/src/game/MapManager.h @@ -23,14 +23,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 TRINITY_DLL_DECL MapManager : public Trinity::Singleton > +class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton > { friend class Trinity::OperatorNew; @@ -149,7 +149,7 @@ class TRINITY_DLL_DECL MapManager : public Trinity::Singletonsecond); } - typedef Trinity::ClassLevelLockable::Lock Guard; + typedef MaNGOS::ClassLevelLockable::Lock Guard; uint32 i_gridCleanUpDelay; MapMapType i_maps; IntervalTimer i_timer; diff --git a/src/game/ObjectAccessor.cpp b/src/game/ObjectAccessor.cpp index 1fa0bd6d1ca..da6279e068a 100644 --- a/src/game/ObjectAccessor.cpp +++ b/src/game/ObjectAccessor.cpp @@ -41,9 +41,9 @@ #include -#define CLASS_LOCK Trinity::ClassLevelLockable +#define CLASS_LOCK MaNGOS::ClassLevelLockable INSTANTIATE_SINGLETON_2(ObjectAccessor, CLASS_LOCK); -INSTANTIATE_CLASS_MUTEX(ObjectAccessor, ZThread::FastMutex); +INSTANTIATE_CLASS_MUTEX(ObjectAccessor, ACE_Thread_Mutex); ObjectAccessor::ObjectAccessor() {} ObjectAccessor::~ObjectAccessor() {} @@ -470,7 +470,7 @@ ObjectAccessor::UpdateObjectVisibility(WorldObject *obj) /// Define the static member of HashMapHolder template UNORDERED_MAP< uint64, T* > HashMapHolder::m_objectMap; -template ZThread::FastMutex HashMapHolder::i_lock; +template ACE_Thread_Mutex HashMapHolder::i_lock; /// Global definitions for the hashmap storage diff --git a/src/game/ObjectAccessor.h b/src/game/ObjectAccessor.h index dd8e02b81ab..f4452b81cab 100644 --- a/src/game/ObjectAccessor.h +++ b/src/game/ObjectAccessor.h @@ -23,7 +23,7 @@ #include "Platform/Define.h" #include "Policies/Singleton.h" -#include "zthread/FastMutex.h" +#include #include "Utilities/UnorderedMap.h" #include "Policies/ThreadingModel.h" @@ -51,8 +51,8 @@ class HashMapHolder public: typedef UNORDERED_MAP< uint64, T* > MapType; - typedef ZThread::FastMutex LockType; - typedef Trinity::GeneralLock Guard; + typedef ACE_Thread_Mutex LockType; + typedef MaNGOS::GeneralLock Guard; static void Insert(T* o) { m_objectMap[o->GetGUID()] = o; } @@ -80,7 +80,7 @@ class HashMapHolder static MapType m_objectMap; }; -class TRINITY_DLL_DECL ObjectAccessor : public Trinity::Singleton > +class MANGOS_DLL_DECL ObjectAccessor : public MaNGOS::Singleton > { friend class Trinity::OperatorNew; @@ -228,8 +228,8 @@ class TRINITY_DLL_DECL ObjectAccessor : public Trinity::Singleton Guard; + typedef ACE_Thread_Mutex LockType; + typedef MaNGOS::GeneralLock Guard; static void _buildChangeObjectForPlayer(WorldObject *, UpdateDataMapType &); static void _buildPacket(Player *, Object *, UpdateDataMapType &); diff --git a/src/game/SharedDefines.h b/src/game/SharedDefines.h index e592bebf1de..a068815bb1c 100644 --- a/src/game/SharedDefines.h +++ b/src/game/SharedDefines.h @@ -24,9 +24,6 @@ #include "Platform/Define.h" #include -#define MaNGOS Trinity -#define GetMangosString GetTrinityString - enum Gender { GENDER_MALE = 0, diff --git a/src/game/World.h b/src/game/World.h index 27075885368..80d5717f981 100644 --- a/src/game/World.h +++ b/src/game/World.h @@ -626,7 +626,7 @@ class World static float m_VisibleObjectGreyDistance; // CLI command holder to be thread safe - ZThread::LockedQueue cliCmdQueue; + ACE_Based::LockedQueue cliCmdQueue; SqlResultQueue *m_resultQueue; // next daily quests reset time @@ -637,7 +637,7 @@ class World //sessions that are added async void AddSession_(WorldSession* s); - ZThread::LockedQueue addSessQueue; + ACE_Based::LockedQueue addSessQueue; //used versions std::string m_DBVersion; diff --git a/src/game/WorldLog.cpp b/src/game/WorldLog.cpp index 52eb1e8b59c..978514ac7d7 100644 --- a/src/game/WorldLog.cpp +++ b/src/game/WorldLog.cpp @@ -27,9 +27,9 @@ #include "Config/ConfigEnv.h" #include "Log.h" -#define CLASS_LOCK Trinity::ClassLevelLockable +#define CLASS_LOCK MaNGOS::ClassLevelLockable 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" diff --git a/src/game/WorldLog.h b/src/game/WorldLog.h index 01f34535dd9..e6b72e654f7 100644 --- a/src/game/WorldLog.h +++ b/src/game/WorldLog.h @@ -32,13 +32,13 @@ #include /// %Log packets to a file -class TRINITY_DLL_DECL WorldLog : public Trinity::Singleton > +class MANGOS_DLL_DECL WorldLog : public MaNGOS::Singleton > { friend class Trinity::OperatorNew; WorldLog(); WorldLog(const WorldLog &); WorldLog& operator=(const WorldLog &); - typedef Trinity::ClassLevelLockable::Lock Guard; + typedef MaNGOS::ClassLevelLockable::Lock Guard; /// Close the file in destructor ~WorldLog(); diff --git a/src/game/WorldSession.h b/src/game/WorldSession.h index d514586957a..a8d6db72809 100644 --- a/src/game/WorldSession.h +++ b/src/game/WorldSession.h @@ -719,8 +719,7 @@ class TRINITY_DLL_SPEC WorldSession uint32 m_latency; AccountData m_accountData[NUM_ACCOUNT_DATA_TYPES]; AddonsList m_addonsList; - - ZThread::LockedQueue _recvQueue; + ACE_Based::LockedQueue _recvQueue; }; #endif /// @} diff --git a/src/shared/Common.h b/src/shared/Common.h index 5cbd7f285f6..37ced4c8e11 100644 --- a/src/shared/Common.h +++ b/src/shared/Common.h @@ -84,6 +84,7 @@ #include #include #include +#include #if PLATFORM == PLATFORM_WINDOWS #define STRCASECMP stricmp @@ -99,10 +100,13 @@ #include #include -#include -#include -#include -#include +#include "LockedQueue.h" +#include "Threading.h" + +#include +#include +#include + #if PLATFORM == PLATFORM_WINDOWS # define FD_SETSIZE 4096 diff --git a/src/shared/Database/Database.cpp b/src/shared/Database/Database.cpp index 07ece3b0cd9..783b520ded3 100644 --- a/src/shared/Database/Database.cpp +++ b/src/shared/Database/Database.cpp @@ -110,7 +110,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,...) diff --git a/src/shared/Database/Database.h b/src/shared/Database/Database.h index 92a1c991dcc..a9f7285c223 100644 --- a/src/shared/Database/Database.h +++ b/src/shared/Database/Database.h @@ -21,8 +21,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" @@ -30,8 +29,8 @@ class SqlTransaction; class SqlResultQueue; class SqlQueryHolder; -typedef UNORDERED_MAP TransactionQueues; -typedef UNORDERED_MAP QueryQueues; +typedef UNORDERED_MAP TransactionQueues; +typedef UNORDERED_MAP QueryQueues; #define MAX_QUERY_LEN 32*1024 @@ -43,7 +42,7 @@ class TRINITY_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: diff --git a/src/shared/Database/DatabaseImpl.h b/src/shared/Database/DatabaseImpl.h index 3d3c53f0873..7cbd0ed8ba5 100644 --- a/src/shared/Database/DatabaseImpl.h +++ b/src/shared/Database/DatabaseImpl.h @@ -29,7 +29,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; \ } @@ -59,7 +59,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; \ } diff --git a/src/shared/Database/DatabaseMysql.cpp b/src/shared/Database/DatabaseMysql.cpp index 5dc02c0a738..92b303a167d 100644 --- a/src/shared/Database/DatabaseMysql.cpp +++ b/src/shared/Database/DatabaseMysql.cpp @@ -23,7 +23,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" @@ -203,8 +203,8 @@ QueryResult* DatabaseMysql::Query(const char *sql) { // guarded block for thread-safe mySQL request - ZThread::Guard query_connection_guard(mMutex); - #ifdef TRINITY_DEBUG + ACE_Guard query_connection_guard(mMutex); + #ifdef MANGOS_DEBUG uint32 _s = getMSTime(); #endif if(mysql_query(mMysql, sql)) @@ -251,7 +251,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 @@ -273,8 +273,9 @@ bool DatabaseMysql::DirectExecute(const char* sql) { // guarded block for thread-safe mySQL request - ZThread::Guard query_connection_guard(mMutex); - #ifdef TRINITY_DEBUG + ACE_Guard query_connection_guard(mMutex); + + #ifdef MANGOS_DEBUG uint32 _s = getMSTime(); #endif if(mysql_query(mMysql, sql)) @@ -318,8 +319,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")) { @@ -329,7 +331,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 @@ -349,7 +351,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; @@ -357,7 +359,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) { @@ -377,7 +379,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; @@ -385,7 +387,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) { @@ -408,7 +410,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() diff --git a/src/shared/Database/DatabaseMysql.h b/src/shared/Database/DatabaseMysql.h index 2fa157e75a5..7f5730f9579 100644 --- a/src/shared/Database/DatabaseMysql.h +++ b/src/shared/Database/DatabaseMysql.h @@ -25,7 +25,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 @@ -65,9 +66,9 @@ class TRINITY_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; diff --git a/src/shared/Database/DatabasePostgre.cpp b/src/shared/Database/DatabasePostgre.cpp index 79e1c87f5e3..d4f48b99fb1 100644 --- a/src/shared/Database/DatabasePostgre.cpp +++ b/src/shared/Database/DatabasePostgre.cpp @@ -23,7 +23,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" @@ -126,8 +126,13 @@ QueryResult* DatabasePostgre::Query(const char *sql) uint32 fieldCount = 0; // guarded block for thread-safe request +<<<<<<< HEAD:src/shared/Database/DatabasePostgre.cpp ZThread::Guard query_connection_guard(mMutex); #ifdef TRINITY_DEBUG +======= + ACE_Guard query_connection_guard(mMutex); + #ifdef MANGOS_DEBUG +>>>>>>> 00c7d15a78b1dcdbf888b768c55424183b2231e4:src/shared/Database/DatabasePostgre.cpp uint32 _s = getMSTime(); #endif // Send the query @@ -174,9 +179,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 @@ -197,8 +203,8 @@ bool DatabasePostgre::DirectExecute(const char* sql) return false; { // guarded block for thread-safe request - ZThread::Guard query_connection_guard(mMutex); - #ifdef TRINITY_DEBUG + ACE_Guard query_connection_guard(mMutex); + #ifdef MANGOS_DEBUG uint32 _s = getMSTime(); #endif PGresult *res = PQexec(mPGconn, sql); @@ -247,7 +253,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")) @@ -258,7 +264,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 @@ -278,14 +284,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) { @@ -304,14 +310,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) { @@ -334,7 +340,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() diff --git a/src/shared/Database/DatabasePostgre.h b/src/shared/Database/DatabasePostgre.h index c7242add572..53f0802f86c 100644 --- a/src/shared/Database/DatabasePostgre.h +++ b/src/shared/Database/DatabasePostgre.h @@ -22,7 +22,6 @@ #define _DatabasePostgre_H #include "Policies/Singleton.h" -#include "zthread/FastMutex.h" #include #ifdef WIN32 @@ -63,10 +62,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; diff --git a/src/shared/Database/QueryResult.h b/src/shared/Database/QueryResult.h index 01da45ed281..39228dd4ba9 100644 --- a/src/shared/Database/QueryResult.h +++ b/src/shared/Database/QueryResult.h @@ -40,7 +40,7 @@ class TRINITY_DLL_SPEC QueryResult if(iter->second == name) return iter->first; } - assert(false && "unknown field name"); + ASSERT(false && "unknown field name"); return uint32(-1); } diff --git a/src/shared/Database/SqlDelayThread.cpp b/src/shared/Database/SqlDelayThread.cpp index 27f58510a0a..9a92fd5dd63 100644 --- a/src/shared/Database/SqlDelayThread.cpp +++ b/src/shared/Database/SqlDelayThread.cpp @@ -37,7 +37,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(); diff --git a/src/shared/Database/SqlDelayThread.h b/src/shared/Database/SqlDelayThread.h index cbae0c1e5eb..3c24d3525b7 100644 --- a/src/shared/Database/SqlDelayThread.h +++ b/src/shared/Database/SqlDelayThread.h @@ -21,21 +21,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 SqlQueue; + typedef ACE_Based::LockedQueue 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: diff --git a/src/shared/Database/SqlOperations.h b/src/shared/Database/SqlOperations.h index 61eef4bb7c4..e91d83b6611 100644 --- a/src/shared/Database/SqlOperations.h +++ b/src/shared/Database/SqlOperations.h @@ -23,9 +23,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 #include "Utilities/Callback.h" @@ -72,7 +71,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 +class SqlResultQueue : public ACE_Based::LockedQueue { public: SqlResultQueue() {} diff --git a/src/shared/Log.h b/src/shared/Log.h index 654f3c0f04c..23555995020 100644 --- a/src/shared/Log.h +++ b/src/shared/Log.h @@ -82,7 +82,7 @@ enum ColorTypes const int Colors = int(WHITE)+1; -class Log : public Trinity::Singleton > +class Log : public Trinity::Singleton > { friend class Trinity::OperatorNew; Log(); diff --git a/src/shared/Makefile.am b/src/shared/Makefile.am index 6b99351cb26..60af5b8a4b5 100644 --- a/src/shared/Makefile.am +++ b/src/shared/Makefile.am @@ -38,6 +38,7 @@ libmangosshared_a_SOURCES = \ Common.cpp \ Common.h \ Errors.h \ + LockedQueue.h \ Log.cpp \ Log.h \ MemoryLeaks.cpp \ @@ -45,6 +46,8 @@ libmangosshared_a_SOURCES = \ ProgressBar.cpp \ ProgressBar.h \ Timer.h \ + Threading.cpp \ + Threading.h \ Util.cpp \ Util.h \ WorldPacket.h \ diff --git a/src/shared/Util.cpp b/src/shared/Util.cpp index 767b65e441c..ac57fc3c9e9 100644 --- a/src/shared/Util.cpp +++ b/src/shared/Util.cpp @@ -23,40 +23,34 @@ #include "sockets/socket_include.h" #include "utf8cpp/utf8.h" #include "mersennetwister/MersenneTwister.h" -#include "zthread/ThreadLocal.h" +#include -typedef ZThread::ThreadLocal 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 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) diff --git a/src/trinitycore/CliRunnable.cpp b/src/trinitycore/CliRunnable.cpp index 91f37cd1b48..d53ee8c24be 100644 --- a/src/trinitycore/CliRunnable.cpp +++ b/src/trinitycore/CliRunnable.cpp @@ -155,7 +155,7 @@ bool ChatHandler::HandleCharacterDeleteCommand(const char* args) } /// Exit the realm -bool ChatHandler::HandleServerExitCommand(const char* args) +bool ChatHandler::HandleServerExitCommand(const char* /*args*/) { SendSysMessage(LANG_COMMAND_EXIT); World::StopNow(SHUTDOWN_EXIT_CODE); @@ -163,7 +163,7 @@ bool ChatHandler::HandleServerExitCommand(const char* args) } /// Display info on users currently in the realm -bool ChatHandler::HandleAccountOnlineListCommand(const char* args) +bool ChatHandler::HandleAccountOnlineListCommand(const char* /*args*/) { ///- Get the list of accounts ID logged to the realm QueryResult *resultDB = CharacterDatabase.Query("SELECT name,account FROM characters WHERE online > 0"); diff --git a/src/trinitycore/CliRunnable.h b/src/trinitycore/CliRunnable.h index 20ff58f27ba..cf745bbb195 100644 --- a/src/trinitycore/CliRunnable.h +++ b/src/trinitycore/CliRunnable.h @@ -26,7 +26,7 @@ #define __CLIRUNNABLE_H /// Command Line Interface handling thread -class CliRunnable : public ZThread::Runnable +class CliRunnable : public ACE_Based::Runnable { public: void run(); diff --git a/src/trinitycore/Makefile.am b/src/trinitycore/Makefile.am index 7e1cd086d3c..f0ac432dab1 100644 --- a/src/trinitycore/Makefile.am +++ b/src/trinitycore/Makefile.am @@ -35,8 +35,13 @@ trinity_worldd_SOURCES = \ WorldRunnable.h ## Link world daemon against the shared library +<<<<<<< HEAD:src/mangosd/Makefile.am trinity_worldd_LDADD = ../bindings/scripts/libtrinityscript.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 trinity_worldd_LDFLAGS = -L../../dep/src/sockets -L../../dep/src/zthread -L../../dep/src/g3dlite -L../bindings/scripts/ -L$(libdir) $(TRINI_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 +>>>>>>> 00c7d15a78b1dcdbf888b768c55424183b2231e4:src/mangosd/Makefile.am ## Additional files to include when running 'make dist' # Include world daemon configuration diff --git a/src/trinitycore/Master.cpp b/src/trinitycore/Master.cpp index 6a952b936d3..2e2d75d5c3c 100644 --- a/src/trinitycore/Master.cpp +++ b/src/trinitycore/Master.cpp @@ -60,7 +60,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; } @@ -79,7 +79,7 @@ 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); @@ -115,7 +115,7 @@ public: } }; -class RARunnable : public ZThread::Runnable +class RARunnable : public ACE_Based::Runnable { public: uint32 numLoops, loopCounter; @@ -181,7 +181,7 @@ public: { while (!World::IsStopped()) { - ZThread::Thread::sleep (static_cast (socketSelecttime / 1000)); + ACE_Based::Thread::Sleep (static_cast (socketSelecttime / 1000)); checkping (); } } @@ -237,8 +237,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::Priority )2); // set server online LoginDatabase.PExecute("UPDATE realmlist SET color = 0, population = 0 WHERE id = '%d'",realmID); @@ -250,10 +250,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 @@ -314,8 +314,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::High); } ///- Launch the world listener socket diff --git a/src/trinitycore/WorldRunnable.cpp b/src/trinitycore/WorldRunnable.cpp index e49e4ad74b8..bd4d3170c52 100644 --- a/src/trinitycore/WorldRunnable.cpp +++ b/src/trinitycore/WorldRunnable.cpp @@ -76,7 +76,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; diff --git a/src/trinitycore/WorldRunnable.h b/src/trinitycore/WorldRunnable.h index 8df3a6a0c89..07ce246b04f 100644 --- a/src/trinitycore/WorldRunnable.h +++ b/src/trinitycore/WorldRunnable.h @@ -26,7 +26,7 @@ #define __WORLDRUNNABLE_H /// Heartbeat thread for the World -class WorldRunnable : public ZThread::Runnable +class WorldRunnable : public ACE_Based::Runnable { public: void run(); diff --git a/src/trinityrealm/AuthSocket.cpp b/src/trinityrealm/AuthSocket.cpp index c5c81593737..8c9eab653ec 100644 --- a/src/trinityrealm/AuthSocket.cpp +++ b/src/trinityrealm/AuthSocket.cpp @@ -173,7 +173,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 *); @@ -236,7 +236,8 @@ AuthSocket::AuthSocket(ISocketHandler &h) : TcpSocket(h) /// Close patch file descriptor before leaving AuthSocket::~AuthSocket() { - ZThread::Guard g(patcherLock); + ACE_Guard g(patcherLock); + if(pPatch) fclose(pPatch); } @@ -912,7 +913,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; } @@ -924,7 +925,6 @@ bool AuthSocket::_HandleXferCancel() ///- Close and delete the socket ibuf.Remove(1); //clear input buffer - //ZThread::Thread::sleep(15); SetCloseAndDelete(); return true; @@ -946,8 +946,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; } @@ -965,7 +964,8 @@ PatcherRunnable::PatcherRunnable(class AuthSocket * as) /// Send content of patch file to the client void PatcherRunnable::run() { - ZThread::Guard g(mySocket->patcherLock); + ACE_Guard g(mySocket->patcherLock); + XFER_DATA_STRUCT xfdata; xfdata.opcode = XFER_DATA; @@ -974,7 +974,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); diff --git a/src/trinityrealm/AuthSocket.h b/src/trinityrealm/AuthSocket.h index 3cae54c7789..43b880a1e74 100644 --- a/src/trinityrealm/AuthSocket.h +++ b/src/trinityrealm/AuthSocket.h @@ -33,7 +33,6 @@ #include "sockets/Utility.h" #include "sockets/Parse.h" #include "sockets/Socket.h" -#include "zthread/Mutex.h" /// Handle login commands class AuthSocket: public TcpSocket @@ -61,7 +60,7 @@ class AuthSocket: public TcpSocket void _SetVSFields(const std::string& rI); FILE *pPatch; - ZThread::Mutex patcherLock; + ACE_Thread_Mutex patcherLock; bool IsLag(); private: diff --git a/src/trinityrealm/Makefile.am b/src/trinityrealm/Makefile.am index a14b50c847a..197d6ebf8c4 100644 --- a/src/trinityrealm/Makefile.am +++ b/src/trinityrealm/Makefile.am @@ -32,8 +32,13 @@ trinity_realmd_SOURCES = \ RealmList.h ## Link realm list daemon against the shared library +<<<<<<< HEAD:src/realmd/Makefile.am trinity_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 trinity_realmd_LDFLAGS = -L../../dep/src/sockets -L../../dep/src/zthread -L$(libdir) $(TRINI_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) +>>>>>>> 00c7d15a78b1dcdbf888b768c55424183b2231e4:src/realmd/Makefile.am ## Additional files to include when running 'make dist' # Include realm list daemon configuration diff --git a/win/TrinityCore&Script VC71.sln b/win/TrinityCore&Script VC71.sln index 8c4432075b4..2eee999cede 100644 --- a/win/TrinityCore&Script VC71.sln +++ b/win/TrinityCore&Script VC71.sln @@ -14,10 +14,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shared", "VC71\shared.vcpro {DE0380F9-C910-4E99-A841-93550D0E61D7} = {DE0380F9-C910-4E99-A841-93550D0E61D7} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zthread", "VC71\zthread.vcproj", "{262199E8-EEDF-4700-A1D1-E9CC901CF480}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "VC71\zlib.vcproj", "{8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}" ProjectSection(ProjectDependencies) = postProject EndProjectSection diff --git a/win/TrinityCore&Script VC80.sln b/win/TrinityCore&Script VC80.sln index 167b00a4b8b..cb880001dc2 100644 --- a/win/TrinityCore&Script VC80.sln +++ b/win/TrinityCore&Script VC80.sln @@ -23,8 +23,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityCore", "VC80\Trinity {563E9905-3657-460C-AE63-0AC39D162E23} = {563E9905-3657-460C-AE63-0AC39D162E23} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zthread", "VC80\zthread.vcproj", "{262199E8-EEDF-4700-A1D1-E9CC901CF480}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "VC80\zlib.vcproj", "{8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "framework", "VC80\framework.vcproj", "{BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}" diff --git a/win/TrinityCore&Script VC90.sln b/win/TrinityCore&Script VC90.sln index 2904ca6f20a..a81cbfc570e 100644 --- a/win/TrinityCore&Script VC90.sln +++ b/win/TrinityCore&Script VC90.sln @@ -23,8 +23,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityCore", "VC90\Trinity {1DC6C4DA-A028-41F3-877D-D5400C594F88} = {1DC6C4DA-A028-41F3-877D-D5400C594F88} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zthread", "VC90\zthread.vcproj", "{262199E8-EEDF-4700-A1D1-E9CC901CF480}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "VC90\zlib.vcproj", "{8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "framework", "VC90\framework.vcproj", "{BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}" diff --git a/win/VC71/ScriptsInterfaces.vcproj b/win/VC71/ScriptsInterfaces.vcproj index 5d229de138a..813f477dd35 100644 --- a/win/VC71/ScriptsInterfaces.vcproj +++ b/win/VC71/ScriptsInterfaces.vcproj @@ -33,10 +33,17 @@ Name="VCCustomBuildTool"/> >>>>>> 00c7d15a78b1dcdbf888b768c55424183b2231e4:win/VC71/script.vcproj GenerateDebugInformation="TRUE" ProgramDatabaseFile="$(OutDir)/TrinityScript.pdb" SubSystem="2" @@ -83,10 +90,17 @@ Name="VCCustomBuildTool"/> >>>>>> 00c7d15a78b1dcdbf888b768c55424183b2231e4:win/VC71/script.vcproj GenerateDebugInformation="FALSE" SubSystem="2" OptimizeReferences="2" diff --git a/win/VC71/TrinityCore.vcproj b/win/VC71/TrinityCore.vcproj index 1da3ad630dd..df6ab1c709e 100644 --- a/win/VC71/TrinityCore.vcproj +++ b/win/VC71/TrinityCore.vcproj @@ -4,7 +4,7 @@ Version="7.10" Name="TrinityCore" ProjectGUID="{D1EA3EE9-4DCF-4CB9-BA6E-B9321E0D552A}" - RootNamespace="mangosd" + RootNamespace="trinitycore" SccProjectName="" SccLocalPath=""> @@ -58,7 +58,7 @@ ImportLibrary="$(OutDir)\trinitycore.lib"/> + TypeLibraryName=".\trinitycore__$(PlatformName)_$(ConfigurationName)\trinitycore.tlb"/> + TypeLibraryName=".\trinitycore__$(PlatformName)_$(ConfigurationName)\trinitycore.tlb"/> @@ -15,7 +15,7 @@ >>>>>> 00c7d15a78b1dcdbf888b768c55424183b2231e4:win/VC71/TrinityRealm.vcproj LinkIncremental="1" SuppressStartupBanner="TRUE" - AdditionalLibraryDirectories=""..\..\dep\lib\$(PlatformName)_$(ConfigurationName)";".\zthread__$(PlatformName)_$(ConfigurationName)"" + AdditionalLibraryDirectories="..\..\dep\lib\$(PlatformName)_$(ConfigurationName)" GenerateDebugInformation="TRUE" ProgramDatabaseFile="..\..\bin\$(PlatformName)_$(ConfigurationName)\TrinityRealm.pdb" GenerateMapFile="TRUE" @@ -57,7 +62,7 @@ LargeAddressAware="2"/> + TypeLibraryName=".\TrinityRealm__$(PlatformName)_$(ConfigurationName)\TrinityRealm.tlb"/> @@ -83,7 +88,7 @@ >>>>>> 00c7d15a78b1dcdbf888b768c55424183b2231e4:win/VC71/TrinityRealm.vcproj SuppressStartupBanner="TRUE" - AdditionalLibraryDirectories=""..\..\dep\lib\$(PlatformName)_$(ConfigurationName)";".\zthread__$(PlatformName)_$(ConfigurationName)"" + AdditionalLibraryDirectories="..\..\dep\lib\$(PlatformName)_$(ConfigurationName)" GenerateDebugInformation="TRUE" ProgramDatabaseFile="..\..\bin\$(PlatformName)_$(ConfigurationName)\TrinityRealm.pdb" GenerateMapFile="TRUE" @@ -125,7 +136,7 @@ FixedBaseAddress="1"/> + TypeLibraryName=".\TrinityRealm__$(PlatformName)_$(ConfigurationName)\TrinityRealm.tlb"/> diff --git a/win/VC71/shared.vcproj b/win/VC71/shared.vcproj index 2bd75f70231..81da9f674f8 100644 --- a/win/VC71/shared.vcproj +++ b/win/VC71/shared.vcproj @@ -44,6 +44,7 @@ Name="VCLibrarianTool" AdditionalDependencies=".\g3dlite__$(PlatformName)_$(ConfigurationName)\g3dlite.lib" OutputFile=".\shared__$(PlatformName)_$(ConfigurationName)\shared.lib" + AdditionalLibraryDirectories="dep\lib\$(PlatformName)_$(ConfigurationName)" SuppressStartupBanner="TRUE"/> @@ -98,6 +99,7 @@ Name="VCLibrarianTool" AdditionalDependencies=".\g3dlite__$(PlatformName)_$(ConfigurationName)\g3dlite.lib" OutputFile=".\shared__$(PlatformName)_$(ConfigurationName)\shared.lib" + AdditionalLibraryDirectories="dep\lib\$(PlatformName)_$(ConfigurationName)" SuppressStartupBanner="TRUE"/> @@ -374,6 +376,7 @@ +<<<<<<< HEAD:win/VC71/shared.vcproj @@ -399,6 +402,38 @@ Outputs="revision.h" /> +======= + + + + + + + + + + + +>>>>>>> 00c7d15a78b1dcdbf888b768c55424183b2231e4:win/VC71/shared.vcproj @@ -409,6 +444,12 @@ + + + + diff --git a/win/VC71/zthread.vcproj b/win/VC71/zthread.vcproj deleted file mode 100644 index 723c90ed7a5..00000000000 --- a/win/VC71/zthread.vcproj +++ /dev/null @@ -1,381 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/win/VC80/ScriptsInterfaces.vcproj b/win/VC80/ScriptsInterfaces.vcproj index 72c7626138d..d4329a747cc 100644 --- a/win/VC80/ScriptsInterfaces.vcproj +++ b/win/VC80/ScriptsInterfaces.vcproj @@ -65,10 +65,10 @@ /> + + @@ -895,6 +905,14 @@ RelativePath="..\..\src\shared\SystemConfig.h" > + + + + diff --git a/win/VC90/ScriptsInterfaces.vcproj b/win/VC90/ScriptsInterfaces.vcproj index 34ad97341e5..7037cffdf68 100644 --- a/win/VC90/ScriptsInterfaces.vcproj +++ b/win/VC90/ScriptsInterfaces.vcproj @@ -67,10 +67,10 @@ /> @@ -42,7 +42,7 @@ /> @@ -41,20 +41,20 @@ /> + + @@ -926,6 +936,14 @@ RelativePath="..\..\src\shared\SystemConfig.h" > + + + + diff --git a/win/VC90/zthread.vcproj b/win/VC90/zthread.vcproj deleted file mode 100644 index a381daa3198..00000000000 --- a/win/VC90/zthread.vcproj +++ /dev/null @@ -1,799 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3 From 54572864167640fa7ccadb53f6cc607e42f29561 Mon Sep 17 00:00:00 2001 From: megamage Date: Wed, 13 May 2009 18:28:21 -0500 Subject: [7815] Apply mangos code style: Replace tabs by spaces in recent added code. Author: VladimirMangos --HG-- branch : trunk --- src/game/World.h | 4 ++-- src/shared/Database/Database.cpp | 2 +- src/shared/Database/DatabaseMysql.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/shared/Database') diff --git a/src/game/World.h b/src/game/World.h index 80d5717f981..11a83678d35 100644 --- a/src/game/World.h +++ b/src/game/World.h @@ -626,7 +626,7 @@ class World static float m_VisibleObjectGreyDistance; // CLI command holder to be thread safe - ACE_Based::LockedQueue cliCmdQueue; + ACE_Based::LockedQueue cliCmdQueue; SqlResultQueue *m_resultQueue; // next daily quests reset time @@ -637,7 +637,7 @@ class World //sessions that are added async void AddSession_(WorldSession* s); - ACE_Based::LockedQueue addSessQueue; + ACE_Based::LockedQueue addSessQueue; //used versions std::string m_DBVersion; diff --git a/src/shared/Database/Database.cpp b/src/shared/Database/Database.cpp index 783b520ded3..d5ccc581232 100644 --- a/src/shared/Database/Database.cpp +++ b/src/shared/Database/Database.cpp @@ -110,7 +110,7 @@ bool Database::PExecuteLog(const char * format,...) void Database::SetResultQueue(SqlResultQueue * queue) { - m_queryQueues[ACE_Based::Thread::current()] = queue; + m_queryQueues[ACE_Based::Thread::current()] = queue; } diff --git a/src/shared/Database/DatabaseMysql.cpp b/src/shared/Database/DatabaseMysql.cpp index 92b303a167d..9574d3dc2ac 100644 --- a/src/shared/Database/DatabaseMysql.cpp +++ b/src/shared/Database/DatabaseMysql.cpp @@ -351,7 +351,7 @@ bool DatabaseMysql::CommitTransaction() // don't use queued execution if it has not been initialized if (!m_threadBody) { - if (tranThread != ACE_Based::Thread::current()) + if (tranThread != ACE_Based::Thread::current()) return false; bool _res = _TransactionCmd("COMMIT"); tranThread = NULL; -- cgit v1.2.3 From 2ed9222ac9c735211e2c10879c20a41992fd2c8f Mon Sep 17 00:00:00 2001 From: raczman Date: Thu, 14 May 2009 13:25:35 +0200 Subject: Fixed build on linux. Tested on Arch linux, still need someone to fixup .vcproj's for windows. --HG-- branch : trunk --- src/shared/CMakeLists.txt | 5 + src/shared/Database/DatabasePostgre.cpp | 5 - src/shared/LockedQueue.h | 144 ++++++++++++++++++++++ src/shared/Threading.cpp | 205 ++++++++++++++++++++++++++++++++ src/shared/Threading.h | 99 +++++++++++++++ 5 files changed, 453 insertions(+), 5 deletions(-) create mode 100644 src/shared/LockedQueue.h create mode 100644 src/shared/Threading.cpp create mode 100644 src/shared/Threading.h (limited to 'src/shared/Database') diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index 8ecfccad34f..b271e2b9545 100644 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -14,6 +14,7 @@ SET(shared_STAT_SRCS Log.h ProgressBar.cpp ProgressBar.h + Threading.cpp Timer.h Util.cpp Util.h @@ -22,3 +23,7 @@ SET(shared_STAT_SRCS ) add_library(shared STATIC ${shared_STAT_SRCS}) +target_link_libraries( +shared +${ACE_LIBRARY} +) diff --git a/src/shared/Database/DatabasePostgre.cpp b/src/shared/Database/DatabasePostgre.cpp index d4f48b99fb1..12875b33200 100644 --- a/src/shared/Database/DatabasePostgre.cpp +++ b/src/shared/Database/DatabasePostgre.cpp @@ -126,13 +126,8 @@ QueryResult* DatabasePostgre::Query(const char *sql) uint32 fieldCount = 0; // guarded block for thread-safe request -<<<<<<< HEAD:src/shared/Database/DatabasePostgre.cpp - ZThread::Guard query_connection_guard(mMutex); - #ifdef TRINITY_DEBUG -======= ACE_Guard query_connection_guard(mMutex); #ifdef MANGOS_DEBUG ->>>>>>> 00c7d15a78b1dcdbf888b768c55424183b2231e4:src/shared/Database/DatabasePostgre.cpp uint32 _s = getMSTime(); #endif // Send the query diff --git a/src/shared/LockedQueue.h b/src/shared/LockedQueue.h new file mode 100644 index 00000000000..b085dd09b83 --- /dev/null +++ b/src/shared/LockedQueue.h @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2009 MaNGOS + * + * 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 +#include +#include +#include +#include "Errors.h" + +namespace ACE_Based +{ + + template > + 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 g(_lock); + + ASSERT(!_canceled); + // throw Cancellation_Exception(); + + _queue.push_back(item); + + } + + /** + * @see Queue::next() + */ + T next() + { + + ACE_Guard g(_lock); + + ASSERT (!_queue.empty() || !_canceled); + // throw Cancellation_Exception(); + + T item = _queue.front(); + _queue.pop_front(); + + return item; + + } + + T front() + { + ACE_Guard g(_lock); + + ASSERT (!_queue.empty()); + // throw NoSuchElement_Exception(); + + return _queue.front(); + } + + /** + * @see Queue::cancel() + */ + void cancel() + { + + ACE_Guard 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 g(_lock); + + return _canceled; + + } + + /** + * @see Queue::size() + */ + size_t size() + { + + ACE_Guard g(_lock); + return _queue.size(); + + } + + bool empty() + { + + ACE_Guard g(_lock); + return _queue.empty(); + } + + }; + +} +#endif diff --git a/src/shared/Threading.cpp b/src/shared/Threading.cpp new file mode 100644 index 00000000000..496e86353ca --- /dev/null +++ b/src/shared/Threading.cpp @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2009 MaNGOS + * + * 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 +#include +#include + +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 _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 ¹ 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)); +} diff --git a/src/shared/Threading.h b/src/shared/Threading.h new file mode 100644 index 00000000000..eac3c0e8efb --- /dev/null +++ b/src/shared/Threading.h @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2009 MaNGOS + * + * 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 +#include +#include +#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 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 -- cgit v1.2.3