From 092c61c20babe4b1fc748379a38117c808c4a16f Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sat, 3 Jan 2015 22:20:30 +0200 Subject: [PATCH] Eluna add mutex lock for hook calls --- ElunaEventMgr.cpp | 1 + HookMgr.cpp | 2 ++ LuaEngine.h | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/ElunaEventMgr.cpp b/ElunaEventMgr.cpp index 9570f26..48c4ca3 100644 --- a/ElunaEventMgr.cpp +++ b/ElunaEventMgr.cpp @@ -26,6 +26,7 @@ LuaEvent::~LuaEvent() void LuaEvent::Execute() { + ELUNA_LOCK(*events->E); // In multithread get map from object and the map's lua state lua_rawgeti((*events->E)->L, LUA_REGISTRYINDEX, funcRef); Eluna::Push((*events->E)->L, funcRef); diff --git a/HookMgr.cpp b/HookMgr.cpp index e405e8d..92371be 100644 --- a/HookMgr.cpp +++ b/HookMgr.cpp @@ -46,6 +46,7 @@ using namespace HookMgr; #define EVENT_BEGIN(BINDMAP, EVENT, RET) \ if (!BINDMAP->HasEvents(EVENT)) \ RET; \ + ELUNA_LOCK(this); \ const char* _LuaBindType = this->BINDMAP->groupName; \ uint32 _LuaEvent = EVENT; \ int _LuaStackTop = lua_gettop(L); \ @@ -78,6 +79,7 @@ using namespace HookMgr; #define ENTRY_BEGIN(BINDMAP, ENTRY, EVENT, RET) \ if (!BINDMAP->HasEvents(ENTRY, EVENT)) \ RET; \ + ELUNA_LOCK(this); \ const char* _LuaBindType = this->BINDMAP->groupName; \ uint32 _LuaEvent = EVENT; \ int _LuaStackTop = lua_gettop(L); \ diff --git a/LuaEngine.h b/LuaEngine.h index fe8555d..77d40d7 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -116,6 +116,16 @@ public: static bool reload; static bool initialized; +#ifdef TRINITY + typedef std::recursive_mutex LockType; + typedef std::lock_guard ElunaGuard; +#else + typedef ACE_Recursive_Thread_Mutex LockType; + typedef ACE_Guard ElunaGuard; +#endif + + LockType elunaLock; + lua_State* L; uint32 event_level; @@ -391,4 +401,5 @@ template<> WorldObject* Eluna::CHECKOBJ(lua_State* L, int narg, boo template<> ElunaObject* Eluna::CHECKOBJ(lua_State* L, int narg, bool error); #define sEluna Eluna::GEluna +#define ELUNA_LOCK(E) Eluna::ElunaGuard elunaGuard((E)->elunaLock); #endif