[7810] Moved ZThread related code on ACE framework. Author: Ambal

Remove ZThread source code from mangos.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-05-13 18:22:21 -05:00
parent 9dd5a1c6d7
commit 25e5c99dec
60 changed files with 489 additions and 1669 deletions
+8 -4
View File
@@ -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
+2 -1
View File
@@ -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,...)
+4 -5
View File
@@ -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:
+2 -2
View File
@@ -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; \
}
+16 -13
View File
@@ -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()
+4 -3
View File
@@ -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;
+19 -12
View File
@@ -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()
+2 -5
View File
@@ -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;
+1 -1
View File
@@ -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);
}
+1 -1
View File
@@ -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();
+8 -7
View File
@@ -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:
+3 -4
View File
@@ -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() {}
+1 -1
View File
@@ -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();
+3
View File
@@ -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 \
+7 -13
View File
@@ -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)