Fix possible race condition with local region cache if a region was added after startup.

user_profiles
Justin Clark-Casey (justincc) 2013-05-03 18:56:58 +01:00
parent 7ca42d5711
commit 5d93c99e8c
1 changed files with 28 additions and 15 deletions

View File

@ -142,10 +142,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
scene.RegisterModuleInterface<IGridService>(this); scene.RegisterModuleInterface<IGridService>(this);
if (m_LocalCache.ContainsKey(scene.RegionInfo.RegionID)) lock (m_LocalCache)
m_log.ErrorFormat("[LOCAL GRID SERVICE CONNECTOR]: simulator seems to have more than one region with the same UUID. Please correct this!"); {
else if (m_LocalCache.ContainsKey(scene.RegionInfo.RegionID))
m_LocalCache.Add(scene.RegionInfo.RegionID, new RegionCache(scene)); m_log.ErrorFormat("[LOCAL GRID SERVICE CONNECTOR]: simulator seems to have more than one region with the same UUID. Please correct this!");
else
m_LocalCache.Add(scene.RegionInfo.RegionID, new RegionCache(scene));
}
} }
public void RemoveRegion(Scene scene) public void RemoveRegion(Scene scene)
@ -153,8 +156,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
if (!m_Enabled) if (!m_Enabled)
return; return;
m_LocalCache[scene.RegionInfo.RegionID].Clear(); lock (m_LocalCache)
m_LocalCache.Remove(scene.RegionInfo.RegionID); {
m_LocalCache[scene.RegionInfo.RegionID].Clear();
m_LocalCache.Remove(scene.RegionInfo.RegionID);
}
} }
public void RegionLoaded(Scene scene) public void RegionLoaded(Scene scene)
@ -191,12 +197,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
// First see if it's a neighbour, even if it isn't on this sim. // First see if it's a neighbour, even if it isn't on this sim.
// Neighbour data is cached in memory, so this is fast // Neighbour data is cached in memory, so this is fast
foreach (RegionCache rcache in m_LocalCache.Values)
lock (m_LocalCache)
{ {
region = rcache.GetRegionByPosition(x, y); foreach (RegionCache rcache in m_LocalCache.Values)
if (region != null)
{ {
return region; region = rcache.GetRegionByPosition(x, y);
if (region != null)
{
return region;
}
} }
} }
@ -245,12 +255,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
{ {
System.Text.StringBuilder caps = new System.Text.StringBuilder(); System.Text.StringBuilder caps = new System.Text.StringBuilder();
foreach (KeyValuePair<UUID, RegionCache> kvp in m_LocalCache) lock (m_LocalCache)
{ {
caps.AppendFormat("*** Neighbours of {0} ({1}) ***\n", kvp.Value.RegionName, kvp.Key); foreach (KeyValuePair<UUID, RegionCache> kvp in m_LocalCache)
List<GridRegion> regions = kvp.Value.GetNeighbours(); {
foreach (GridRegion r in regions) caps.AppendFormat("*** Neighbours of {0} ({1}) ***\n", kvp.Value.RegionName, kvp.Key);
caps.AppendFormat(" {0} @ {1}-{2}\n", r.RegionName, r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize); List<GridRegion> regions = kvp.Value.GetNeighbours();
foreach (GridRegion r in regions)
caps.AppendFormat(" {0} @ {1}-{2}\n", r.RegionName, r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize);
}
} }
MainConsole.Instance.Output(caps.ToString()); MainConsole.Instance.Output(caps.ToString());