mirror of
https://github.com/opensim/opensim.git
synced 2026-08-06 01:06:30 +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 is contained in:
@@ -83,6 +83,12 @@ 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);
|
||||
|
||||
/// <summary>
|
||||
/// Instance of this script.
|
||||
/// </summary>
|
||||
protected IScriptInstance m_scriptInstance;
|
||||
|
||||
protected IScriptEngine m_ScriptEngine;
|
||||
protected SceneObjectPart m_host;
|
||||
|
||||
@@ -112,11 +118,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
|
||||
public void Initialize(IScriptInstance scriptInstance)
|
||||
{
|
||||
m_ScriptEngine = scriptInstance.Engine;
|
||||
m_host = scriptInstance.Part;
|
||||
m_item = scriptInstance.ScriptTask;
|
||||
m_scriptInstance = scriptInstance;
|
||||
m_ScriptEngine = m_scriptInstance.Engine;
|
||||
m_host = m_scriptInstance.Part;
|
||||
m_item = m_scriptInstance.ScriptTask;
|
||||
|
||||
LoadLimits(); // read script limits from config.
|
||||
LoadConfig();
|
||||
|
||||
m_TransferModule =
|
||||
m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
|
||||
@@ -129,7 +136,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 +182,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_scriptInstance.CoopTermination)
|
||||
System.Threading.Thread.Sleep(delay);
|
||||
else if (m_scriptInstance.CoopSleepHandle.WaitOne(delay))
|
||||
throw new ScriptCoopStopException();
|
||||
}
|
||||
|
||||
public Scene World
|
||||
@@ -2914,7 +2930,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()
|
||||
|
||||
Reference in New Issue
Block a user