Merge commit 'origin/master' into 310

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

View file

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

View file

@ -19,8 +19,7 @@
#ifndef DATABASE_H
#define DATABASE_H
#include "zthread/Thread.h"
#include "../src/zthread/ThreadImpl.h"
#include "Threading.h"
#include "Utilities/UnorderedMap.h"
#include "Database/SqlDelayThread.h"
@ -28,8 +27,8 @@ class SqlTransaction;
class SqlResultQueue;
class SqlQueryHolder;
typedef UNORDERED_MAP<ZThread::ThreadImpl*, SqlTransaction*> TransactionQueues;
typedef UNORDERED_MAP<ZThread::ThreadImpl*, SqlResultQueue*> QueryQueues;
typedef UNORDERED_MAP<ACE_Based::Thread* , SqlTransaction*> TransactionQueues;
typedef UNORDERED_MAP<ACE_Based::Thread* , SqlResultQueue*> QueryQueues;
#define MAX_QUERY_LEN 32*1024
@ -41,7 +40,7 @@ class MANGOS_DLL_SPEC Database
TransactionQueues m_tranQueues; ///< Transaction queues from diff. threads
QueryQueues m_queryQueues; ///< Query queues from diff threads
SqlDelayThread* m_threadBody; ///< Pointer to delay sql executer
ZThread::Thread* m_delayThread; ///< Pointer to executer thread
ACE_Based::Thread* m_delayThread; ///< Pointer to executer thread
public:

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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