From c13bf719e1575ca8318c96caf10387a413a1a670 Mon Sep 17 00:00:00 2001 From: Homer Horwitz Date: Mon, 24 Nov 2008 20:43:16 +0000 Subject: - Evaluate config only once - Fixed some locking issues --- .../Avatar/InstantMessage/PresenceModule.cs | 56 ++++++++++++++-------- 1 file changed, 35 insertions(+), 21 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/PresenceModule.cs b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/PresenceModule.cs index 7b358c2..28ed991 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/PresenceModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/PresenceModule.cs @@ -58,20 +58,25 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage public void Initialise(Scene scene, IConfigSource config) { - IConfig cnf = config.Configs["Messaging"]; - if (cnf != null && cnf.GetString( - "PresenceModule", "PresenceModule") != - "PresenceModule") - return; + lock (m_Scenes) + { + // This is a shared module; Initialise will be called for every region on this server. + // Only check config once for the first region. + if (m_Scenes.Count == 0) + { + IConfig cnf = config.Configs["Messaging"]; + if (cnf != null && cnf.GetString( + "PresenceModule", "PresenceModule") != + "PresenceModule") + return; - cnf = config.Configs["Startup"]; - if (cnf != null) - m_Gridmode = cnf.GetBoolean("gridmode", false); + cnf = config.Configs["Startup"]; + if (cnf != null) + m_Gridmode = cnf.GetBoolean("gridmode", false); - m_Enabled = true; + m_Enabled = true; + } - lock (m_Scenes) - { if (m_Gridmode) NotifyMessageServerOfStartup(scene); @@ -122,27 +127,36 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage if (!(client.Scene is Scene)) return; - if (!(m_RootAgents.ContainsKey(client.AgentId))) - return; - Scene scene = (Scene)client.Scene; - if (m_RootAgents[client.AgentId] != scene) - return; - - m_RootAgents.Remove(client.AgentId); + // OnConnectionClosed can be called from several threads at once (with different client, of course) + // Concurrent access to m_RootAgents is prone to failure on multi-core/-processor systems without + // correct locking). + lock (m_RootAgents) + { + Scene rootScene; + if (!(m_RootAgents.TryGetValue(client.AgentId, out rootScene)) || scene != rootScene) + return; + m_RootAgents.Remove(client.AgentId); + } NotifyMessageServerOfAgentLeaving(client.AgentId, scene.RegionInfo.RegionID, scene.RegionInfo.RegionHandle); } public void OnSetRootAgentScene(UUID agentID, Scene scene) { - if (m_RootAgents.ContainsKey(agentID)) + // OnSetRootAgentScene can be called from several threads at once (with different agentID). + // Concurrent access to m_RootAgents is prone to failure on multi-core/-processor systems without + // correct locking). + lock (m_RootAgents) { - if (m_RootAgents[agentID] == scene) + Scene rootScene; + if (m_RootAgents.TryGetValue(agentID, out rootScene) && scene == rootScene) + { return; + } + m_RootAgents[agentID] = scene; } - m_RootAgents[agentID] = scene; NotifyMessageServerOfAgentLocation(agentID, scene.RegionInfo.RegionID, scene.RegionInfo.RegionHandle); } -- cgit v1.1