Improve locking in AgentCircuitManager

iar_mods
Justin Clark-Casey (justincc) 2011-12-03 16:19:11 +00:00
parent c934901a05
commit ced820bd5e
1 changed files with 41 additions and 25 deletions

View File

@ -38,6 +38,9 @@ namespace OpenSim.Framework
/// <summary>
/// Agent circuits indexed by circuit code.
/// </summary>
/// <remarks>
/// We lock this for operations both on this dictionary and on m_agentCircuitsByUUID
/// </remarks>
private Dictionary<uint, AgentCircuitData> m_agentCircuits = new Dictionary<uint, AgentCircuitData>();
/// <summary>
@ -48,16 +51,20 @@ namespace OpenSim.Framework
public virtual AuthenticateResponse AuthenticateSession(UUID sessionID, UUID agentID, uint circuitcode)
{
AgentCircuitData validcircuit = null;
if (m_agentCircuits.ContainsKey(circuitcode))
lock (m_agentCircuits)
{
if (m_agentCircuits.ContainsKey(circuitcode))
validcircuit = m_agentCircuits[circuitcode];
}
AuthenticateResponse user = new AuthenticateResponse();
if (validcircuit == null)
{
//don't have this circuit code in our list
user.Authorised = false;
return (user);
return user;
}
if ((sessionID == validcircuit.SessionID) && (agentID == validcircuit.AgentID))
@ -79,7 +86,7 @@ namespace OpenSim.Framework
user.Authorised = false;
}
return (user);
return user;
}
/// <summary>
@ -129,17 +136,24 @@ namespace OpenSim.Framework
}
}
}
public AgentCircuitData GetAgentCircuitData(uint circuitCode)
{
AgentCircuitData agentCircuit = null;
lock (m_agentCircuits)
m_agentCircuits.TryGetValue(circuitCode, out agentCircuit);
return agentCircuit;
}
public AgentCircuitData GetAgentCircuitData(UUID agentID)
{
AgentCircuitData agentCircuit = null;
lock (m_agentCircuits)
m_agentCircuitsByUUID.TryGetValue(agentID, out agentCircuit);
return agentCircuit;
}
@ -149,11 +163,13 @@ namespace OpenSim.Framework
/// <returns></returns>
public Dictionary<UUID, AgentCircuitData> GetAgentCircuits()
{
lock (m_agentCircuitsByUUID)
lock (m_agentCircuits)
return new Dictionary<UUID, AgentCircuitData>(m_agentCircuitsByUUID);
}
public void UpdateAgentData(AgentCircuitData agentData)
{
lock (m_agentCircuits)
{
if (m_agentCircuits.ContainsKey((uint) agentData.circuitcode))
{
@ -168,6 +184,7 @@ namespace OpenSim.Framework
// m_log.Debug("update user start pos is " + agentData.startpos.X + " , " + agentData.startpos.Y + " , " + agentData.startpos.Z);
}
}
}
/// <summary>
/// Sometimes the circuitcode may not be known before setting up the connection
@ -189,24 +206,23 @@ namespace OpenSim.Framework
return true;
}
}
return false;
return false;
}
public void UpdateAgentChildStatus(uint circuitcode, bool childstatus)
{
lock (m_agentCircuits)
if (m_agentCircuits.ContainsKey(circuitcode))
{
m_agentCircuits[circuitcode].child = childstatus;
}
}
public bool GetAgentChildStatus(uint circuitcode)
{
lock (m_agentCircuits)
if (m_agentCircuits.ContainsKey(circuitcode))
{
return m_agentCircuits[circuitcode].child;
}
return false;
}
}