If the entire simulator is shutting down then don't bother to unload the scripts from the appdomain in XEngine.

All the other actions (script state save, etc.) still occur.
This makes shutdown where there are many scripts vastly quicker.
0.7.2-post-fixes
Justin Clark-Casey (justincc) 2011-11-17 21:03:08 +00:00
parent 1e69845869
commit 8c0d8e72aa
2 changed files with 35 additions and 17 deletions

View File

@ -98,9 +98,10 @@ namespace OpenSim.Region.Framework.Scenes
public event OnPluginConsoleDelegate OnPluginConsole; public event OnPluginConsoleDelegate OnPluginConsole;
public delegate void OnShutdownDelegate(); /// <summary>
/// Triggered when the entire simulator is shutdown.
public event OnShutdownDelegate OnShutdown; /// </summary>
public event Action OnShutdown;
public delegate void ObjectDeGrabDelegate(uint localID, uint originalID, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs); public delegate void ObjectDeGrabDelegate(uint localID, uint originalID, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs);
public delegate void ScriptResetDelegate(uint localID, UUID itemID); public delegate void ScriptResetDelegate(uint localID, UUID itemID);
@ -113,9 +114,14 @@ namespace OpenSim.Region.Framework.Scenes
public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest; public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest;
public delegate void SceneShuttingDownDelegate(Scene scene); /// <summary>
/// Triggered when an individual scene is shutdown.
public event SceneShuttingDownDelegate OnSceneShuttingDown; /// </summary>
/// <remarks>
/// This does not automatically mean that the entire simulator is shutting down. Listen to OnShutdown for that
/// notification.
/// </remarks>
public event Action<Scene> OnSceneShuttingDown;
/// <summary> /// <summary>
/// Fired when an object is touched/grabbed. /// Fired when an object is touched/grabbed.
@ -864,10 +870,10 @@ namespace OpenSim.Region.Framework.Scenes
public void TriggerShutdown() public void TriggerShutdown()
{ {
OnShutdownDelegate handlerShutdown = OnShutdown; Action handlerShutdown = OnShutdown;
if (handlerShutdown != null) if (handlerShutdown != null)
{ {
foreach (OnShutdownDelegate d in handlerShutdown.GetInvocationList()) foreach (Action d in handlerShutdown.GetInvocationList())
{ {
try try
{ {
@ -2207,10 +2213,10 @@ namespace OpenSim.Region.Framework.Scenes
public void TriggerSceneShuttingDown(Scene s) public void TriggerSceneShuttingDown(Scene s)
{ {
SceneShuttingDownDelegate handler = OnSceneShuttingDown; Action<Scene> handler = OnSceneShuttingDown;
if (handler != null) if (handler != null)
{ {
foreach (SceneShuttingDownDelegate d in handler.GetInvocationList()) foreach (Action<Scene> d in handler.GetInvocationList())
{ {
try try
{ {

View File

@ -90,6 +90,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
private bool m_KillTimedOutScripts; private bool m_KillTimedOutScripts;
private string m_ScriptEnginesPath = null; private string m_ScriptEnginesPath = null;
/// <summary>
/// Is the entire simulator in the process of shutting down?
/// </summary>
private bool m_SimulatorShuttingDown;
private static List<XEngine> m_ScriptEngines = private static List<XEngine> m_ScriptEngines =
new List<XEngine>(); new List<XEngine>();
@ -470,17 +475,22 @@ namespace OpenSim.Region.ScriptEngine.XEngine
// //
instance.DestroyScriptInstance(); instance.DestroyScriptInstance();
// Unload scripts and app domains // Unload scripts and app domains.
// Must be done explicitly because they have infinite // Must be done explicitly because they have infinite
// lifetime // lifetime.
// // However, don't bother to do this if the simulator is shutting
m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); // down since it takes a long time with many scripts.
if (m_DomainScripts[instance.AppDomain].Count == 0) if (!m_SimulatorShuttingDown)
{ {
m_DomainScripts.Remove(instance.AppDomain); m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
UnloadAppDomain(instance.AppDomain); if (m_DomainScripts[instance.AppDomain].Count == 0)
{
m_DomainScripts.Remove(instance.AppDomain);
UnloadAppDomain(instance.AppDomain);
}
} }
} }
m_Scripts.Clear(); m_Scripts.Clear();
m_PrimObjects.Clear(); m_PrimObjects.Clear();
m_Assemblies.Clear(); m_Assemblies.Clear();
@ -1428,6 +1438,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
public void OnShutdown() public void OnShutdown()
{ {
m_SimulatorShuttingDown = true;
List<IScriptInstance> instances = new List<IScriptInstance>(); List<IScriptInstance> instances = new List<IScriptInstance>();
lock (m_Scripts) lock (m_Scripts)