From c934901a056f142c49e6b449971fcaf59ff19d82 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 3 Dec 2011 16:11:47 +0000 Subject: Use GetAgentCircuits() to receive a copy of the AgentCircuitsByUUID dictionary rather than AgentCircuitManager.AgentCircuits directly in "show circuits" to avoid enumeration exceptions --- OpenSim/Framework/AgentCircuitManager.cs | 91 +++++++++++++++++++------------- 1 file changed, 54 insertions(+), 37 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/AgentCircuitManager.cs b/OpenSim/Framework/AgentCircuitManager.cs index 1ce8c34..a59bcfa 100644 --- a/OpenSim/Framework/AgentCircuitManager.cs +++ b/OpenSim/Framework/AgentCircuitManager.cs @@ -35,15 +35,22 @@ namespace OpenSim.Framework /// public class AgentCircuitManager { - public Dictionary AgentCircuits = new Dictionary(); - public Dictionary AgentCircuitsByUUID = new Dictionary(); + /// + /// Agent circuits indexed by circuit code. + /// + private Dictionary m_agentCircuits = new Dictionary(); + + /// + /// Agent circuits indexed by agent UUID. + /// + private Dictionary m_agentCircuitsByUUID = new Dictionary(); public virtual AuthenticateResponse AuthenticateSession(UUID sessionID, UUID agentID, uint circuitcode) { AgentCircuitData validcircuit = null; - if (AgentCircuits.ContainsKey(circuitcode)) + if (m_agentCircuits.ContainsKey(circuitcode)) { - validcircuit = AgentCircuits[circuitcode]; + validcircuit = m_agentCircuits[circuitcode]; } AuthenticateResponse user = new AuthenticateResponse(); if (validcircuit == null) @@ -82,71 +89,81 @@ namespace OpenSim.Framework /// public virtual void AddNewCircuit(uint circuitCode, AgentCircuitData agentData) { - lock (AgentCircuits) + lock (m_agentCircuits) { - if (AgentCircuits.ContainsKey(circuitCode)) + if (m_agentCircuits.ContainsKey(circuitCode)) { - AgentCircuits[circuitCode] = agentData; - AgentCircuitsByUUID[agentData.AgentID] = agentData; + m_agentCircuits[circuitCode] = agentData; + m_agentCircuitsByUUID[agentData.AgentID] = agentData; } else { - AgentCircuits.Add(circuitCode, agentData); - AgentCircuitsByUUID[agentData.AgentID] = agentData; + m_agentCircuits.Add(circuitCode, agentData); + m_agentCircuitsByUUID[agentData.AgentID] = agentData; } } } public virtual void RemoveCircuit(uint circuitCode) { - lock (AgentCircuits) + lock (m_agentCircuits) { - if (AgentCircuits.ContainsKey(circuitCode)) + if (m_agentCircuits.ContainsKey(circuitCode)) { - UUID agentID = AgentCircuits[circuitCode].AgentID; - AgentCircuits.Remove(circuitCode); - AgentCircuitsByUUID.Remove(agentID); + UUID agentID = m_agentCircuits[circuitCode].AgentID; + m_agentCircuits.Remove(circuitCode); + m_agentCircuitsByUUID.Remove(agentID); } } } public virtual void RemoveCircuit(UUID agentID) { - lock (AgentCircuits) + lock (m_agentCircuits) { - if (AgentCircuitsByUUID.ContainsKey(agentID)) + if (m_agentCircuitsByUUID.ContainsKey(agentID)) { - uint circuitCode = AgentCircuitsByUUID[agentID].circuitcode; - AgentCircuits.Remove(circuitCode); - AgentCircuitsByUUID.Remove(agentID); + uint circuitCode = m_agentCircuitsByUUID[agentID].circuitcode; + m_agentCircuits.Remove(circuitCode); + m_agentCircuitsByUUID.Remove(agentID); } } } public AgentCircuitData GetAgentCircuitData(uint circuitCode) { AgentCircuitData agentCircuit = null; - AgentCircuits.TryGetValue(circuitCode, out agentCircuit); + m_agentCircuits.TryGetValue(circuitCode, out agentCircuit); return agentCircuit; } public AgentCircuitData GetAgentCircuitData(UUID agentID) { AgentCircuitData agentCircuit = null; - AgentCircuitsByUUID.TryGetValue(agentID, out agentCircuit); + m_agentCircuitsByUUID.TryGetValue(agentID, out agentCircuit); return agentCircuit; } + /// + /// Get all current agent circuits indexed by agent UUID. + /// + /// + public Dictionary GetAgentCircuits() + { + lock (m_agentCircuitsByUUID) + return new Dictionary(m_agentCircuitsByUUID); + } + public void UpdateAgentData(AgentCircuitData agentData) { - if (AgentCircuits.ContainsKey((uint) agentData.circuitcode)) + if (m_agentCircuits.ContainsKey((uint) agentData.circuitcode)) { - AgentCircuits[(uint) agentData.circuitcode].firstname = agentData.firstname; - AgentCircuits[(uint) agentData.circuitcode].lastname = agentData.lastname; - AgentCircuits[(uint) agentData.circuitcode].startpos = agentData.startpos; + 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 - AgentCircuits[(uint) agentData.circuitcode].SecureSessionID = agentData.SecureSessionID; - AgentCircuits[(uint) agentData.circuitcode].SessionID = agentData.SessionID; + 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); } @@ -159,16 +176,16 @@ namespace OpenSim.Framework /// public bool TryChangeCiruitCode(uint circuitcode, uint newcircuitcode) { - lock (AgentCircuits) + lock (m_agentCircuits) { - if (AgentCircuits.ContainsKey((uint)circuitcode) && !AgentCircuits.ContainsKey((uint)newcircuitcode)) + if (m_agentCircuits.ContainsKey((uint)circuitcode) && !m_agentCircuits.ContainsKey((uint)newcircuitcode)) { - AgentCircuitData agentData = AgentCircuits[(uint)circuitcode]; + AgentCircuitData agentData = m_agentCircuits[(uint)circuitcode]; agentData.circuitcode = newcircuitcode; - AgentCircuits.Remove((uint)circuitcode); - AgentCircuits.Add(newcircuitcode, agentData); + m_agentCircuits.Remove((uint)circuitcode); + m_agentCircuits.Add(newcircuitcode, agentData); return true; } } @@ -178,17 +195,17 @@ namespace OpenSim.Framework public void UpdateAgentChildStatus(uint circuitcode, bool childstatus) { - if (AgentCircuits.ContainsKey(circuitcode)) + if (m_agentCircuits.ContainsKey(circuitcode)) { - AgentCircuits[circuitcode].child = childstatus; + m_agentCircuits[circuitcode].child = childstatus; } } public bool GetAgentChildStatus(uint circuitcode) { - if (AgentCircuits.ContainsKey(circuitcode)) + if (m_agentCircuits.ContainsKey(circuitcode)) { - return AgentCircuits[circuitcode].child; + return m_agentCircuits[circuitcode].child; } return false; } -- cgit v1.1 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') 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 From 4919c6056022053f8632b030a06fd8f48ac02a8e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 3 Dec 2011 18:59:54 +0000 Subject: Add beginning of ScenePresenceAgentTests.TestCreateChildScenePresence() This required an option to be added to NullRegionData via ConnectionString for it to act as a non-static instance, so that regression tests (which only load this class once) don't get hopeless confused and complex to compensate. Normal standalone operation unaffected. --- OpenSim/Framework/Tests/AgentCircuitManagerTests.cs | 2 -- OpenSim/Framework/Tests/AnimationTests.cs | 2 -- 2 files changed, 4 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Tests/AgentCircuitManagerTests.cs b/OpenSim/Framework/Tests/AgentCircuitManagerTests.cs index 9615f1b..ae132c8 100644 --- a/OpenSim/Framework/Tests/AgentCircuitManagerTests.cs +++ b/OpenSim/Framework/Tests/AgentCircuitManagerTests.cs @@ -194,8 +194,6 @@ namespace OpenSim.Framework.Tests resp = agentCircuitManager.AuthenticateSession(SessionId2, AgentId2, circuitcode2); Assert.That(!resp.Authorised); - } - } } diff --git a/OpenSim/Framework/Tests/AnimationTests.cs b/OpenSim/Framework/Tests/AnimationTests.cs index aa4c6aa..967a355 100644 --- a/OpenSim/Framework/Tests/AnimationTests.cs +++ b/OpenSim/Framework/Tests/AnimationTests.cs @@ -87,8 +87,6 @@ namespace OpenSim.Framework.Tests anim4.SequenceNum = anim2.SequenceNum; Assert.That(anim4.ObjectID == objUUID2 && anim4.AnimID == animUUID2 && anim4.SequenceNum == 1, "void constructor and manual field population failed to set the properties correctly."); - - } } } \ No newline at end of file -- cgit v1.1