diff options
author | Justin Clark-Casey (justincc) | 2013-01-16 00:12:40 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2013-01-16 00:12:40 +0000 |
commit | 1b5c41c14ad11325be249ea1cce3c65d4d6a89be (patch) | |
tree | 987e140c9402c48cc8daf59d2b8af165646cc93a /OpenSim/Region/ScriptEngine/Shared/Api | |
parent | Instead of passing separate engine, part and item components to script APIs, ... (diff) | |
download | opensim-SC-1b5c41c14ad11325be249ea1cce3c65d4d6a89be.zip opensim-SC-1b5c41c14ad11325be249ea1cce3c65d4d6a89be.tar.gz opensim-SC-1b5c41c14ad11325be249ea1cce3c65d4d6a89be.tar.bz2 opensim-SC-1b5c41c14ad11325be249ea1cce3c65d4d6a89be.tar.xz |
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.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 44072c6..b992efa 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -83,6 +83,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
83 | public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi | 83 | public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi |
84 | { | 84 | { |
85 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 85 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
86 | |||
87 | /// <summary> | ||
88 | /// Instance of this script. | ||
89 | /// </summary> | ||
90 | protected IScriptInstance m_scriptInstance; | ||
91 | |||
86 | protected IScriptEngine m_ScriptEngine; | 92 | protected IScriptEngine m_ScriptEngine; |
87 | protected SceneObjectPart m_host; | 93 | protected SceneObjectPart m_host; |
88 | 94 | ||
@@ -112,11 +118,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
112 | 118 | ||
113 | public void Initialize(IScriptInstance scriptInstance) | 119 | public void Initialize(IScriptInstance scriptInstance) |
114 | { | 120 | { |
115 | m_ScriptEngine = scriptInstance.Engine; | 121 | m_scriptInstance = scriptInstance; |
116 | m_host = scriptInstance.Part; | 122 | m_ScriptEngine = m_scriptInstance.Engine; |
117 | m_item = scriptInstance.ScriptTask; | 123 | m_host = m_scriptInstance.Part; |
124 | m_item = m_scriptInstance.ScriptTask; | ||
118 | 125 | ||
119 | LoadLimits(); // read script limits from config. | 126 | LoadConfig(); |
120 | 127 | ||
121 | m_TransferModule = | 128 | m_TransferModule = |
122 | m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>(); | 129 | m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>(); |
@@ -129,7 +136,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
129 | /// <summary> | 136 | /// <summary> |
130 | /// Load configuration items that affect script, object and run-time behavior. */ | 137 | /// Load configuration items that affect script, object and run-time behavior. */ |
131 | /// </summary> | 138 | /// </summary> |
132 | private void LoadLimits() | 139 | private void LoadConfig() |
133 | { | 140 | { |
134 | m_ScriptDelayFactor = | 141 | m_ScriptDelayFactor = |
135 | m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f); | 142 | m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f); |
@@ -175,7 +182,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
175 | delay = (int)((float)delay * m_ScriptDelayFactor); | 182 | delay = (int)((float)delay * m_ScriptDelayFactor); |
176 | if (delay == 0) | 183 | if (delay == 0) |
177 | return; | 184 | return; |
178 | System.Threading.Thread.Sleep(delay); | 185 | |
186 | Sleep(delay); | ||
187 | } | ||
188 | |||
189 | protected virtual void Sleep(int delay) | ||
190 | { | ||
191 | if (!m_scriptInstance.CoopTermination) | ||
192 | System.Threading.Thread.Sleep(delay); | ||
193 | else if (m_scriptInstance.CoopSleepHandle.WaitOne(delay)) | ||
194 | throw new ScriptCoopStopException(); | ||
179 | } | 195 | } |
180 | 196 | ||
181 | public Scene World | 197 | public Scene World |
@@ -2914,7 +2930,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2914 | { | 2930 | { |
2915 | // m_log.Info("llSleep snoozing " + sec + "s."); | 2931 | // m_log.Info("llSleep snoozing " + sec + "s."); |
2916 | m_host.AddScriptLPS(1); | 2932 | m_host.AddScriptLPS(1); |
2917 | Thread.Sleep((int)(sec * 1000)); | 2933 | |
2934 | Sleep((int)(sec * 1000)); | ||
2918 | } | 2935 | } |
2919 | 2936 | ||
2920 | public LSL_Float llGetMass() | 2937 | public LSL_Float llGetMass() |