Make dictionary read/write locking consistent in CapabilitiesModule, rename two dictionary fields to standard m_ format

cpu-performance
Justin Clark-Casey (justincc) 2013-07-08 18:07:04 +01:00
parent 2f6ee8aee2
commit a38c2abae4
1 changed files with 83 additions and 49 deletions

View File

@ -57,8 +57,8 @@ namespace OpenSim.Region.CoreModules.Framework
/// </summary> /// </summary>
protected Dictionary<UUID, Caps> m_capsObjects = new Dictionary<UUID, Caps>(); protected Dictionary<UUID, Caps> m_capsObjects = new Dictionary<UUID, Caps>();
protected Dictionary<UUID, string> capsPaths = new Dictionary<UUID, string>(); protected Dictionary<UUID, string> m_capsPaths = new Dictionary<UUID, string>();
protected Dictionary<UUID, Dictionary<ulong, string>> childrenSeeds protected Dictionary<UUID, Dictionary<ulong, string>> m_childrenSeeds
= new Dictionary<UUID, Dictionary<ulong, string>>(); = new Dictionary<UUID, Dictionary<ulong, string>>();
public void Initialise(IConfigSource source) public void Initialise(IConfigSource source)
@ -105,35 +105,42 @@ namespace OpenSim.Region.CoreModules.Framework
if (m_scene.RegionInfo.EstateSettings.IsBanned(agentId)) if (m_scene.RegionInfo.EstateSettings.IsBanned(agentId))
return; return;
Caps caps;
String capsObjectPath = GetCapsPath(agentId); String capsObjectPath = GetCapsPath(agentId);
if (m_capsObjects.ContainsKey(agentId)) lock (m_capsObjects)
{ {
Caps oldCaps = m_capsObjects[agentId]; if (m_capsObjects.ContainsKey(agentId))
{
Caps oldCaps = m_capsObjects[agentId];
m_log.DebugFormat( m_log.DebugFormat(
"[CAPS]: Recreating caps for agent {0}. Old caps path {1}, new caps path {2}. ", "[CAPS]: Recreating caps for agent {0}. Old caps path {1}, new caps path {2}. ",
agentId, oldCaps.CapsObjectPath, capsObjectPath); agentId, oldCaps.CapsObjectPath, capsObjectPath);
// This should not happen. The caller code is confused. We need to fix that. // This should not happen. The caller code is confused. We need to fix that.
// CAPs can never be reregistered, or the client will be confused. // CAPs can never be reregistered, or the client will be confused.
// Hence this return here. // Hence this return here.
//return; //return;
}
caps = new Caps(MainServer.Instance, m_scene.RegionInfo.ExternalHostName,
(MainServer.Instance == null) ? 0: MainServer.Instance.Port,
capsObjectPath, agentId, m_scene.RegionInfo.RegionName);
m_capsObjects[agentId] = caps;
} }
Caps caps = new Caps(MainServer.Instance, m_scene.RegionInfo.ExternalHostName,
(MainServer.Instance == null) ? 0: MainServer.Instance.Port,
capsObjectPath, agentId, m_scene.RegionInfo.RegionName);
m_capsObjects[agentId] = caps;
m_scene.EventManager.TriggerOnRegisterCaps(agentId, caps); m_scene.EventManager.TriggerOnRegisterCaps(agentId, caps);
} }
public void RemoveCaps(UUID agentId) public void RemoveCaps(UUID agentId)
{ {
if (childrenSeeds.ContainsKey(agentId)) lock (m_childrenSeeds)
{ {
childrenSeeds.Remove(agentId); if (m_childrenSeeds.ContainsKey(agentId))
{
m_childrenSeeds.Remove(agentId);
}
} }
lock (m_capsObjects) lock (m_capsObjects)
@ -168,16 +175,22 @@ namespace OpenSim.Region.CoreModules.Framework
public void SetAgentCapsSeeds(AgentCircuitData agent) public void SetAgentCapsSeeds(AgentCircuitData agent)
{ {
capsPaths[agent.AgentID] = agent.CapsPath; lock (m_capsPaths)
childrenSeeds[agent.AgentID] m_capsPaths[agent.AgentID] = agent.CapsPath;
= ((agent.ChildrenCapSeeds == null) ? new Dictionary<ulong, string>() : agent.ChildrenCapSeeds);
lock (m_childrenSeeds)
m_childrenSeeds[agent.AgentID]
= ((agent.ChildrenCapSeeds == null) ? new Dictionary<ulong, string>() : agent.ChildrenCapSeeds);
} }
public string GetCapsPath(UUID agentId) public string GetCapsPath(UUID agentId)
{ {
if (capsPaths.ContainsKey(agentId)) lock (m_capsPaths)
{ {
return capsPaths[agentId]; if (m_capsPaths.ContainsKey(agentId))
{
return m_capsPaths[agentId];
}
} }
return null; return null;
@ -186,17 +199,24 @@ namespace OpenSim.Region.CoreModules.Framework
public Dictionary<ulong, string> GetChildrenSeeds(UUID agentID) public Dictionary<ulong, string> GetChildrenSeeds(UUID agentID)
{ {
Dictionary<ulong, string> seeds = null; Dictionary<ulong, string> seeds = null;
if (childrenSeeds.TryGetValue(agentID, out seeds))
return seeds; lock (m_childrenSeeds)
if (m_childrenSeeds.TryGetValue(agentID, out seeds))
return seeds;
return new Dictionary<ulong, string>(); return new Dictionary<ulong, string>();
} }
public void DropChildSeed(UUID agentID, ulong handle) public void DropChildSeed(UUID agentID, ulong handle)
{ {
Dictionary<ulong, string> seeds; Dictionary<ulong, string> seeds;
if (childrenSeeds.TryGetValue(agentID, out seeds))
lock (m_childrenSeeds)
{ {
seeds.Remove(handle); if (m_childrenSeeds.TryGetValue(agentID, out seeds))
{
seeds.Remove(handle);
}
} }
} }
@ -204,30 +224,41 @@ namespace OpenSim.Region.CoreModules.Framework
{ {
Dictionary<ulong, string> seeds; Dictionary<ulong, string> seeds;
string returnval; string returnval;
if (childrenSeeds.TryGetValue(agentID, out seeds))
lock (m_childrenSeeds)
{ {
if (seeds.TryGetValue(handle, out returnval)) if (m_childrenSeeds.TryGetValue(agentID, out seeds))
return returnval; {
if (seeds.TryGetValue(handle, out returnval))
return returnval;
}
} }
return null; return null;
} }
public void SetChildrenSeed(UUID agentID, Dictionary<ulong, string> seeds) public void SetChildrenSeed(UUID agentID, Dictionary<ulong, string> seeds)
{ {
//m_log.DebugFormat(" !!! Setting child seeds in {0} to {1}", m_scene.RegionInfo.RegionName, seeds.Count); //m_log.DebugFormat(" !!! Setting child seeds in {0} to {1}", m_scene.RegionInfo.RegionName, seeds.Count);
childrenSeeds[agentID] = seeds;
lock (m_childrenSeeds)
m_childrenSeeds[agentID] = seeds;
} }
public void DumpChildrenSeeds(UUID agentID) public void DumpChildrenSeeds(UUID agentID)
{ {
m_log.Info("================ ChildrenSeed "+m_scene.RegionInfo.RegionName+" ================"); m_log.Info("================ ChildrenSeed "+m_scene.RegionInfo.RegionName+" ================");
foreach (KeyValuePair<ulong, string> kvp in childrenSeeds[agentID])
lock (m_childrenSeeds)
{ {
uint x, y; foreach (KeyValuePair<ulong, string> kvp in m_childrenSeeds[agentID])
Utils.LongToUInts(kvp.Key, out x, out y); {
x = x / Constants.RegionSize; uint x, y;
y = y / Constants.RegionSize; Utils.LongToUInts(kvp.Key, out x, out y);
m_log.Info(" >> "+x+", "+y+": "+kvp.Value); x = x / Constants.RegionSize;
y = y / Constants.RegionSize;
m_log.Info(" >> "+x+", "+y+": "+kvp.Value);
}
} }
} }
@ -236,18 +267,21 @@ namespace OpenSim.Region.CoreModules.Framework
StringBuilder caps = new StringBuilder(); StringBuilder caps = new StringBuilder();
caps.AppendFormat("Region {0}:\n", m_scene.RegionInfo.RegionName); caps.AppendFormat("Region {0}:\n", m_scene.RegionInfo.RegionName);
foreach (KeyValuePair<UUID, Caps> kvp in m_capsObjects) lock (m_capsObjects)
{ {
caps.AppendFormat("** User {0}:\n", kvp.Key); foreach (KeyValuePair<UUID, Caps> kvp in m_capsObjects)
for (IDictionaryEnumerator kvp2 = kvp.Value.CapsHandlers.GetCapsDetails(false, null).GetEnumerator(); kvp2.MoveNext(); )
{ {
Uri uri = new Uri(kvp2.Value.ToString()); caps.AppendFormat("** User {0}:\n", kvp.Key);
caps.AppendFormat(m_showCapsCommandFormat, kvp2.Key, uri.PathAndQuery);
}
foreach (KeyValuePair<string, string> kvp3 in kvp.Value.ExternalCapsHandlers) for (IDictionaryEnumerator kvp2 = kvp.Value.CapsHandlers.GetCapsDetails(false, null).GetEnumerator(); kvp2.MoveNext(); )
caps.AppendFormat(m_showCapsCommandFormat, kvp3.Key, kvp3.Value); {
Uri uri = new Uri(kvp2.Value.ToString());
caps.AppendFormat(m_showCapsCommandFormat, kvp2.Key, uri.PathAndQuery);
}
foreach (KeyValuePair<string, string> kvp3 in kvp.Value.ExternalCapsHandlers)
caps.AppendFormat(m_showCapsCommandFormat, kvp3.Key, kvp3.Value);
}
} }
MainConsole.Instance.Output(caps.ToString()); MainConsole.Instance.Output(caps.ToString());