diff --git a/BindingMap.h b/BindingMap.h index 1bc0ce7..d406c81 100644 --- a/BindingMap.h +++ b/BindingMap.h @@ -23,7 +23,7 @@ extern "C" * A set of bindings from keys of type `K` to Lua references. */ template -class BindingMap : public ElunaUtil::RWLockable +class BindingMap : public ElunaUtil::Lockable { private: lua_State* L; @@ -78,7 +78,7 @@ public: */ uint64 Insert(const K& key, int ref, uint32 shots) { - WriteGuard guard(GetLock()); + Guard guard(GetLock()); uint64 id = (++maxBindingID); BindingList& list = bindings[key]; @@ -92,7 +92,7 @@ public: */ void Clear(const K& key) { - WriteGuard guard(GetLock()); + Guard guard(GetLock()); if (bindings.empty()) return; @@ -118,7 +118,7 @@ public: */ void Clear() { - WriteGuard guard(GetLock()); + Guard guard(GetLock()); if (bindings.empty()) return; @@ -134,7 +134,7 @@ public: */ void Remove(uint64 id) { - WriteGuard guard(GetLock()); + Guard guard(GetLock()); auto iter = id_lookup_table.find(id); if (iter == id_lookup_table.end()) @@ -163,7 +163,7 @@ public: */ bool HasBindingsFor(const K& key) { - ReadGuard guard(GetLock()); + Guard guard(GetLock()); if (bindings.empty()) return false; @@ -181,7 +181,7 @@ public: */ void PushRefsFor(const K& key) { - WriteGuard guard(GetLock()); + Guard guard(GetLock()); if (bindings.empty()) return; diff --git a/ElunaEventMgr.cpp b/ElunaEventMgr.cpp index 91b7c39..dd42fa5 100644 --- a/ElunaEventMgr.cpp +++ b/ElunaEventMgr.cpp @@ -18,7 +18,7 @@ ElunaEventProcessor::ElunaEventProcessor(Eluna** _E, WorldObject* _obj) : m_time { if (obj) { - EventMgr::WriteGuard guard((*E)->eventMgr->GetLock()); + EventMgr::Guard guard((*E)->eventMgr->GetLock()); (*E)->eventMgr->processors.insert(this); } } @@ -29,7 +29,7 @@ ElunaEventProcessor::~ElunaEventProcessor() if (obj && Eluna::IsInitialized()) { - EventMgr::WriteGuard guard((*E)->eventMgr->GetLock()); + EventMgr::Guard guard((*E)->eventMgr->GetLock()); (*E)->eventMgr->processors.erase(this); } } @@ -124,7 +124,7 @@ EventMgr::EventMgr(Eluna** _E) : globalProcessor(new ElunaEventProcessor(_E, NUL EventMgr::~EventMgr() { { - ReadGuard guard(GetLock()); + Guard guard(GetLock()); if (!processors.empty()) for (ProcessorSet::const_iterator it = processors.begin(); it != processors.end(); ++it) // loop processors (*it)->RemoveEvents_internal(); @@ -136,7 +136,7 @@ EventMgr::~EventMgr() void EventMgr::SetStates(LuaEventState state) { - ReadGuard guard(GetLock()); + Guard guard(GetLock()); if (!processors.empty()) for (ProcessorSet::const_iterator it = processors.begin(); it != processors.end(); ++it) // loop processors (*it)->SetStates(state); @@ -145,7 +145,7 @@ void EventMgr::SetStates(LuaEventState state) void EventMgr::SetState(int eventId, LuaEventState state) { - ReadGuard guard(GetLock()); + Guard guard(GetLock()); if (!processors.empty()) for (ProcessorSet::const_iterator it = processors.begin(); it != processors.end(); ++it) // loop processors (*it)->SetState(eventId, state); diff --git a/ElunaEventMgr.h b/ElunaEventMgr.h index d77c157..354144a 100644 --- a/ElunaEventMgr.h +++ b/ElunaEventMgr.h @@ -77,7 +77,7 @@ private: Eluna** E; }; -class EventMgr : public ElunaUtil::RWLockable +class EventMgr : public ElunaUtil::Lockable { public: typedef std::unordered_set ProcessorSet; diff --git a/ElunaUtility.h b/ElunaUtility.h index a98d333..c651580 100644 --- a/ElunaUtility.h +++ b/ElunaUtility.h @@ -9,6 +9,8 @@ #include #include +#include +#include #include "Common.h" #include "SharedDefines.h" #include "ObjectGuid.h" @@ -21,20 +23,6 @@ #include "Database/QueryResult.h" #endif -// Some dummy includes containing BOOST_VERSION: -// ObjectAccessor.h Config.h Log.h -#ifndef MANGOS -#define USING_BOOST -#endif - -#ifdef USING_BOOST -#include -#include -#else -#include -#include -#endif - #ifdef TRINITY typedef QueryResult ElunaQuery; #define ELUNA_LOG_INFO(...) TC_LOG_INFO("eluna", __VA_ARGS__); @@ -133,25 +121,15 @@ namespace ElunaUtil /* * Usage: * Inherit this class, then when needing lock, use - * ReadGuard guard(GetLock()); - * or - * WriteGuard guard(GetLock()); + * Guard guard(GetLock()); * * The lock is automatically released at end of scope */ - class RWLockable + class Lockable { public: - -#ifdef USING_BOOST - typedef boost::shared_mutex LockType; - typedef boost::shared_lock ReadGuard; - typedef boost::unique_lock WriteGuard; -#else - typedef ACE_RW_Thread_Mutex LockType; - typedef ACE_Read_Guard ReadGuard; - typedef ACE_Write_Guard WriteGuard; -#endif + typedef std::mutex LockType; + typedef std::lock_guard Guard; LockType& GetLock() { return _lock; } diff --git a/LuaEngine.cpp b/LuaEngine.cpp index e639b70..97dd49e 100644 --- a/LuaEngine.cpp +++ b/LuaEngine.cpp @@ -14,6 +14,12 @@ #include "ElunaCreatureAI.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 #include #else