diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/Common.h | 12 | ||||
-rw-r--r-- | src/shared/Database/Database.cpp | 3 | ||||
-rw-r--r-- | src/shared/Database/Database.h | 9 | ||||
-rw-r--r-- | src/shared/Database/DatabaseImpl.h | 4 | ||||
-rw-r--r-- | src/shared/Database/DatabaseMysql.cpp | 29 | ||||
-rw-r--r-- | src/shared/Database/DatabaseMysql.h | 7 | ||||
-rw-r--r-- | src/shared/Database/DatabasePostgre.cpp | 31 | ||||
-rw-r--r-- | src/shared/Database/DatabasePostgre.h | 7 | ||||
-rw-r--r-- | src/shared/Database/QueryResult.h | 2 | ||||
-rw-r--r-- | src/shared/Database/SqlDelayThread.cpp | 2 | ||||
-rw-r--r-- | src/shared/Database/SqlDelayThread.h | 15 | ||||
-rw-r--r-- | src/shared/Database/SqlOperations.h | 7 | ||||
-rw-r--r-- | src/shared/Log.h | 2 | ||||
-rw-r--r-- | src/shared/Makefile.am | 3 | ||||
-rw-r--r-- | src/shared/Util.cpp | 20 |
15 files changed, 81 insertions, 72 deletions
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 <math.h> #include <errno.h> #include <signal.h> +#include <assert.h> #if PLATFORM == PLATFORM_WINDOWS #define STRCASECMP stricmp @@ -99,10 +100,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 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<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 @@ -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<ZThread::FastMutex> query_connection_guard(mMutex); - #ifdef TRINITY_DEBUG + ACE_Guard<ACE_Thread_Mutex> 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<ZThread::FastMutex> query_connection_guard(mMutex); - #ifdef TRINITY_DEBUG + ACE_Guard<ACE_Thread_Mutex> 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<ZThread::FastMutex> query_connection_guard(mMutex); #ifdef TRINITY_DEBUG +======= + ACE_Guard<ACE_Thread_Mutex> 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<ZThread::FastMutex> query_connection_guard(mMutex); - #ifdef TRINITY_DEBUG + ACE_Guard<ACE_Thread_Mutex> 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 <stdarg.h> #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<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: 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 <queue> #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<Trinity::IQueryCallback*, ZThread::FastMutex> +class SqlResultQueue : public ACE_Based::LockedQueue<MaNGOS::IQueryCallback* , ACE_Thread_Mutex> { 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<Log, Trinity::ClassLevelLockable<Log, ZThread::FastMutex> > +class Log : public Trinity::Singleton<Log, Trinity::ClassLevelLockable<Log, ACE_Thread_Mutex> > { friend class Trinity::OperatorNew<Log>; 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 <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) |