mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
Eluna add mutex lock for hook calls
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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); \
|
||||
|
||||
11
LuaEngine.h
11
LuaEngine.h
@@ -116,6 +116,16 @@ public:
|
||||
static bool reload;
|
||||
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;
|
||||
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);
|
||||
|
||||
#define sEluna Eluna::GEluna
|
||||
#define ELUNA_LOCK(E) Eluna::ElunaGuard elunaGuard((E)->elunaLock);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user