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:
Justin Clark-Casey (justincc)
2013-01-16 00:12:40 +00:00
parent fccb03227e
commit 1b5c41c14a
8 changed files with 293 additions and 14 deletions

View File

@@ -28,6 +28,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using OpenMetaverse;
using log4net;
using OpenSim.Framework;
@@ -180,6 +181,18 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
void Suspend();
void Resume();
/// <summary>
/// If true then scripts should look to terminate their threads in co-operation with the script engine rather
/// than through Thread.Abort()
/// </summary>
bool CoopTermination { get; }
/// <summary>
/// Used for script sleeps when we are using co-operative script termination.
/// </summary>
/// <remarks>null if CoopTermination is not active</remarks>
EventWaitHandle CoopSleepHandle { get; }
/// <summary>
/// Process the next event queued for this script instance.
/// </summary>