mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
Eluna reimplement lock and improve hook handling
This commit is contained in:
2746
HookMgr.cpp
2746
HookMgr.cpp
File diff suppressed because it is too large
Load Diff
@@ -456,7 +456,7 @@ public:
|
|||||||
#ifdef MANGOS
|
#ifdef MANGOS
|
||||||
#define sHookMgr (&MaNGOS::Singleton<HookMgr>::Instance())
|
#define sHookMgr (&MaNGOS::Singleton<HookMgr>::Instance())
|
||||||
#else
|
#else
|
||||||
#define sHookMgr ACE_Singleton<HookMgr, ACE_Thread_Mutex>::instance()
|
#define sHookMgr ACE_Singleton<HookMgr, ACE_Null_Mutex>::instance()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -750,15 +750,19 @@ void Eluna::EventBind::Insert(int eventId, int funcRef)
|
|||||||
Bindings[eventId].push_back(funcRef);
|
Bindings[eventId].push_back(funcRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Eluna::EventBind::BeginCall(int eventId) const
|
bool Eluna::EventBind::HasEvents(int eventId) const
|
||||||
{
|
{
|
||||||
if (Bindings.empty())
|
if (Bindings.empty())
|
||||||
return false;
|
return false;
|
||||||
if (Bindings.find(eventId) == Bindings.end())
|
if (Bindings.find(eventId) == Bindings.end())
|
||||||
return false;
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Eluna::EventBind::BeginCall(int eventId) const
|
||||||
|
{
|
||||||
lua_settop(sEluna->L, 0); // stack should be empty
|
lua_settop(sEluna->L, 0); // stack should be empty
|
||||||
sEluna->Push(sEluna->L, eventId);
|
sEluna->Push(sEluna->L, eventId);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Eluna::EventBind::ExecuteCall()
|
void Eluna::EventBind::ExecuteCall()
|
||||||
|
|||||||
56
LuaEngine.h
56
LuaEngine.h
@@ -65,9 +65,6 @@ extern "C"
|
|||||||
|
|
||||||
typedef std::set<std::string> LoadedScripts;
|
typedef std::set<std::string> LoadedScripts;
|
||||||
|
|
||||||
#define ELUNA_GUARD() { }
|
|
||||||
// ACE_Guard< ACE_Thread_Mutex > ELUNA_GUARD_OBJECT (sEluna->lock);
|
|
||||||
|
|
||||||
#ifdef MANGOS
|
#ifdef MANGOS
|
||||||
#undef sWorld
|
#undef sWorld
|
||||||
#undef sMapMgr
|
#undef sMapMgr
|
||||||
@@ -451,11 +448,11 @@ class Eluna
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
friend class ScriptMgr;
|
friend class ScriptMgr;
|
||||||
friend class ACE_Singleton<Eluna, ACE_Thread_Mutex>;
|
friend class ACE_Singleton<Eluna, ACE_Null_Mutex>;
|
||||||
|
|
||||||
lua_State* L;
|
lua_State* L;
|
||||||
EventMgr m_EventMgr;
|
EventMgr m_EventMgr;
|
||||||
// ACE_Thread_Mutex lock;
|
ACE_Recursive_Thread_Mutex lock;
|
||||||
|
|
||||||
Eluna()
|
Eluna()
|
||||||
{
|
{
|
||||||
@@ -491,8 +488,10 @@ public:
|
|||||||
return &itr->second;
|
return &itr->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks if there are events for ID, if so, cleans stack and pushes eventId
|
// Checks if there are events for ID
|
||||||
bool BeginCall(int eventId) const;
|
bool HasEvents(int eventId) const;
|
||||||
|
// Cleans stack and pushes eventId
|
||||||
|
void BeginCall(int eventId) const;
|
||||||
// Loops through all registered events for the eventId at stack index 1
|
// Loops through all registered events for the eventId at stack index 1
|
||||||
// Copies the whole stack as arguments for the called function. Before Executing, push all params to stack!
|
// Copies the whole stack as arguments for the called function. Before Executing, push all params to stack!
|
||||||
// Leaves return values from all functions in order to the stack.
|
// Leaves return values from all functions in order to the stack.
|
||||||
@@ -687,9 +686,50 @@ template<> Corpse* Eluna::CHECKOBJ<Corpse>(lua_State* L, int narg, bool error);
|
|||||||
#ifdef MANGOS
|
#ifdef MANGOS
|
||||||
#define sEluna (&MaNGOS::Singleton<Eluna>::Instance())
|
#define sEluna (&MaNGOS::Singleton<Eluna>::Instance())
|
||||||
#else
|
#else
|
||||||
#define sEluna ACE_Singleton<Eluna, ACE_Thread_Mutex>::instance()
|
#define sEluna ACE_Singleton<Eluna, ACE_Null_Mutex>::instance()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
class FakeLock
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static bool locked;
|
||||||
|
FakeLock()
|
||||||
|
{
|
||||||
|
if (locked)
|
||||||
|
printf("ELUNA_GUARD CREATE\n");
|
||||||
|
locked = true;
|
||||||
|
}
|
||||||
|
~FakeLock()
|
||||||
|
{
|
||||||
|
if (!locked)
|
||||||
|
printf("ELUNA_GUARD DELETE\n");
|
||||||
|
locked = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
class FakeRecursiveLock
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static uint32 locked;
|
||||||
|
FakeRecursiveLock()
|
||||||
|
{
|
||||||
|
++locked;
|
||||||
|
if (locked > 1)
|
||||||
|
printf("GUARD LOCK %u\n", locked);
|
||||||
|
}
|
||||||
|
~FakeRecursiveLock()
|
||||||
|
{
|
||||||
|
if (!locked)
|
||||||
|
printf("GUARD FAULTY\n");
|
||||||
|
else if (locked > 1)
|
||||||
|
printf("GUARD RELE %u\n", locked);
|
||||||
|
--locked;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
#define ELUNA_GUARD() \
|
||||||
|
ACE_Guard< ACE_Recursive_Thread_Mutex > ELUNA_GUARD_OBJECT(sEluna->lock);
|
||||||
|
|
||||||
class LuaTaxiMgr
|
class LuaTaxiMgr
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user