From e2f81b7336337b110483b28ba5cd7ae10b0de71c Mon Sep 17 00:00:00 2001 From: Patman64 Date: Mon, 5 Jan 2015 22:20:52 -0500 Subject: [PATCH] Make the Eluna mutex static. It was previously unsafe to reload Eluna because it had to be reloaded with the mutex unlocked. This is because the mutex's lifespan was shorter than the Eluna instance it was guarding. --- HookMgr.cpp | 2 +- LuaEngine.cpp | 1 + LuaEngine.h | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/HookMgr.cpp b/HookMgr.cpp index 288736a..fe837d5 100644 --- a/HookMgr.cpp +++ b/HookMgr.cpp @@ -463,13 +463,13 @@ void Eluna::OnShutdownCancel() void Eluna::OnWorldUpdate(uint32 diff) { + ELUNA_LOCK(this); if (reload) { ReloadEluna(); return; } - ELUNA_LOCK(this); eventMgr->globalProcessor->Update(diff); Push(diff); diff --git a/LuaEngine.cpp b/LuaEngine.cpp index 036bcb4..f1ec9c9 100644 --- a/LuaEngine.cpp +++ b/LuaEngine.cpp @@ -36,6 +36,7 @@ std::string Eluna::lua_requirepath; Eluna* Eluna::GEluna = NULL; bool Eluna::reload = false; bool Eluna::initialized = false; +Eluna::LockType Eluna::lock; extern void RegisterFunctions(Eluna* E); diff --git a/LuaEngine.h b/LuaEngine.h index b7b23b0..f9e603b 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -159,10 +159,10 @@ public: typedef std::lock_guard ElunaGuard; #else typedef ACE_Recursive_Thread_Mutex LockType; - typedef ACE_Guard ElunaGuard; + typedef ACE_Guard Guard; #endif - LockType elunaLock; + static LockType lock; lua_State* L; uint32 event_level; @@ -459,5 +459,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); +#define ELUNA_LOCK(E) Eluna::Guard __guard(Eluna::lock); #endif