mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
Merge pull request #135 from ElunaLuaEngine/mutexlock
Eluna add mutex lock for hook calls Needed for packet hooks. Packet hooks will get some changes soon.
This commit is contained in:
@@ -26,6 +26,7 @@ LuaEvent::~LuaEvent()
|
|||||||
|
|
||||||
void LuaEvent::Execute()
|
void LuaEvent::Execute()
|
||||||
{
|
{
|
||||||
|
ELUNA_LOCK(*events->E);
|
||||||
// In multithread get map from object and the map's lua state
|
// In multithread get map from object and the map's lua state
|
||||||
lua_rawgeti((*events->E)->L, LUA_REGISTRYINDEX, funcRef);
|
lua_rawgeti((*events->E)->L, LUA_REGISTRYINDEX, funcRef);
|
||||||
Eluna::Push((*events->E)->L, funcRef);
|
Eluna::Push((*events->E)->L, funcRef);
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ using namespace HookMgr;
|
|||||||
#define EVENT_BEGIN(BINDMAP, EVENT, RET) \
|
#define EVENT_BEGIN(BINDMAP, EVENT, RET) \
|
||||||
if (!BINDMAP->HasEvents(EVENT)) \
|
if (!BINDMAP->HasEvents(EVENT)) \
|
||||||
RET; \
|
RET; \
|
||||||
|
ELUNA_LOCK(this); \
|
||||||
const char* _LuaBindType = this->BINDMAP->groupName; \
|
const char* _LuaBindType = this->BINDMAP->groupName; \
|
||||||
uint32 _LuaEvent = EVENT; \
|
uint32 _LuaEvent = EVENT; \
|
||||||
int _LuaStackTop = lua_gettop(L); \
|
int _LuaStackTop = lua_gettop(L); \
|
||||||
@@ -78,6 +79,7 @@ using namespace HookMgr;
|
|||||||
#define ENTRY_BEGIN(BINDMAP, ENTRY, EVENT, RET) \
|
#define ENTRY_BEGIN(BINDMAP, ENTRY, EVENT, RET) \
|
||||||
if (!BINDMAP->HasEvents(ENTRY, EVENT)) \
|
if (!BINDMAP->HasEvents(ENTRY, EVENT)) \
|
||||||
RET; \
|
RET; \
|
||||||
|
ELUNA_LOCK(this); \
|
||||||
const char* _LuaBindType = this->BINDMAP->groupName; \
|
const char* _LuaBindType = this->BINDMAP->groupName; \
|
||||||
uint32 _LuaEvent = EVENT; \
|
uint32 _LuaEvent = EVENT; \
|
||||||
int _LuaStackTop = lua_gettop(L); \
|
int _LuaStackTop = lua_gettop(L); \
|
||||||
|
|||||||
11
LuaEngine.h
11
LuaEngine.h
@@ -116,6 +116,16 @@ public:
|
|||||||
static bool reload;
|
static bool reload;
|
||||||
static bool initialized;
|
static bool initialized;
|
||||||
|
|
||||||
|
#ifdef TRINITY
|
||||||
|
typedef std::recursive_mutex LockType;
|
||||||
|
typedef std::lock_guard<LockType> ElunaGuard;
|
||||||
|
#else
|
||||||
|
typedef ACE_Recursive_Thread_Mutex LockType;
|
||||||
|
typedef ACE_Guard<LockType> ElunaGuard;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
LockType elunaLock;
|
||||||
|
|
||||||
lua_State* L;
|
lua_State* L;
|
||||||
uint32 event_level;
|
uint32 event_level;
|
||||||
|
|
||||||
@@ -391,4 +401,5 @@ template<> WorldObject* Eluna::CHECKOBJ<WorldObject>(lua_State* L, int narg, boo
|
|||||||
template<> ElunaObject* Eluna::CHECKOBJ<ElunaObject>(lua_State* L, int narg, bool error);
|
template<> ElunaObject* Eluna::CHECKOBJ<ElunaObject>(lua_State* L, int narg, bool error);
|
||||||
|
|
||||||
#define sEluna Eluna::GEluna
|
#define sEluna Eluna::GEluna
|
||||||
|
#define ELUNA_LOCK(E) Eluna::ElunaGuard elunaGuard((E)->elunaLock);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user