Do proper locking of m_localScenes list in SceneManager

bulletsim
Justin Clark-Casey (justincc) 2011-08-06 01:15:49 +01:00
parent dad1d6df18
commit 76f46b2545
2 changed files with 143 additions and 97 deletions

View File

@ -47,12 +47,12 @@ namespace OpenSim.Region.Framework.Scenes
public event RestartSim OnRestartSim; public event RestartSim OnRestartSim;
private readonly List<Scene> m_localScenes; private readonly List<Scene> m_localScenes = new List<Scene>();
private Scene m_currentScene = null; private Scene m_currentScene = null;
public List<Scene> Scenes public List<Scene> Scenes
{ {
get { return m_localScenes; } get { return new List<Scene>(m_localScenes); }
} }
public Scene CurrentScene public Scene CurrentScene
@ -65,13 +65,12 @@ namespace OpenSim.Region.Framework.Scenes
get get
{ {
if (m_currentScene == null) if (m_currentScene == null)
{
lock (m_localScenes)
{ {
if (m_localScenes.Count > 0) if (m_localScenes.Count > 0)
{
return m_localScenes[0]; return m_localScenes[0];
}
else else
{
return null; return null;
} }
} }
@ -82,15 +81,13 @@ namespace OpenSim.Region.Framework.Scenes
} }
} }
public SceneManager()
{
m_localScenes = new List<Scene>();
}
public void Close() public void Close()
{ {
// collect known shared modules in sharedModules // collect known shared modules in sharedModules
Dictionary<string, IRegionModule> sharedModules = new Dictionary<string, IRegionModule>(); Dictionary<string, IRegionModule> sharedModules = new Dictionary<string, IRegionModule>();
lock (m_localScenes)
{
for (int i = 0; i < m_localScenes.Count; i++) for (int i = 0; i < m_localScenes.Count; i++)
{ {
// extract known shared modules from scene // extract known shared modules from scene
@ -103,6 +100,7 @@ namespace OpenSim.Region.Framework.Scenes
// close scene/region // close scene/region
m_localScenes[i].Close(); m_localScenes[i].Close();
} }
}
// all regions/scenes are now closed, we can now safely // all regions/scenes are now closed, we can now safely
// close all shared modules // close all shared modules
@ -113,6 +111,8 @@ namespace OpenSim.Region.Framework.Scenes
} }
public void Close(Scene cscene) public void Close(Scene cscene)
{
lock (m_localScenes)
{ {
if (m_localScenes.Contains(cscene)) if (m_localScenes.Contains(cscene))
{ {
@ -125,10 +125,13 @@ namespace OpenSim.Region.Framework.Scenes
} }
} }
} }
}
public void Add(Scene scene) public void Add(Scene scene)
{ {
scene.OnRestart += HandleRestart; scene.OnRestart += HandleRestart;
lock (m_localScenes)
m_localScenes.Add(scene); m_localScenes.Add(scene);
} }
@ -136,6 +139,9 @@ namespace OpenSim.Region.Framework.Scenes
{ {
m_log.Error("[SCENEMANAGER]: Got Restart message for region:" + rdata.RegionName + " Sending up to main"); m_log.Error("[SCENEMANAGER]: Got Restart message for region:" + rdata.RegionName + " Sending up to main");
int RegionSceneElement = -1; int RegionSceneElement = -1;
lock (m_localScenes)
{
for (int i = 0; i < m_localScenes.Count; i++) for (int i = 0; i < m_localScenes.Count; i++)
{ {
if (rdata.RegionName == m_localScenes[i].RegionInfo.RegionName) if (rdata.RegionName == m_localScenes[i].RegionInfo.RegionName)
@ -151,6 +157,7 @@ namespace OpenSim.Region.Framework.Scenes
{ {
m_localScenes.RemoveAt(RegionSceneElement); m_localScenes.RemoveAt(RegionSceneElement);
} }
}
// Send signal to main that we're restarting this sim. // Send signal to main that we're restarting this sim.
OnRestartSim(rdata); OnRestartSim(rdata);
@ -160,6 +167,8 @@ namespace OpenSim.Region.Framework.Scenes
{ {
RegionInfo Result = null; RegionInfo Result = null;
lock (m_localScenes)
{
for (int i = 0; i < m_localScenes.Count; i++) for (int i = 0; i < m_localScenes.Count; i++)
{ {
if (m_localScenes[i].RegionInfo.RegionHandle == regionHandle) if (m_localScenes[i].RegionInfo.RegionHandle == regionHandle)
@ -168,6 +177,7 @@ namespace OpenSim.Region.Framework.Scenes
Result = m_localScenes[i].RegionInfo; Result = m_localScenes[i].RegionInfo;
} }
} }
if (Result != null) if (Result != null)
{ {
for (int i = 0; i < m_localScenes.Count; i++) for (int i = 0; i < m_localScenes.Count; i++)
@ -184,6 +194,7 @@ namespace OpenSim.Region.Framework.Scenes
m_log.Error("[REGION]: Unable to notify Other regions of this Region coming up"); m_log.Error("[REGION]: Unable to notify Other regions of this Region coming up");
} }
} }
}
/// <summary> /// <summary>
/// Save the prims in the current scene to an xml file in OpenSimulator's original 'xml' format /// Save the prims in the current scene to an xml file in OpenSimulator's original 'xml' format
@ -285,6 +296,7 @@ namespace OpenSim.Region.Framework.Scenes
{ {
if (m_currentScene == null) if (m_currentScene == null)
{ {
lock (m_localScenes)
m_localScenes.ForEach(func); m_localScenes.ForEach(func);
} }
else else
@ -313,6 +325,8 @@ namespace OpenSim.Region.Framework.Scenes
return true; return true;
} }
else else
{
lock (m_localScenes)
{ {
foreach (Scene scene in m_localScenes) foreach (Scene scene in m_localScenes)
{ {
@ -322,6 +336,7 @@ namespace OpenSim.Region.Framework.Scenes
return true; return true;
} }
} }
}
return false; return false;
} }
@ -331,6 +346,8 @@ namespace OpenSim.Region.Framework.Scenes
{ {
m_log.Debug("Searching for Region: '" + regionID + "'"); m_log.Debug("Searching for Region: '" + regionID + "'");
lock (m_localScenes)
{
foreach (Scene scene in m_localScenes) foreach (Scene scene in m_localScenes)
{ {
if (scene.RegionInfo.RegionID == regionID) if (scene.RegionInfo.RegionID == regionID)
@ -339,11 +356,14 @@ namespace OpenSim.Region.Framework.Scenes
return true; return true;
} }
} }
}
return false; return false;
} }
public bool TryGetScene(string regionName, out Scene scene) public bool TryGetScene(string regionName, out Scene scene)
{
lock (m_localScenes)
{ {
foreach (Scene mscene in m_localScenes) foreach (Scene mscene in m_localScenes)
{ {
@ -353,11 +373,15 @@ namespace OpenSim.Region.Framework.Scenes
return true; return true;
} }
} }
}
scene = null; scene = null;
return false; return false;
} }
public bool TryGetScene(UUID regionID, out Scene scene) public bool TryGetScene(UUID regionID, out Scene scene)
{
lock (m_localScenes)
{ {
foreach (Scene mscene in m_localScenes) foreach (Scene mscene in m_localScenes)
{ {
@ -367,12 +391,15 @@ namespace OpenSim.Region.Framework.Scenes
return true; return true;
} }
} }
}
scene = null; scene = null;
return false; return false;
} }
public bool TryGetScene(uint locX, uint locY, out Scene scene) public bool TryGetScene(uint locX, uint locY, out Scene scene)
{
lock (m_localScenes)
{ {
foreach (Scene mscene in m_localScenes) foreach (Scene mscene in m_localScenes)
{ {
@ -383,12 +410,15 @@ namespace OpenSim.Region.Framework.Scenes
return true; return true;
} }
} }
}
scene = null; scene = null;
return false; return false;
} }
public bool TryGetScene(IPEndPoint ipEndPoint, out Scene scene) public bool TryGetScene(IPEndPoint ipEndPoint, out Scene scene)
{
lock (m_localScenes)
{ {
foreach (Scene mscene in m_localScenes) foreach (Scene mscene in m_localScenes)
{ {
@ -399,6 +429,7 @@ namespace OpenSim.Region.Framework.Scenes
return true; return true;
} }
} }
}
scene = null; scene = null;
return false; return false;
@ -464,6 +495,8 @@ namespace OpenSim.Region.Framework.Scenes
} }
public RegionInfo GetRegionInfo(UUID regionID) public RegionInfo GetRegionInfo(UUID regionID)
{
lock (m_localScenes)
{ {
foreach (Scene scene in m_localScenes) foreach (Scene scene in m_localScenes)
{ {
@ -472,6 +505,7 @@ namespace OpenSim.Region.Framework.Scenes
return scene.RegionInfo; return scene.RegionInfo;
} }
} }
}
return null; return null;
} }
@ -487,6 +521,8 @@ namespace OpenSim.Region.Framework.Scenes
} }
public bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar) public bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar)
{
lock (m_localScenes)
{ {
foreach (Scene scene in m_localScenes) foreach (Scene scene in m_localScenes)
{ {
@ -495,6 +531,7 @@ namespace OpenSim.Region.Framework.Scenes
return true; return true;
} }
} }
}
avatar = null; avatar = null;
return false; return false;
@ -503,6 +540,9 @@ namespace OpenSim.Region.Framework.Scenes
public bool TryGetAvatarsScene(UUID avatarId, out Scene scene) public bool TryGetAvatarsScene(UUID avatarId, out Scene scene)
{ {
ScenePresence avatar = null; ScenePresence avatar = null;
lock (m_localScenes)
{
foreach (Scene mScene in m_localScenes) foreach (Scene mScene in m_localScenes)
{ {
if (mScene.TryGetScenePresence(avatarId, out avatar)) if (mScene.TryGetScenePresence(avatarId, out avatar))
@ -511,6 +551,7 @@ namespace OpenSim.Region.Framework.Scenes
return true; return true;
} }
} }
}
scene = null; scene = null;
return false; return false;
@ -518,11 +559,15 @@ namespace OpenSim.Region.Framework.Scenes
public void CloseScene(Scene scene) public void CloseScene(Scene scene)
{ {
lock (m_localScenes)
m_localScenes.Remove(scene); m_localScenes.Remove(scene);
scene.Close(); scene.Close();
} }
public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar) public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
{
lock (m_localScenes)
{ {
foreach (Scene scene in m_localScenes) foreach (Scene scene in m_localScenes)
{ {
@ -531,6 +576,7 @@ namespace OpenSim.Region.Framework.Scenes
return true; return true;
} }
} }
}
avatar = null; avatar = null;
return false; return false;
@ -538,6 +584,7 @@ namespace OpenSim.Region.Framework.Scenes
public void ForEachScene(Action<Scene> action) public void ForEachScene(Action<Scene> action)
{ {
lock (m_localScenes)
m_localScenes.ForEach(action); m_localScenes.ForEach(action);
} }
} }

