have script mutex locks before spells locks
This commit is contained in:
parent
d639e54961
commit
b693deb4f8
@ -623,13 +623,14 @@ LuaSpell* LuaInterface::GetCurrentSpell(lua_State* state, bool needsLock) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LuaInterface::RemoveCurrentSpell(lua_State* state, LuaSpell* cur_spell, bool needsLock, bool removeCurSpell, bool removeSpellScript) {
|
void LuaInterface::RemoveCurrentSpell(lua_State* state, LuaSpell* cur_spell, bool needsLock, bool removeCurSpell, bool removeSpellScript) {
|
||||||
|
|
||||||
|
MSpellScripts.writelock(__FUNCTION__, __LINE__);
|
||||||
if(needsLock) {
|
if(needsLock) {
|
||||||
MSpells.lock();
|
MSpells.lock();
|
||||||
MSpellDelete.lock();
|
MSpellDelete.lock();
|
||||||
}
|
}
|
||||||
map<lua_State*, LuaSpell*>::iterator itr = current_spells.find(state);
|
map<lua_State*, LuaSpell*>::iterator itr = current_spells.find(state);
|
||||||
if(removeSpellScript && itr->second) {
|
if(removeSpellScript && itr->second) {
|
||||||
MSpellScripts.writelock(__FUNCTION__, __LINE__);
|
|
||||||
map<string, map<lua_State*, LuaSpell*> >::iterator spell_script_itr = spell_scripts.find(cur_spell->file_name);
|
map<string, map<lua_State*, LuaSpell*> >::iterator spell_script_itr = spell_scripts.find(cur_spell->file_name);
|
||||||
if(spell_script_itr != spell_scripts.end()) {
|
if(spell_script_itr != spell_scripts.end()) {
|
||||||
LogWrite(SPELL__DEBUG, 9, "Spell", "LuaInterface::RemoveCurrentSpell spell %s. Queue Entries %u.", cur_spell->file_name.c_str(), spell_script_itr->second.size());
|
LogWrite(SPELL__DEBUG, 9, "Spell", "LuaInterface::RemoveCurrentSpell spell %s. Queue Entries %u.", cur_spell->file_name.c_str(), spell_script_itr->second.size());
|
||||||
@ -641,7 +642,6 @@ void LuaInterface::RemoveCurrentSpell(lua_State* state, LuaSpell* cur_spell, boo
|
|||||||
}
|
}
|
||||||
mutex->releasewritelock(__FUNCTION__, __LINE__);
|
mutex->releasewritelock(__FUNCTION__, __LINE__);
|
||||||
}
|
}
|
||||||
MSpellScripts.releasewritelock(__FUNCTION__, __LINE__);
|
|
||||||
}
|
}
|
||||||
if(itr != current_spells.end() && removeCurSpell)
|
if(itr != current_spells.end() && removeCurSpell)
|
||||||
current_spells.erase(itr);
|
current_spells.erase(itr);
|
||||||
@ -649,6 +649,7 @@ void LuaInterface::RemoveCurrentSpell(lua_State* state, LuaSpell* cur_spell, boo
|
|||||||
MSpellDelete.unlock();
|
MSpellDelete.unlock();
|
||||||
MSpells.unlock();
|
MSpells.unlock();
|
||||||
}
|
}
|
||||||
|
MSpellScripts.releasewritelock(__FUNCTION__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaInterface::CallSpellProcess(LuaSpell* spell, int8 num_parameters, std::string customFunction) {
|
bool LuaInterface::CallSpellProcess(LuaSpell* spell, int8 num_parameters, std::string customFunction) {
|
||||||
@ -2385,8 +2386,8 @@ LuaSpell* LuaInterface::GetSpellScript(const char* name, bool create_new, bool u
|
|||||||
LuaSpell* ret = 0;
|
LuaSpell* ret = 0;
|
||||||
Mutex* mutex = 0;
|
Mutex* mutex = 0;
|
||||||
|
|
||||||
MSpells.lock();
|
|
||||||
MSpellScripts.writelock(__FUNCTION__, __LINE__);
|
MSpellScripts.writelock(__FUNCTION__, __LINE__);
|
||||||
|
MSpells.lock();
|
||||||
itr = spell_scripts.find(name);
|
itr = spell_scripts.find(name);
|
||||||
if(itr != spell_scripts.end()) {
|
if(itr != spell_scripts.end()) {
|
||||||
mutex = GetSpellScriptMutex(name);
|
mutex = GetSpellScriptMutex(name);
|
||||||
@ -2404,8 +2405,8 @@ LuaSpell* LuaInterface::GetSpellScript(const char* name, bool create_new, bool u
|
|||||||
}
|
}
|
||||||
mutex->releasewritelock(__FUNCTION__, __LINE__);
|
mutex->releasewritelock(__FUNCTION__, __LINE__);
|
||||||
}
|
}
|
||||||
MSpellScripts.releasewritelock(__FUNCTION__, __LINE__);
|
|
||||||
MSpells.unlock();
|
MSpells.unlock();
|
||||||
|
MSpellScripts.releasewritelock(__FUNCTION__, __LINE__);
|
||||||
|
|
||||||
if(!ret && create_new){
|
if(!ret && create_new){
|
||||||
if(!name || (ret = LoadSpellScript(name)) == nullptr) {
|
if(!name || (ret = LoadSpellScript(name)) == nullptr) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user