mirror of
https://github.com/opensim/opensim.git
synced 2026-08-04 16:22:50 +08:00
Implement co-operative script termination if termination comes during a script wait event (llSleep(), etc.)
This makes use of EventWaitHandles since various web references indicate that Thread.Interrupt() can also cause runtime instability.
If co-op termination is enabled, then termination sets the wait handle instead of waiting for a timeout before possibly aborting the thread.
This allows the script to cleanly terminate if it's in a llSleep/LL function delay or the next time it enters such a wait without any timeout period.
Co-op termination is not yet testable since checking for termination request within loops that never trigger a wait is not yet implemented.
This commit, unlike 1b5c41c, passes the wait handle as an extra parameter through IScript.Initialize() instead of passing IScriptInstance itself.
This commit is contained in:
@@ -83,9 +83,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
protected IScriptEngine m_ScriptEngine;
|
||||
protected SceneObjectPart m_host;
|
||||
|
||||
/// <summary>
|
||||
/// Used for script sleeps when we are using co-operative script termination.
|
||||
/// </summary>
|
||||
/// <remarks>null if co-operative script termination is not active</remarks>
|
||||
EventWaitHandle m_coopSleepHandle;
|
||||
|
||||
/// <summary>
|
||||
/// The item that hosts this script
|
||||
/// </summary>
|
||||
@@ -110,13 +117,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp.
|
||||
protected ISoundModule m_SoundModule = null;
|
||||
|
||||
public void Initialize(IScriptInstance scriptInstance)
|
||||
public void Initialize(
|
||||
IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, EventWaitHandle coopSleepHandle)
|
||||
{
|
||||
m_ScriptEngine = scriptInstance.Engine;
|
||||
m_host = scriptInstance.Part;
|
||||
m_item = scriptInstance.ScriptTask;
|
||||
m_ScriptEngine = scriptEngine;
|
||||
m_host = host;
|
||||
m_item = item;
|
||||
m_coopSleepHandle = coopSleepHandle;
|
||||
|
||||
LoadLimits(); // read script limits from config.
|
||||
LoadConfig();
|
||||
|
||||
m_TransferModule =
|
||||
m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
|
||||
@@ -129,7 +138,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
/// <summary>
|
||||
/// Load configuration items that affect script, object and run-time behavior. */
|
||||
/// </summary>
|
||||
private void LoadLimits()
|
||||
private void LoadConfig()
|
||||
{
|
||||
m_ScriptDelayFactor =
|
||||
m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
|
||||
@@ -175,7 +184,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
delay = (int)((float)delay * m_ScriptDelayFactor);
|
||||
if (delay == 0)
|
||||
return;
|
||||
System.Threading.Thread.Sleep(delay);
|
||||
|
||||
Sleep(delay);
|
||||
}
|
||||
|
||||
protected virtual void Sleep(int delay)
|
||||
{
|
||||
if (m_coopSleepHandle == null)
|
||||
System.Threading.Thread.Sleep(delay);
|
||||
else if (m_coopSleepHandle.WaitOne(delay))
|
||||
throw new ScriptCoopStopException();
|
||||
}
|
||||
|
||||
public Scene World
|
||||
@@ -2914,7 +2932,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
{
|
||||
// m_log.Info("llSleep snoozing " + sec + "s.");
|
||||
m_host.AddScriptLPS(1);
|
||||
Thread.Sleep((int)(sec * 1000));
|
||||
|
||||
Sleep((int)(sec * 1000));
|
||||
}
|
||||
|
||||
public LSL_Float llGetMass()
|
||||
|
||||
@@ -30,6 +30,7 @@ using System.Reflection;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Remoting.Lifetime;
|
||||
using System.Threading;
|
||||
using OpenMetaverse;
|
||||
using Nini.Config;
|
||||
using OpenSim;
|
||||
@@ -61,10 +62,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
internal bool m_LSFunctionsEnabled = false;
|
||||
internal IScriptModuleComms m_comms = null;
|
||||
|
||||
public void Initialize(IScriptInstance scriptInstance)
|
||||
public void Initialize(
|
||||
IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, EventWaitHandle coopSleepHandle)
|
||||
{
|
||||
m_ScriptEngine = scriptInstance.Engine;
|
||||
m_host = scriptInstance.Part;
|
||||
m_ScriptEngine = scriptEngine;
|
||||
m_host = host;
|
||||
|
||||
if (m_ScriptEngine.Config.GetBoolean("AllowLightShareFunctions", false))
|
||||
m_LSFunctionsEnabled = true;
|
||||
|
||||
@@ -30,6 +30,7 @@ using System.Reflection;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Remoting.Lifetime;
|
||||
using System.Threading;
|
||||
using OpenMetaverse;
|
||||
using Nini.Config;
|
||||
using OpenSim;
|
||||
@@ -61,11 +62,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
internal bool m_MODFunctionsEnabled = false;
|
||||
internal IScriptModuleComms m_comms = null;
|
||||
|
||||
public void Initialize(IScriptInstance scriptInstance)
|
||||
public void Initialize(
|
||||
IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, EventWaitHandle coopSleepHandle)
|
||||
{
|
||||
m_ScriptEngine = scriptInstance.Engine;
|
||||
m_host = scriptInstance.Part;
|
||||
m_item = scriptInstance.ScriptTask;
|
||||
m_ScriptEngine = scriptEngine;
|
||||
m_host = host;
|
||||
m_item = item;
|
||||
|
||||
if (m_ScriptEngine.Config.GetBoolean("AllowMODFunctions", false))
|
||||
m_MODFunctionsEnabled = true;
|
||||
|
||||
@@ -142,11 +142,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
|
||||
protected IUrlModule m_UrlModule = null;
|
||||
|
||||
public void Initialize(IScriptInstance scriptInstance)
|
||||
public void Initialize(
|
||||
IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, EventWaitHandle coopSleepHandle)
|
||||
{
|
||||
m_ScriptEngine = scriptInstance.Engine;
|
||||
m_host = scriptInstance.Part;
|
||||
m_item = scriptInstance.ScriptTask;
|
||||
m_ScriptEngine = scriptEngine;
|
||||
m_host = host;
|
||||
m_item = item;
|
||||
|
||||
m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user