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.
0.7.5-pf-bulletsim
Oren Hurvitz 2012-12-14 16:17:07 +02:00 committed by Justin Clark-Casey (justincc)
parent 226d655f23
commit e5e6fe8c41
1 changed files with 44 additions and 20 deletions

View File

@ -113,12 +113,15 @@ namespace OpenSim.Data.Null
// Find region data // Find region data
List<RegionData> ret = new List<RegionData>(); List<RegionData> ret = new List<RegionData>();
lock (m_regionData)
{
foreach (RegionData r in m_regionData.Values) foreach (RegionData r in m_regionData.Values)
{ {
// m_log.DebugFormat("[NULL REGION DATA]: comparing {0} to {1}", cleanName, r.RegionName.ToLower()); // m_log.DebugFormat("[NULL REGION DATA]: comparing {0} to {1}", cleanName, r.RegionName.ToLower());
if (queryMatch(r.RegionName.ToLower())) if (queryMatch(r.RegionName.ToLower()))
ret.Add(r); ret.Add(r);
} }
}
if (ret.Count > 0) if (ret.Count > 0)
return ret; return ret;
@ -133,11 +136,14 @@ namespace OpenSim.Data.Null
List<RegionData> ret = new List<RegionData>(); List<RegionData> ret = new List<RegionData>();
lock (m_regionData)
{
foreach (RegionData r in m_regionData.Values) foreach (RegionData r in m_regionData.Values)
{ {
if (r.posX == posX && r.posY == posY) if (r.posX == posX && r.posY == posY)
ret.Add(r); ret.Add(r);
} }
}
if (ret.Count > 0) if (ret.Count > 0)
return ret[0]; return ret[0];
@ -150,8 +156,11 @@ namespace OpenSim.Data.Null
if (m_useStaticInstance && Instance != this) if (m_useStaticInstance && Instance != this)
return Instance.Get(regionID, scopeID); return Instance.Get(regionID, scopeID);
lock (m_regionData)
{
if (m_regionData.ContainsKey(regionID)) if (m_regionData.ContainsKey(regionID))
return m_regionData[regionID]; return m_regionData[regionID];
}
return null; return null;
} }
@ -163,11 +172,14 @@ namespace OpenSim.Data.Null
List<RegionData> ret = new List<RegionData>(); List<RegionData> ret = new List<RegionData>();
lock (m_regionData)
{
foreach (RegionData r in m_regionData.Values) foreach (RegionData r in m_regionData.Values)
{ {
if (r.posX >= startX && r.posX <= endX && r.posY >= startY && r.posY <= endY) if (r.posX >= startX && r.posX <= endX && r.posY >= startY && r.posY <= endY)
ret.Add(r); ret.Add(r);
} }
}
return ret; return ret;
} }
@ -180,7 +192,10 @@ namespace OpenSim.Data.Null
// m_log.DebugFormat( // m_log.DebugFormat(
// "[NULL REGION DATA]: Storing region {0} {1}, scope {2}", data.RegionName, data.RegionID, data.ScopeID); // "[NULL REGION DATA]: Storing region {0} {1}, scope {2}", data.RegionName, data.RegionID, data.ScopeID);
lock (m_regionData)
{
m_regionData[data.RegionID] = data; m_regionData[data.RegionID] = data;
}
return true; return true;
} }
@ -190,10 +205,13 @@ namespace OpenSim.Data.Null
if (m_useStaticInstance && Instance != this) if (m_useStaticInstance && Instance != this)
return Instance.SetDataItem(regionID, item, value); return Instance.SetDataItem(regionID, item, value);
lock (m_regionData)
{
if (!m_regionData.ContainsKey(regionID)) if (!m_regionData.ContainsKey(regionID))
return false; return false;
m_regionData[regionID].Data[item] = value; m_regionData[regionID].Data[item] = value;
}
return true; return true;
} }
@ -205,10 +223,13 @@ namespace OpenSim.Data.Null
// m_log.DebugFormat("[NULL REGION DATA]: Deleting region {0}", regionID); // m_log.DebugFormat("[NULL REGION DATA]: Deleting region {0}", regionID);
lock (m_regionData)
{
if (!m_regionData.ContainsKey(regionID)) if (!m_regionData.ContainsKey(regionID))
return false; return false;
m_regionData.Remove(regionID); m_regionData.Remove(regionID);
}
return true; return true;
} }
@ -238,11 +259,14 @@ namespace OpenSim.Data.Null
List<RegionData> ret = new List<RegionData>(); List<RegionData> ret = new List<RegionData>();
lock (m_regionData)
{
foreach (RegionData r in m_regionData.Values) foreach (RegionData r in m_regionData.Values)
{ {
if ((Convert.ToInt32(r.Data["flags"]) & regionFlags) != 0) if ((Convert.ToInt32(r.Data["flags"]) & regionFlags) != 0)
ret.Add(r); ret.Add(r);
} }
}
return ret; return ret;
} }