Eluna add mutex lock for hook calls

This commit is contained in:
Rochet2
2015-01-03 22:20:30 +02:00
parent 5bf5b11c6f
commit 092c61c20b
3 changed files with 14 additions and 0 deletions

View File

@@ -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);

View File

@@ -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); \

View File

@@ -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