From 699d3b0965a5e77c967365dec41813fe9e196836 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 19 Jul 2010 13:59:11 -0700 Subject: One more stab at http://opensimulator.org/mantis/view.php?id=4858. Eliminated the nested locks of m_Scripts and m_PrimObjects. --- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 66 +++++++++++++------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/XEngine') diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 808cf82..b8bdc19 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -818,60 +818,60 @@ namespace OpenSim.Region.ScriptEngine.XEngine m_CompileDict.Remove(itemID); } + IScriptInstance instance = null; + lock (m_Scripts) { // Do we even have it? if (!m_Scripts.ContainsKey(itemID)) return; - IScriptInstance instance=m_Scripts[itemID]; + instance=m_Scripts[itemID]; m_Scripts.Remove(itemID); + } - instance.ClearQueue(); - instance.Stop(0); - + instance.ClearQueue(); + instance.Stop(0); // bool objectRemoved = false; - lock (m_PrimObjects) + lock (m_PrimObjects) + { + // Remove the script from it's prim + if (m_PrimObjects.ContainsKey(localID)) { - // Remove the script from it's prim - if (m_PrimObjects.ContainsKey(localID)) - { - // Remove inventory item record - if (m_PrimObjects[localID].Contains(itemID)) - m_PrimObjects[localID].Remove(itemID); + // Remove inventory item record + if (m_PrimObjects[localID].Contains(itemID)) + m_PrimObjects[localID].Remove(itemID); - // If there are no more scripts, remove prim - if (m_PrimObjects[localID].Count == 0) - { - m_PrimObjects.Remove(localID); + // If there are no more scripts, remove prim + if (m_PrimObjects[localID].Count == 0) + { + m_PrimObjects.Remove(localID); // objectRemoved = true; - } } } + } - instance.RemoveState(); - instance.DestroyScriptInstance(); + instance.RemoveState(); + instance.DestroyScriptInstance(); - m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); - if (m_DomainScripts[instance.AppDomain].Count == 0) - { - m_DomainScripts.Remove(instance.AppDomain); - UnloadAppDomain(instance.AppDomain); - } - - instance = null; + m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); + if (m_DomainScripts[instance.AppDomain].Count == 0) + { + m_DomainScripts.Remove(instance.AppDomain); + UnloadAppDomain(instance.AppDomain); + } - ObjectRemoved handlerObjectRemoved = OnObjectRemoved; - if (handlerObjectRemoved != null) - { - SceneObjectPart part = m_Scene.GetSceneObjectPart(localID); - handlerObjectRemoved(part.UUID); - } + instance = null; - CleanAssemblies(); + ObjectRemoved handlerObjectRemoved = OnObjectRemoved; + if (handlerObjectRemoved != null) + { + SceneObjectPart part = m_Scene.GetSceneObjectPart(localID); + handlerObjectRemoved(part.UUID); } + ScriptRemoved handlerScriptRemoved = OnScriptRemoved; if (handlerScriptRemoved != null) handlerScriptRemoved(itemID); -- cgit v1.1 From 257a46dfb9d722de1e1bcf331c2def0549fb998e Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 19 Jul 2010 15:20:34 -0700 Subject: Another stab at http://opensimulator.org/mantis/view.php?id=4858. Eliminated more nested locks. --- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 64 +++++++++++++++----------- 1 file changed, 36 insertions(+), 28 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/XEngine') diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index b8bdc19..aff4bda 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -701,9 +701,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine } } + ScriptInstance instance = null; lock (m_Scripts) { - ScriptInstance instance = null; // Create the object record if ((!m_Scripts.ContainsKey(itemID)) || @@ -784,28 +784,29 @@ namespace OpenSim.Region.ScriptEngine.XEngine m_Scripts[itemID] = instance; } + } - lock (m_PrimObjects) - { - if (!m_PrimObjects.ContainsKey(localID)) - m_PrimObjects[localID] = new List(); + lock (m_PrimObjects) + { + if (!m_PrimObjects.ContainsKey(localID)) + m_PrimObjects[localID] = new List(); - if (!m_PrimObjects[localID].Contains(itemID)) - m_PrimObjects[localID].Add(itemID); + if (!m_PrimObjects[localID].Contains(itemID)) + m_PrimObjects[localID].Add(itemID); - } + } - if (!m_Assemblies.ContainsKey(assetID)) - m_Assemblies[assetID] = assembly; + if (!m_Assemblies.ContainsKey(assetID)) + m_Assemblies[assetID] = assembly; - lock (m_AddingAssemblies) - { - m_AddingAssemblies[assembly]--; - } - - if (instance!=null) - instance.Init(); + lock (m_AddingAssemblies) + { + m_AddingAssemblies[assembly]--; } + + if (instance != null) + instance.Init(); + return true; } @@ -1005,26 +1006,33 @@ namespace OpenSim.Region.ScriptEngine.XEngine public bool PostObjectEvent(uint localID, EventParams p) { bool result = false; - + List uuids = null; + lock (m_PrimObjects) { if (!m_PrimObjects.ContainsKey(localID)) return false; - - foreach (UUID itemID in m_PrimObjects[localID]) + uuids = m_PrimObjects[localID]; + } + + foreach (UUID itemID in uuids) + { + IScriptInstance instance = null; + try { if (m_Scripts.ContainsKey(itemID)) - { - IScriptInstance instance = m_Scripts[itemID]; - if (instance != null) - { - instance.PostEvent(p); - result = true; - } - } + instance = m_Scripts[itemID]; + } + catch { /* ignore race conditions */ } + + if (instance != null) + { + instance.PostEvent(p); + result = true; } } + return result; } -- cgit v1.1