From e5e6fe8c41a043119c0ac7783a9b874e5eb856bc Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Fri, 14 Dec 2012 16:17:07 +0200 Subject: Added locking in NullRegionData. This prevents errors when one thread iterates over the regions (e.g., from RegenerateMaptileAndReregister()) while another thread is adding a region. --- OpenSim/Data/Null/NullRegionData.cs | 64 +++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 20 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Data/Null/NullRegionData.cs b/OpenSim/Data/Null/NullRegionData.cs index b4d701a..f707d98 100644 --- a/OpenSim/Data/Null/NullRegionData.cs +++ b/OpenSim/Data/Null/NullRegionData.cs @@ -113,11 +113,14 @@ namespace OpenSim.Data.Null // Find region data List ret = new List(); - foreach (RegionData r in m_regionData.Values) + lock (m_regionData) { -// m_log.DebugFormat("[NULL REGION DATA]: comparing {0} to {1}", cleanName, r.RegionName.ToLower()); + foreach (RegionData r in m_regionData.Values) + { + // m_log.DebugFormat("[NULL REGION DATA]: comparing {0} to {1}", cleanName, r.RegionName.ToLower()); if (queryMatch(r.RegionName.ToLower())) ret.Add(r); + } } if (ret.Count > 0) @@ -133,10 +136,13 @@ namespace OpenSim.Data.Null List ret = new List(); - foreach (RegionData r in m_regionData.Values) + lock (m_regionData) { - if (r.posX == posX && r.posY == posY) - ret.Add(r); + foreach (RegionData r in m_regionData.Values) + { + if (r.posX == posX && r.posY == posY) + ret.Add(r); + } } if (ret.Count > 0) @@ -150,8 +156,11 @@ namespace OpenSim.Data.Null if (m_useStaticInstance && Instance != this) return Instance.Get(regionID, scopeID); - if (m_regionData.ContainsKey(regionID)) - return m_regionData[regionID]; + lock (m_regionData) + { + if (m_regionData.ContainsKey(regionID)) + return m_regionData[regionID]; + } return null; } @@ -163,10 +172,13 @@ namespace OpenSim.Data.Null List ret = new List(); - foreach (RegionData r in m_regionData.Values) + lock (m_regionData) { - if (r.posX >= startX && r.posX <= endX && r.posY >= startY && r.posY <= endY) - ret.Add(r); + foreach (RegionData r in m_regionData.Values) + { + if (r.posX >= startX && r.posX <= endX && r.posY >= startY && r.posY <= endY) + ret.Add(r); + } } return ret; @@ -180,7 +192,10 @@ namespace OpenSim.Data.Null // m_log.DebugFormat( // "[NULL REGION DATA]: Storing region {0} {1}, scope {2}", data.RegionName, data.RegionID, data.ScopeID); - m_regionData[data.RegionID] = data; + lock (m_regionData) + { + m_regionData[data.RegionID] = data; + } return true; } @@ -190,10 +205,13 @@ namespace OpenSim.Data.Null if (m_useStaticInstance && Instance != this) return Instance.SetDataItem(regionID, item, value); - if (!m_regionData.ContainsKey(regionID)) - return false; + lock (m_regionData) + { + if (!m_regionData.ContainsKey(regionID)) + return false; - m_regionData[regionID].Data[item] = value; + m_regionData[regionID].Data[item] = value; + } return true; } @@ -205,10 +223,13 @@ namespace OpenSim.Data.Null // m_log.DebugFormat("[NULL REGION DATA]: Deleting region {0}", regionID); - if (!m_regionData.ContainsKey(regionID)) - return false; + lock (m_regionData) + { + if (!m_regionData.ContainsKey(regionID)) + return false; - m_regionData.Remove(regionID); + m_regionData.Remove(regionID); + } return true; } @@ -238,10 +259,13 @@ namespace OpenSim.Data.Null List ret = new List(); - foreach (RegionData r in m_regionData.Values) + lock (m_regionData) { - if ((Convert.ToInt32(r.Data["flags"]) & regionFlags) != 0) - ret.Add(r); + foreach (RegionData r in m_regionData.Values) + { + if ((Convert.ToInt32(r.Data["flags"]) & regionFlags) != 0) + ret.Add(r); + } } return ret; -- cgit v1.1