From ced820bd5e0fe9c20309fe1a3cb91f9ee316ec22 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Sat, 3 Dec 2011 16:19:11 +0000
Subject: Improve locking in AgentCircuitManager
---
OpenSim/Framework/AgentCircuitManager.cs | 66 ++++++++++++++++++++------------
1 file changed, 41 insertions(+), 25 deletions(-)
(limited to 'OpenSim/Framework/AgentCircuitManager.cs')
diff --git a/OpenSim/Framework/AgentCircuitManager.cs b/OpenSim/Framework/AgentCircuitManager.cs
index a59bcfa..b6e48b4 100644
--- a/OpenSim/Framework/AgentCircuitManager.cs
+++ b/OpenSim/Framework/AgentCircuitManager.cs
@@ -38,6 +38,9 @@ namespace OpenSim.Framework
///
/// Agent circuits indexed by circuit code.
///
+ ///
+ /// We lock this for operations both on this dictionary and on m_agentCircuitsByUUID
+ ///
private Dictionary m_agentCircuits = new Dictionary();
///
@@ -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)
{
- validcircuit = m_agentCircuits[circuitcode];
+ 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;
}
///
@@ -129,17 +136,24 @@ namespace OpenSim.Framework
}
}
}
+
public AgentCircuitData GetAgentCircuitData(uint circuitCode)
{
AgentCircuitData agentCircuit = null;
- m_agentCircuits.TryGetValue(circuitCode, out agentCircuit);
+
+ lock (m_agentCircuits)
+ m_agentCircuits.TryGetValue(circuitCode, out agentCircuit);
+
return agentCircuit;
}
public AgentCircuitData GetAgentCircuitData(UUID agentID)
{
AgentCircuitData agentCircuit = null;
- m_agentCircuitsByUUID.TryGetValue(agentID, out agentCircuit);
+
+ lock (m_agentCircuits)
+ m_agentCircuitsByUUID.TryGetValue(agentID, out agentCircuit);
+
return agentCircuit;
}
@@ -149,23 +163,26 @@ namespace OpenSim.Framework
///
public Dictionary GetAgentCircuits()
{
- lock (m_agentCircuitsByUUID)
+ lock (m_agentCircuits)
return new Dictionary(m_agentCircuitsByUUID);
}
public void UpdateAgentData(AgentCircuitData agentData)
{
- if (m_agentCircuits.ContainsKey((uint) agentData.circuitcode))
+ lock (m_agentCircuits)
{
- m_agentCircuits[(uint) agentData.circuitcode].firstname = agentData.firstname;
- m_agentCircuits[(uint) agentData.circuitcode].lastname = agentData.lastname;
- m_agentCircuits[(uint) agentData.circuitcode].startpos = agentData.startpos;
+ if (m_agentCircuits.ContainsKey((uint) agentData.circuitcode))
+ {
+ m_agentCircuits[(uint) agentData.circuitcode].firstname = agentData.firstname;
+ m_agentCircuits[(uint) agentData.circuitcode].lastname = agentData.lastname;
+ m_agentCircuits[(uint) agentData.circuitcode].startpos = agentData.startpos;
- // Updated for when we don't know them before calling Scene.NewUserConnection
- m_agentCircuits[(uint) agentData.circuitcode].SecureSessionID = agentData.SecureSessionID;
- m_agentCircuits[(uint) agentData.circuitcode].SessionID = agentData.SessionID;
+ // Updated for when we don't know them before calling Scene.NewUserConnection
+ m_agentCircuits[(uint) agentData.circuitcode].SecureSessionID = agentData.SecureSessionID;
+ m_agentCircuits[(uint) agentData.circuitcode].SessionID = agentData.SessionID;
- // m_log.Debug("update user start pos is " + agentData.startpos.X + " , " + agentData.startpos.Y + " , " + agentData.startpos.Z);
+ // m_log.Debug("update user start pos is " + agentData.startpos.X + " , " + agentData.startpos.Y + " , " + agentData.startpos.Z);
+ }
}
}
@@ -189,25 +206,24 @@ namespace OpenSim.Framework
return true;
}
}
- return false;
+ return false;
}
public void UpdateAgentChildStatus(uint circuitcode, bool childstatus)
{
- if (m_agentCircuits.ContainsKey(circuitcode))
- {
- m_agentCircuits[circuitcode].child = childstatus;
- }
+ lock (m_agentCircuits)
+ if (m_agentCircuits.ContainsKey(circuitcode))
+ m_agentCircuits[circuitcode].child = childstatus;
}
public bool GetAgentChildStatus(uint circuitcode)
{
- if (m_agentCircuits.ContainsKey(circuitcode))
- {
- return m_agentCircuits[circuitcode].child;
- }
+ lock (m_agentCircuits)
+ if (m_agentCircuits.ContainsKey(circuitcode))
+ return m_agentCircuits[circuitcode].child;
+
return false;
}
}
-}
+}
\ No newline at end of file
--
cgit v1.1