From 76f46b25454c0c9376130a59cc1b766c0d105dd0 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Sat, 6 Aug 2011 01:15:49 +0100 Subject: [PATCH] Do proper locking of m_localScenes list in SceneManager --- .../Region/Framework/Scenes/SceneManager.cs | 233 +++++++++++------- .../HGInstantMessageService.cs | 7 +- 2 files changed, 143 insertions(+), 97 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs index 86ba2aa536..069367db8f 100644 --- a/OpenSim/Region/Framework/Scenes/SceneManager.cs +++ b/OpenSim/Region/Framework/Scenes/SceneManager.cs @@ -47,12 +47,12 @@ namespace OpenSim.Region.Framework.Scenes public event RestartSim OnRestartSim; - private readonly List m_localScenes; + private readonly List m_localScenes = new List(); private Scene m_currentScene = null; public List Scenes { - get { return m_localScenes; } + get { return new List(m_localScenes); } } public Scene CurrentScene @@ -66,13 +66,12 @@ namespace OpenSim.Region.Framework.Scenes { if (m_currentScene == null) { - if (m_localScenes.Count > 0) + lock (m_localScenes) { - return m_localScenes[0]; - } - else - { - return null; + if (m_localScenes.Count > 0) + return m_localScenes[0]; + else + return null; } } else @@ -82,26 +81,25 @@ namespace OpenSim.Region.Framework.Scenes } } - public SceneManager() - { - m_localScenes = new List(); - } - public void Close() { // collect known shared modules in sharedModules Dictionary sharedModules = new Dictionary(); - for (int i = 0; i < m_localScenes.Count; i++) + + lock (m_localScenes) { - // extract known shared modules from scene - foreach (string k in m_localScenes[i].Modules.Keys) + for (int i = 0; i < m_localScenes.Count; i++) { - if (m_localScenes[i].Modules[k].IsSharedModule && - !sharedModules.ContainsKey(k)) - sharedModules[k] = m_localScenes[i].Modules[k]; + // extract known shared modules from scene + foreach (string k in m_localScenes[i].Modules.Keys) + { + if (m_localScenes[i].Modules[k].IsSharedModule && + !sharedModules.ContainsKey(k)) + sharedModules[k] = m_localScenes[i].Modules[k]; + } + // close scene/region + m_localScenes[i].Close(); } - // close scene/region - m_localScenes[i].Close(); } // all regions/scenes are now closed, we can now safely @@ -114,13 +112,16 @@ namespace OpenSim.Region.Framework.Scenes public void Close(Scene cscene) { - if (m_localScenes.Contains(cscene)) + lock (m_localScenes) { - for (int i = 0; i < m_localScenes.Count; i++) + if (m_localScenes.Contains(cscene)) { - if (m_localScenes[i].Equals(cscene)) + for (int i = 0; i < m_localScenes.Count; i++) { - m_localScenes[i].Close(); + if (m_localScenes[i].Equals(cscene)) + { + m_localScenes[i].Close(); + } } } } @@ -129,27 +130,33 @@ namespace OpenSim.Region.Framework.Scenes public void Add(Scene scene) { scene.OnRestart += HandleRestart; - m_localScenes.Add(scene); + + lock (m_localScenes) + m_localScenes.Add(scene); } public void HandleRestart(RegionInfo rdata) { m_log.Error("[SCENEMANAGER]: Got Restart message for region:" + rdata.RegionName + " Sending up to main"); int RegionSceneElement = -1; - for (int i = 0; i < m_localScenes.Count; i++) + + lock (m_localScenes) { - if (rdata.RegionName == m_localScenes[i].RegionInfo.RegionName) + for (int i = 0; i < m_localScenes.Count; i++) { - RegionSceneElement = i; + if (rdata.RegionName == m_localScenes[i].RegionInfo.RegionName) + { + RegionSceneElement = i; + } } - } - // Now we make sure the region is no longer known about by the SceneManager - // Prevents duplicates. + // Now we make sure the region is no longer known about by the SceneManager + // Prevents duplicates. - if (RegionSceneElement >= 0) - { - m_localScenes.RemoveAt(RegionSceneElement); + if (RegionSceneElement >= 0) + { + m_localScenes.RemoveAt(RegionSceneElement); + } } // Send signal to main that we're restarting this sim. @@ -160,28 +167,32 @@ namespace OpenSim.Region.Framework.Scenes { RegionInfo Result = null; - for (int i = 0; i < m_localScenes.Count; i++) - { - if (m_localScenes[i].RegionInfo.RegionHandle == regionHandle) - { - // Inform other regions to tell their avatar about me - Result = m_localScenes[i].RegionInfo; - } - } - if (Result != null) + lock (m_localScenes) { for (int i = 0; i < m_localScenes.Count; i++) { - if (m_localScenes[i].RegionInfo.RegionHandle != regionHandle) + if (m_localScenes[i].RegionInfo.RegionHandle == regionHandle) { // Inform other regions to tell their avatar about me - //m_localScenes[i].OtherRegionUp(Result); + Result = m_localScenes[i].RegionInfo; } } - } - else - { - m_log.Error("[REGION]: Unable to notify Other regions of this Region coming up"); + + if (Result != null) + { + for (int i = 0; i < m_localScenes.Count; i++) + { + if (m_localScenes[i].RegionInfo.RegionHandle != regionHandle) + { + // Inform other regions to tell their avatar about me + //m_localScenes[i].OtherRegionUp(Result); + } + } + } + else + { + m_log.Error("[REGION]: Unable to notify Other regions of this Region coming up"); + } } } @@ -285,7 +296,8 @@ namespace OpenSim.Region.Framework.Scenes { if (m_currentScene == null) { - m_localScenes.ForEach(func); + lock (m_localScenes) + m_localScenes.ForEach(func); } else { @@ -314,12 +326,15 @@ namespace OpenSim.Region.Framework.Scenes } else { - foreach (Scene scene in m_localScenes) + lock (m_localScenes) { - if (String.Compare(scene.RegionInfo.RegionName, regionName, true) == 0) + foreach (Scene scene in m_localScenes) { - m_currentScene = scene; - return true; + if (String.Compare(scene.RegionInfo.RegionName, regionName, true) == 0) + { + m_currentScene = scene; + return true; + } } } @@ -331,12 +346,15 @@ namespace OpenSim.Region.Framework.Scenes { m_log.Debug("Searching for Region: '" + regionID + "'"); - foreach (Scene scene in m_localScenes) + lock (m_localScenes) { - if (scene.RegionInfo.RegionID == regionID) + foreach (Scene scene in m_localScenes) { - m_currentScene = scene; - return true; + if (scene.RegionInfo.RegionID == regionID) + { + m_currentScene = scene; + return true; + } } } @@ -345,26 +363,33 @@ namespace OpenSim.Region.Framework.Scenes public bool TryGetScene(string regionName, out Scene scene) { - foreach (Scene mscene in m_localScenes) + lock (m_localScenes) { - if (String.Compare(mscene.RegionInfo.RegionName, regionName, true) == 0) + foreach (Scene mscene in m_localScenes) { - scene = mscene; - return true; + if (String.Compare(mscene.RegionInfo.RegionName, regionName, true) == 0) + { + scene = mscene; + return true; + } } } + scene = null; return false; } public bool TryGetScene(UUID regionID, out Scene scene) { - foreach (Scene mscene in m_localScenes) + lock (m_localScenes) { - if (mscene.RegionInfo.RegionID == regionID) + foreach (Scene mscene in m_localScenes) { - scene = mscene; - return true; + if (mscene.RegionInfo.RegionID == regionID) + { + scene = mscene; + return true; + } } } @@ -374,13 +399,16 @@ namespace OpenSim.Region.Framework.Scenes public bool TryGetScene(uint locX, uint locY, out Scene scene) { - foreach (Scene mscene in m_localScenes) + lock (m_localScenes) { - if (mscene.RegionInfo.RegionLocX == locX && - mscene.RegionInfo.RegionLocY == locY) + foreach (Scene mscene in m_localScenes) { - scene = mscene; - return true; + if (mscene.RegionInfo.RegionLocX == locX && + mscene.RegionInfo.RegionLocY == locY) + { + scene = mscene; + return true; + } } } @@ -390,13 +418,16 @@ namespace OpenSim.Region.Framework.Scenes public bool TryGetScene(IPEndPoint ipEndPoint, out Scene scene) { - foreach (Scene mscene in m_localScenes) + lock (m_localScenes) { - if ((mscene.RegionInfo.InternalEndPoint.Equals(ipEndPoint.Address)) && - (mscene.RegionInfo.InternalEndPoint.Port == ipEndPoint.Port)) + foreach (Scene mscene in m_localScenes) { - scene = mscene; - return true; + if ((mscene.RegionInfo.InternalEndPoint.Equals(ipEndPoint.Address)) && + (mscene.RegionInfo.InternalEndPoint.Port == ipEndPoint.Port)) + { + scene = mscene; + return true; + } } } @@ -465,11 +496,14 @@ namespace OpenSim.Region.Framework.Scenes public RegionInfo GetRegionInfo(UUID regionID) { - foreach (Scene scene in m_localScenes) + lock (m_localScenes) { - if (scene.RegionInfo.RegionID == regionID) + foreach (Scene scene in m_localScenes) { - return scene.RegionInfo; + if (scene.RegionInfo.RegionID == regionID) + { + return scene.RegionInfo; + } } } @@ -488,11 +522,14 @@ namespace OpenSim.Region.Framework.Scenes public bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar) { - foreach (Scene scene in m_localScenes) + lock (m_localScenes) { - if (scene.TryGetScenePresence(avatarId, out avatar)) + foreach (Scene scene in m_localScenes) { - return true; + if (scene.TryGetScenePresence(avatarId, out avatar)) + { + return true; + } } } @@ -503,12 +540,16 @@ namespace OpenSim.Region.Framework.Scenes public bool TryGetAvatarsScene(UUID avatarId, out Scene scene) { ScenePresence avatar = null; - foreach (Scene mScene in m_localScenes) + + lock (m_localScenes) { - if (mScene.TryGetScenePresence(avatarId, out avatar)) + foreach (Scene mScene in m_localScenes) { - scene = mScene; - return true; + if (mScene.TryGetScenePresence(avatarId, out avatar)) + { + scene = mScene; + return true; + } } } @@ -518,17 +559,22 @@ namespace OpenSim.Region.Framework.Scenes public void CloseScene(Scene scene) { - m_localScenes.Remove(scene); + lock (m_localScenes) + m_localScenes.Remove(scene); + scene.Close(); } public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar) { - foreach (Scene scene in m_localScenes) + lock (m_localScenes) { - if (scene.TryGetAvatarByName(avatarName, out avatar)) + foreach (Scene scene in m_localScenes) { - return true; + if (scene.TryGetAvatarByName(avatarName, out avatar)) + { + return true; + } } } @@ -538,7 +584,8 @@ namespace OpenSim.Region.Framework.Scenes public void ForEachScene(Action action) { - m_localScenes.ForEach(action); + lock (m_localScenes) + m_localScenes.ForEach(action); } } -} +} \ No newline at end of file diff --git a/OpenSim/Services/HypergridService/HGInstantMessageService.cs b/OpenSim/Services/HypergridService/HGInstantMessageService.cs index bb31fc951e..0d59636b72 100644 --- a/OpenSim/Services/HypergridService/HGInstantMessageService.cs +++ b/OpenSim/Services/HypergridService/HGInstantMessageService.cs @@ -95,7 +95,6 @@ namespace OpenSim.Services.HypergridService m_InGatekeeper = serverConfig.GetBoolean("InGatekeeper", false); m_log.DebugFormat("[HG IM SERVICE]: Starting... InRobust? {0}", m_InGatekeeper); - if (gridService == string.Empty || presenceService == string.Empty) throw new Exception(String.Format("Incomplete specifications, InstantMessage Service cannot function.")); @@ -120,7 +119,7 @@ namespace OpenSim.Services.HypergridService public bool IncomingInstantMessage(GridInstantMessage im) { - m_log.DebugFormat("[HG IM SERVICE]: Received message from {0} to {1}", im.fromAgentID, im.toAgentID); +// m_log.DebugFormat("[HG IM SERVICE]: Received message from {0} to {1}", im.fromAgentID, im.toAgentID); UUID toAgentID = new UUID(im.toAgentID); bool success = false; @@ -142,7 +141,7 @@ namespace OpenSim.Services.HypergridService public bool OutgoingInstantMessage(GridInstantMessage im, string url, bool foreigner) { - m_log.DebugFormat("[HG IM SERVICE]: Sending message from {0} to {1}@{2}", im.fromAgentID, im.toAgentID, url); +// m_log.DebugFormat("[HG IM SERVICE]: Sending message from {0} to {1}@{2}", im.fromAgentID, im.toAgentID, url); if (url != string.Empty) return TrySendInstantMessage(im, url, true, foreigner); else @@ -333,7 +332,7 @@ namespace OpenSim.Services.HypergridService if (m_RestURL != string.Empty && (im.offline != 0) && (!im.fromGroup || (im.fromGroup && m_ForwardOfflineGroupMessages))) { - m_log.DebugFormat("[HG IM SERVICE]: Message saved"); +// m_log.DebugFormat("[HG IM SERVICE]: Message saved"); return SynchronousRestObjectRequester.MakeRequest( "POST", m_RestURL + "/SaveMessage/", im);