aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Api
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2013-01-16 02:07:43 +0000
committerJustin Clark-Casey (justincc)2013-01-16 02:07:43 +0000
commit0963ece25bdef16852f5fd8ae4515a2f05d8b6e4 (patch)
treef95a3eef3e94df4408d555a30cd62bce629623f2 /OpenSim/Region/ScriptEngine/Shared/Api
parentRevert "Implement co-operative script termination if termination comes during... (diff)
downloadopensim-SC_OLD-0963ece25bdef16852f5fd8ae4515a2f05d8b6e4.zip
opensim-SC_OLD-0963ece25bdef16852f5fd8ae4515a2f05d8b6e4.tar.gz
opensim-SC_OLD-0963ece25bdef16852f5fd8ae4515a2f05d8b6e4.tar.bz2
opensim-SC_OLD-0963ece25bdef16852f5fd8ae4515a2f05d8b6e4.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. This commit, unlike 1b5c41c, passes the wait handle as an extra parameter through IScript.Initialize() instead of passing IScriptInstance itself.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs35
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs8
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs9
4 files changed, 43 insertions, 19 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..d47fd6b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -83,10 +83,17 @@ 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
86 protected IScriptEngine m_ScriptEngine; 87 protected IScriptEngine m_ScriptEngine;
87 protected SceneObjectPart m_host; 88 protected SceneObjectPart m_host;
88 89
89 /// <summary> 90 /// <summary>
91 /// Used for script sleeps when we are using co-operative script termination.
92 /// </summary>
93 /// <remarks>null if co-operative script termination is not active</remarks>
94 EventWaitHandle m_coopSleepHandle;
95
96 /// <summary>
90 /// The item that hosts this script 97 /// The item that hosts this script
91 /// </summary> 98 /// </summary>
92 protected TaskInventoryItem m_item; 99 protected TaskInventoryItem m_item;
@@ -110,13 +117,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
110 protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp. 117 protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp.
111 protected ISoundModule m_SoundModule = null; 118 protected ISoundModule m_SoundModule = null;
112 119
113 public void Initialize(IScriptInstance scriptInstance) 120 public void Initialize(
121 IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, EventWaitHandle coopSleepHandle)
114 { 122 {
115 m_ScriptEngine = scriptInstance.Engine; 123 m_ScriptEngine = scriptEngine;
116 m_host = scriptInstance.Part; 124 m_host = host;
117 m_item = scriptInstance.ScriptTask; 125 m_item = item;
126 m_coopSleepHandle = coopSleepHandle;
118 127
119 LoadLimits(); // read script limits from config. 128 LoadConfig();
120 129
121 m_TransferModule = 130 m_TransferModule =
122 m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>(); 131 m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
@@ -129,7 +138,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
129 /// <summary> 138 /// <summary>
130 /// Load configuration items that affect script, object and run-time behavior. */ 139 /// Load configuration items that affect script, object and run-time behavior. */
131 /// </summary> 140 /// </summary>
132 private void LoadLimits() 141 private void LoadConfig()
133 { 142 {
134 m_ScriptDelayFactor = 143 m_ScriptDelayFactor =
135 m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f); 144 m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
@@ -175,7 +184,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
175 delay = (int)((float)delay * m_ScriptDelayFactor); 184 delay = (int)((float)delay * m_ScriptDelayFactor);
176 if (delay == 0) 185 if (delay == 0)
177 return; 186 return;
178 System.Threading.Thread.Sleep(delay); 187
188 Sleep(delay);
189 }
190
191 protected virtual void Sleep(int delay)
192 {
193 if (m_coopSleepHandle == null)
194 System.Threading.Thread.Sleep(delay);
195 else if (m_coopSleepHandle.WaitOne(delay))
196 throw new ScriptCoopStopException();
179 } 197 }
180 198
181 public Scene World 199 public Scene World
@@ -2914,7 +2932,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2914 { 2932 {
2915// m_log.Info("llSleep snoozing " + sec + "s."); 2933// m_log.Info("llSleep snoozing " + sec + "s.");
2916 m_host.AddScriptLPS(1); 2934 m_host.AddScriptLPS(1);
2917 Thread.Sleep((int)(sec * 1000)); 2935
2936 Sleep((int)(sec * 1000));
2918 } 2937 }
2919 2938
2920 public LSL_Float llGetMass() 2939 public LSL_Float llGetMass()
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
index 071c60e..a08ccc8 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
@@ -30,6 +30,7 @@ using System.Reflection;
30using System.Collections; 30using System.Collections;
31using System.Collections.Generic; 31using System.Collections.Generic;
32using System.Runtime.Remoting.Lifetime; 32using System.Runtime.Remoting.Lifetime;
33using System.Threading;
33using OpenMetaverse; 34using OpenMetaverse;
34using Nini.Config; 35using Nini.Config;
35using OpenSim; 36using OpenSim;
@@ -61,10 +62,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
61 internal bool m_LSFunctionsEnabled = false; 62 internal bool m_LSFunctionsEnabled = false;
62 internal IScriptModuleComms m_comms = null; 63 internal IScriptModuleComms m_comms = null;
63 64
64 public void Initialize(IScriptInstance scriptInstance) 65 public void Initialize(
66 IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, EventWaitHandle coopSleepHandle)
65 { 67 {
66 m_ScriptEngine = scriptInstance.Engine; 68 m_ScriptEngine = scriptEngine;
67 m_host = scriptInstance.Part; 69 m_host = host;
68 70
69 if (m_ScriptEngine.Config.GetBoolean("AllowLightShareFunctions", false)) 71 if (m_ScriptEngine.Config.GetBoolean("AllowLightShareFunctions", false))
70 m_LSFunctionsEnabled = true; 72 m_LSFunctionsEnabled = true;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
index cbc69aa..981499e 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
@@ -30,6 +30,7 @@ using System.Reflection;
30using System.Collections; 30using System.Collections;
31using System.Collections.Generic; 31using System.Collections.Generic;
32using System.Runtime.Remoting.Lifetime; 32using System.Runtime.Remoting.Lifetime;
33using System.Threading;
33using OpenMetaverse; 34using OpenMetaverse;
34using Nini.Config; 35using Nini.Config;
35using OpenSim; 36using OpenSim;
@@ -61,11 +62,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
61 internal bool m_MODFunctionsEnabled = false; 62 internal bool m_MODFunctionsEnabled = false;
62 internal IScriptModuleComms m_comms = null; 63 internal IScriptModuleComms m_comms = null;
63 64
64 public void Initialize(IScriptInstance scriptInstance) 65 public void Initialize(
66 IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, EventWaitHandle coopSleepHandle)
65 { 67 {
66 m_ScriptEngine = scriptInstance.Engine; 68 m_ScriptEngine = scriptEngine;
67 m_host = scriptInstance.Part; 69 m_host = host;
68 m_item = scriptInstance.ScriptTask; 70 m_item = item;
69 71
70 if (m_ScriptEngine.Config.GetBoolean("AllowMODFunctions", false)) 72 if (m_ScriptEngine.Config.GetBoolean("AllowMODFunctions", false))
71 m_MODFunctionsEnabled = true; 73 m_MODFunctionsEnabled = true;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 33ae5f0..25635ff 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -142,11 +142,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
142 142
143 protected IUrlModule m_UrlModule = null; 143 protected IUrlModule m_UrlModule = null;
144 144
145 public void Initialize(IScriptInstance scriptInstance) 145 public void Initialize(
146 IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, EventWaitHandle coopSleepHandle)
146 { 147 {
147 m_ScriptEngine = scriptInstance.Engine; 148 m_ScriptEngine = scriptEngine;
148 m_host = scriptInstance.Part; 149 m_host = host;
149 m_item = scriptInstance.ScriptTask; 150 m_item = item;
150 151
151 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); 152 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
152 153