View File

@ -95,7 +95,6 @@ namespace OpenSim.Services.HypergridService
m_InGatekeeper = serverConfig.GetBoolean("InGatekeeper", false); m_InGatekeeper = serverConfig.GetBoolean("InGatekeeper", false);
m_log.DebugFormat("[HG IM SERVICE]: Starting... InRobust? {0}", m_InGatekeeper); m_log.DebugFormat("[HG IM SERVICE]: Starting... InRobust? {0}", m_InGatekeeper);
if (gridService == string.Empty || presenceService == string.Empty) if (gridService == string.Empty || presenceService == string.Empty)
throw new Exception(String.Format("Incomplete specifications, InstantMessage Service cannot function.")); throw new Exception(String.Format("Incomplete specifications, InstantMessage Service cannot function."));
@ -120,7 +119,7 @@ namespace OpenSim.Services.HypergridService
public bool IncomingInstantMessage(GridInstantMessage im) 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); UUID toAgentID = new UUID(im.toAgentID);
bool success = false; bool success = false;
@ -142,7 +141,7 @@ namespace OpenSim.Services.HypergridService
public bool OutgoingInstantMessage(GridInstantMessage im, string url, bool foreigner) 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) if (url != string.Empty)
return TrySendInstantMessage(im, url, true, foreigner); return TrySendInstantMessage(im, url, true, foreigner);
else else
@ -333,7 +332,7 @@ namespace OpenSim.Services.HypergridService
if (m_RestURL != string.Empty && (im.offline != 0) if (m_RestURL != string.Empty && (im.offline != 0)
&& (!im.fromGroup || (im.fromGroup && m_ForwardOfflineGroupMessages))) && (!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<GridInstantMessage, bool>( return SynchronousRestObjectRequester.MakeRequest<GridInstantMessage, bool>(
"POST", m_RestURL + "/SaveMessage/", im); "POST", m_RestURL + "/SaveMessage/", im);