From 01f70de2ea562f78991084be01a83295f8f2be0b Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Fri, 20 Feb 2009 14:04:29 +0000 Subject: * Consistently lock part.TaskInventory as pointed out in http://opensimulator.org/mantis/view.php?id=3159 * Not locking causes enumeration exceptions as described in this matis * part.TaskInventory needs to be locked for every access as it's a dictionary * Extra locking will hopefully not cause any major issues - in places where the enumeration of the dictionary performs other lock or long running operations, the dictionary is cloned instead --- .../Framework/Scenes/Hypergrid/HGAssetMapper.cs | 7 +++-- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 34 +++++++++++++--------- OpenSim/Region/Framework/Scenes/UuidGatherer.cs | 6 ++-- 3 files changed, 30 insertions(+), 17 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes') diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs index 1a3c4c8..f7db908 100644 --- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs +++ b/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs @@ -226,9 +226,12 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid { TaskInventoryDictionary tinv = sog.RootPart.TaskInventory; - foreach (TaskInventoryItem titem in tinv.Values) + lock (tinv) { - uuids.Add(titem.AssetID, (InventoryType)titem.Type == InventoryType.Texture); + foreach (TaskInventoryItem titem in tinv.Values) + { + uuids.Add(titem.AssetID, (InventoryType)titem.Type == InventoryType.Texture); + } } } diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index ec3fdf1..27c22eb 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -1710,12 +1710,15 @@ if (m_shape != null) { info.AddValue("m_inventoryFileName", Inventory.GetInventoryFileName()); info.AddValue("m_folderID", UUID); info.AddValue("PhysActor", PhysActor); - + Dictionary TaskInventory_work = new Dictionary(); - foreach (UUID id in TaskInventory.Keys) + lock (TaskInventory) { - TaskInventory_work.Add(id.Guid, TaskInventory[id]); + foreach (UUID id in TaskInventory.Keys) + { + TaskInventory_work.Add(id.Guid, TaskInventory[id]); + } } info.AddValue("TaskInventory", TaskInventory_work); @@ -2166,13 +2169,16 @@ if (m_shape != null) { { //Trys to fetch sound id from prim's inventory. //Prim's inventory doesn't support non script items yet - SceneObjectPart op = this; - foreach (KeyValuePair item in op.TaskInventory) + + lock (TaskInventory) { - if (item.Value.Name == sound) + foreach (KeyValuePair item in TaskInventory) { - soundID = item.Value.ItemID; - break; + if (item.Value.Name == sound) + { + soundID = item.Value.ItemID; + break; + } } } } @@ -2486,13 +2492,15 @@ if (m_shape != null) { if (!UUID.TryParse(sound, out soundID)) { // search sound file from inventory - SceneObjectPart op = this; - foreach (KeyValuePair item in op.TaskInventory) + lock (TaskInventory) { - if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound) + foreach (KeyValuePair item in TaskInventory) { - soundID = item.Value.ItemID; - break; + if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound) + { + soundID = item.Value.ItemID; + break; + } } } } diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs index bc8896e..7b2fae0 100644 --- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs @@ -140,9 +140,11 @@ namespace OpenSim.Region.Framework.Scenes // If the prim is a sculpt then preserve this information too if (part.Shape.SculptTexture != UUID.Zero) assetUuids[part.Shape.SculptTexture] = 1; - + + TaskInventoryDictionary taskDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone(); + // Now analyze this prim's inventory items to preserve all the uuids that they reference - foreach (TaskInventoryItem tii in part.TaskInventory.Values) + foreach (TaskInventoryItem tii in taskDictionary.Values) { //m_log.DebugFormat("[ARCHIVER]: Analysing item asset type {0}", tii.Type); -- cgit v1.1