mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
Remove ACE and boost RW mutex requirements
This commit is contained in:
14
BindingMap.h
14
BindingMap.h
@@ -23,7 +23,7 @@ extern "C"
|
|||||||
* A set of bindings from keys of type `K` to Lua references.
|
* A set of bindings from keys of type `K` to Lua references.
|
||||||
*/
|
*/
|
||||||
template<typename K>
|
template<typename K>
|
||||||
class BindingMap : public ElunaUtil::RWLockable
|
class BindingMap : public ElunaUtil::Lockable
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
lua_State* L;
|
lua_State* L;
|
||||||
@@ -78,7 +78,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
uint64 Insert(const K& key, int ref, uint32 shots)
|
uint64 Insert(const K& key, int ref, uint32 shots)
|
||||||
{
|
{
|
||||||
WriteGuard guard(GetLock());
|
Guard guard(GetLock());
|
||||||
|
|
||||||
uint64 id = (++maxBindingID);
|
uint64 id = (++maxBindingID);
|
||||||
BindingList& list = bindings[key];
|
BindingList& list = bindings[key];
|
||||||
@@ -92,7 +92,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void Clear(const K& key)
|
void Clear(const K& key)
|
||||||
{
|
{
|
||||||
WriteGuard guard(GetLock());
|
Guard guard(GetLock());
|
||||||
|
|
||||||
if (bindings.empty())
|
if (bindings.empty())
|
||||||
return;
|
return;
|
||||||
@@ -118,7 +118,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
WriteGuard guard(GetLock());
|
Guard guard(GetLock());
|
||||||
|
|
||||||
if (bindings.empty())
|
if (bindings.empty())
|
||||||
return;
|
return;
|
||||||
@@ -134,7 +134,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void Remove(uint64 id)
|
void Remove(uint64 id)
|
||||||
{
|
{
|
||||||
WriteGuard guard(GetLock());
|
Guard guard(GetLock());
|
||||||
|
|
||||||
auto iter = id_lookup_table.find(id);
|
auto iter = id_lookup_table.find(id);
|
||||||
if (iter == id_lookup_table.end())
|
if (iter == id_lookup_table.end())
|
||||||
@@ -163,7 +163,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool HasBindingsFor(const K& key)
|
bool HasBindingsFor(const K& key)
|
||||||
{
|
{
|
||||||
ReadGuard guard(GetLock());
|
Guard guard(GetLock());
|
||||||
|
|
||||||
if (bindings.empty())
|
if (bindings.empty())
|
||||||
return false;
|
return false;
|
||||||
@@ -181,7 +181,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void PushRefsFor(const K& key)
|
void PushRefsFor(const K& key)
|
||||||
{
|
{
|
||||||
WriteGuard guard(GetLock());
|
Guard guard(GetLock());
|
||||||
|
|
||||||
if (bindings.empty())
|
if (bindings.empty())
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ ElunaEventProcessor::ElunaEventProcessor(Eluna** _E, WorldObject* _obj) : m_time
|
|||||||
{
|
{
|
||||||
if (obj)
|
if (obj)
|
||||||
{
|
{
|
||||||
EventMgr::WriteGuard guard((*E)->eventMgr->GetLock());
|
EventMgr::Guard guard((*E)->eventMgr->GetLock());
|
||||||
(*E)->eventMgr->processors.insert(this);
|
(*E)->eventMgr->processors.insert(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ ElunaEventProcessor::~ElunaEventProcessor()
|
|||||||
|
|
||||||
if (obj && Eluna::IsInitialized())
|
if (obj && Eluna::IsInitialized())
|
||||||
{
|
{
|
||||||
EventMgr::WriteGuard guard((*E)->eventMgr->GetLock());
|
EventMgr::Guard guard((*E)->eventMgr->GetLock());
|
||||||
(*E)->eventMgr->processors.erase(this);
|
(*E)->eventMgr->processors.erase(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,7 +124,7 @@ EventMgr::EventMgr(Eluna** _E) : globalProcessor(new ElunaEventProcessor(_E, NUL
|
|||||||
EventMgr::~EventMgr()
|
EventMgr::~EventMgr()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
ReadGuard guard(GetLock());
|
Guard guard(GetLock());
|
||||||
if (!processors.empty())
|
if (!processors.empty())
|
||||||
for (ProcessorSet::const_iterator it = processors.begin(); it != processors.end(); ++it) // loop processors
|
for (ProcessorSet::const_iterator it = processors.begin(); it != processors.end(); ++it) // loop processors
|
||||||
(*it)->RemoveEvents_internal();
|
(*it)->RemoveEvents_internal();
|
||||||
@@ -136,7 +136,7 @@ EventMgr::~EventMgr()
|
|||||||
|
|
||||||
void EventMgr::SetStates(LuaEventState state)
|
void EventMgr::SetStates(LuaEventState state)
|
||||||
{
|
{
|
||||||
ReadGuard guard(GetLock());
|
Guard guard(GetLock());
|
||||||
if (!processors.empty())
|
if (!processors.empty())
|
||||||
for (ProcessorSet::const_iterator it = processors.begin(); it != processors.end(); ++it) // loop processors
|
for (ProcessorSet::const_iterator it = processors.begin(); it != processors.end(); ++it) // loop processors
|
||||||
(*it)->SetStates(state);
|
(*it)->SetStates(state);
|
||||||
@@ -145,7 +145,7 @@ void EventMgr::SetStates(LuaEventState state)
|
|||||||
|
|
||||||
void EventMgr::SetState(int eventId, LuaEventState state)
|
void EventMgr::SetState(int eventId, LuaEventState state)
|
||||||
{
|
{
|
||||||
ReadGuard guard(GetLock());
|
Guard guard(GetLock());
|
||||||
if (!processors.empty())
|
if (!processors.empty())
|
||||||
for (ProcessorSet::const_iterator it = processors.begin(); it != processors.end(); ++it) // loop processors
|
for (ProcessorSet::const_iterator it = processors.begin(); it != processors.end(); ++it) // loop processors
|
||||||
(*it)->SetState(eventId, state);
|
(*it)->SetState(eventId, state);
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ private:
|
|||||||
Eluna** E;
|
Eluna** E;
|
||||||
};
|
};
|
||||||
|
|
||||||
class EventMgr : public ElunaUtil::RWLockable
|
class EventMgr : public ElunaUtil::Lockable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::unordered_set<ElunaEventProcessor*> ProcessorSet;
|
typedef std::unordered_set<ElunaEventProcessor*> ProcessorSet;
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
#include <mutex>
|
||||||
|
#include <memory>
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "SharedDefines.h"
|
#include "SharedDefines.h"
|
||||||
#include "ObjectGuid.h"
|
#include "ObjectGuid.h"
|
||||||
@@ -21,20 +23,6 @@
|
|||||||
#include "Database/QueryResult.h"
|
#include "Database/QueryResult.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Some dummy includes containing BOOST_VERSION:
|
|
||||||
// ObjectAccessor.h Config.h Log.h
|
|
||||||
#ifndef MANGOS
|
|
||||||
#define USING_BOOST
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USING_BOOST
|
|
||||||
#include <boost/thread/locks.hpp>
|
|
||||||
#include <boost/thread/shared_mutex.hpp>
|
|
||||||
#else
|
|
||||||
#include <ace/RW_Thread_Mutex.h>
|
|
||||||
#include <ace/Guard_T.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef TRINITY
|
#ifdef TRINITY
|
||||||
typedef QueryResult ElunaQuery;
|
typedef QueryResult ElunaQuery;
|
||||||
#define ELUNA_LOG_INFO(...) TC_LOG_INFO("eluna", __VA_ARGS__);
|
#define ELUNA_LOG_INFO(...) TC_LOG_INFO("eluna", __VA_ARGS__);
|
||||||
@@ -133,25 +121,15 @@ namespace ElunaUtil
|
|||||||
/*
|
/*
|
||||||
* Usage:
|
* Usage:
|
||||||
* Inherit this class, then when needing lock, use
|
* Inherit this class, then when needing lock, use
|
||||||
* ReadGuard guard(GetLock());
|
* Guard guard(GetLock());
|
||||||
* or
|
|
||||||
* WriteGuard guard(GetLock());
|
|
||||||
*
|
*
|
||||||
* The lock is automatically released at end of scope
|
* The lock is automatically released at end of scope
|
||||||
*/
|
*/
|
||||||
class RWLockable
|
class Lockable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
typedef std::mutex LockType;
|
||||||
#ifdef USING_BOOST
|
typedef std::lock_guard<LockType> Guard;
|
||||||
typedef boost::shared_mutex LockType;
|
|
||||||
typedef boost::shared_lock<LockType> ReadGuard;
|
|
||||||
typedef boost::unique_lock<LockType> WriteGuard;
|
|
||||||
#else
|
|
||||||
typedef ACE_RW_Thread_Mutex LockType;
|
|
||||||
typedef ACE_Read_Guard<LockType> ReadGuard;
|
|
||||||
typedef ACE_Write_Guard<LockType> WriteGuard;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
LockType& GetLock() { return _lock; }
|
LockType& GetLock() { return _lock; }
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,12 @@
|
|||||||
#include "ElunaCreatureAI.h"
|
#include "ElunaCreatureAI.h"
|
||||||
#include "ElunaInstanceAI.h"
|
#include "ElunaInstanceAI.h"
|
||||||
|
|
||||||
|
// Some dummy includes containing BOOST_VERSION:
|
||||||
|
// ObjectAccessor.h Config.h Log.h
|
||||||
|
#ifndef MANGOS
|
||||||
|
#define USING_BOOST
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USING_BOOST
|
#ifdef USING_BOOST
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#else
|
#else
|
||||||
|
|||||||
Reference in New Issue
Block a user