aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
diff options
context:
space:
mode:
authorMelanie2013-01-16 16:52:57 +0000
committerMelanie2013-01-16 16:52:57 +0000
commit9c99ed26ebe7cd2e42c10487e4ddfde0c934d921 (patch)
tree536b2d6530fdda925203afddd27a4b9444e4d2a7 /OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
parentComplete removal of the now unused state queue (diff)
parentChanged a couple of debug messages at the request of osgrid. (diff)
downloadopensim-SC-9c99ed26ebe7cd2e42c10487e4ddfde0c934d921.zip
opensim-SC-9c99ed26ebe7cd2e42c10487e4ddfde0c934d921.tar.gz
opensim-SC-9c99ed26ebe7cd2e42c10487e4ddfde0c934d921.tar.bz2
opensim-SC-9c99ed26ebe7cd2e42c10487e4ddfde0c934d921.tar.xz
Merge branch 'master' of melanie@opensimulator.org:/var/git/opensim
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs100
1 files changed, 76 insertions, 24 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index f172216..75aea2b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -157,9 +157,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
157 157
158 public UUID AppDomain { get; set; } 158 public UUID AppDomain { get; set; }
159 159
160 /// <summary>
161 /// Scene part in which this script instance is contained.
162 /// </summary>
163 public SceneObjectPart Part { get; private set; } 160 public SceneObjectPart Part { get; private set; }
164 161
165 public string PrimName { get; private set; } 162 public string PrimName { get; private set; }
@@ -203,49 +200,68 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
203 200
204 public static readonly long MaxMeasurementPeriod = 30 * TimeSpan.TicksPerMinute; 201 public static readonly long MaxMeasurementPeriod = 30 * TimeSpan.TicksPerMinute;
205 202
203 private bool m_coopTermination;
204
205 private EventWaitHandle m_coopSleepHandle;
206
206 public void ClearQueue() 207 public void ClearQueue()
207 { 208 {
208 m_TimerQueued = false; 209 m_TimerQueued = false;
209 EventQueue.Clear(); 210 EventQueue.Clear();
210 } 211 }
211 212
212 public ScriptInstance(IScriptEngine engine, SceneObjectPart part, 213 public ScriptInstance(
213 UUID itemID, UUID assetID, string assembly, 214 IScriptEngine engine, SceneObjectPart part, TaskInventoryItem item,
214 AppDomain dom, string primName, string scriptName, 215 int startParam, bool postOnRez,
215 int startParam, bool postOnRez, StateSource stateSource, 216 int maxScriptQueue)
216 int maxScriptQueue)
217 { 217 {
218 State = "default"; 218 State = "default";
219 EventQueue = new Queue(32); 219 EventQueue = new Queue(32);
220 220
221 Engine = engine; 221 Engine = engine;
222 Part = part; 222 Part = part;
223 ItemID = itemID; 223 ScriptTask = item;
224 AssetID = assetID; 224
225 PrimName = primName; 225 // This is currently only here to allow regression tests to get away without specifying any inventory
226 ScriptName = scriptName; 226 // item when they are testing script logic that doesn't require an item.
227 m_Assembly = assembly; 227 if (ScriptTask != null)
228 {
229 ScriptName = ScriptTask.Name;
230 ItemID = ScriptTask.ItemID;
231 AssetID = ScriptTask.AssetID;
232 }
233
234 PrimName = part.ParentGroup.Name;
228 StartParam = startParam; 235 StartParam = startParam;
229 m_MaxScriptQueue = maxScriptQueue; 236 m_MaxScriptQueue = maxScriptQueue;
230 m_stateSource = stateSource;
231 m_postOnRez = postOnRez; 237 m_postOnRez = postOnRez;
232 m_AttachedAvatar = Part.ParentGroup.AttachedAvatar; 238 m_AttachedAvatar = Part.ParentGroup.AttachedAvatar;
233 m_RegionID = Part.ParentGroup.Scene.RegionInfo.RegionID; 239 m_RegionID = Part.ParentGroup.Scene.RegionInfo.RegionID;
234 240
235 lock (Part.TaskInventory) 241 if (Engine.Config.GetString("ScriptStopStrategy", "abort") == "co-op")
236 { 242 {
237 if (Part.TaskInventory.ContainsKey(ItemID)) 243 m_coopTermination = true;
238 { 244 m_coopSleepHandle = new AutoResetEvent(false);
239 ScriptTask = Part.TaskInventory[ItemID];
240 }
241 } 245 }
246 }
247
248 /// <summary>
249 /// Load the script from an assembly into an AppDomain.
250 /// </summary>
251 /// <param name='dom'></param>
252 /// <param name='assembly'></param>
253 /// <param name='stateSource'></param>
254 public void Load(AppDomain dom, string assembly, StateSource stateSource)
255 {
256 m_Assembly = assembly;
257 m_stateSource = stateSource;
242 258
243 ApiManager am = new ApiManager(); 259 ApiManager am = new ApiManager();
244 260
245 foreach (string api in am.GetApis()) 261 foreach (string api in am.GetApis())
246 { 262 {
247 m_Apis[api] = am.CreateApi(api); 263 m_Apis[api] = am.CreateApi(api);
248 m_Apis[api].Initialize(engine, part, ScriptTask); 264 m_Apis[api].Initialize(Engine, Part, ScriptTask, m_coopSleepHandle);
249 } 265 }
250 266
251 try 267 try
@@ -279,7 +295,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
279 295
280// // m_log.Debug("[Script] Script instance created"); 296// // m_log.Debug("[Script] Script instance created");
281 297
282 part.SetScriptEvents(ItemID, 298 Part.SetScriptEvents(ItemID,
283 (int)m_Script.GetStateEventFlags(State)); 299 (int)m_Script.GetStateEventFlags(State));
284 } 300 }
285 catch (Exception e) 301 catch (Exception e)
@@ -526,9 +542,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
526 } 542 }
527 543
528 // Wait for the current event to complete. 544 // Wait for the current event to complete.
529 if (!m_InSelfDelete && workItem.Wait(new TimeSpan((long)timeout * 100000))) 545 if (!m_InSelfDelete)
530 { 546 {
531 return true; 547 if (!m_coopTermination)
548 {
549 // If we're not co-operative terminating then try and wait for the event to complete before stopping
550 if (workItem.Wait(new TimeSpan((long)timeout * 100000)))
551 return true;
552 }
553 else
554 {
555 m_log.DebugFormat(
556 "[SCRIPT INSTANCE]: Co-operatively stopping script {0} {1} in {2} {3}",
557 ScriptName, ItemID, PrimName, ObjectID);
558
559 // This will terminate the event on next handle check by the script.
560 m_coopSleepHandle.Set();
561
562 // For now, we will wait forever since the event should always cleanly terminate once LSL loop
563 // checking is implemented. May want to allow a shorter timeout option later.
564 if (workItem.Wait(TimeSpan.MaxValue))
565 {
566 m_log.DebugFormat(
567 "[SCRIPT INSTANCE]: Co-operatively stopped script {0} {1} in {2} {3}",
568 ScriptName, ItemID, PrimName, ObjectID);
569
570 return true;
571 }
572 }
532 } 573 }
533 574
534 lock (EventQueue) 575 lock (EventQueue)
@@ -541,6 +582,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
541 582
542 // If the event still hasn't stopped and we the stop isn't the result of script or object removal, then 583 // If the event still hasn't stopped and we the stop isn't the result of script or object removal, then
543 // forcibly abort the work item (this aborts the underlying thread). 584 // forcibly abort the work item (this aborts the underlying thread).
585 // Co-operative termination should never reach this point.
544 if (!m_InSelfDelete) 586 if (!m_InSelfDelete)
545 { 587 {
546 m_log.DebugFormat( 588 m_log.DebugFormat(
@@ -780,7 +822,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
780 m_InEvent = false; 822 m_InEvent = false;
781 m_CurrentEvent = String.Empty; 823 m_CurrentEvent = String.Empty;
782 824
783 if ((!(e is TargetInvocationException) || (!(e.InnerException is SelfDeleteException) && !(e.InnerException is ScriptDeleteException))) && !(e is ThreadAbortException)) 825 if ((!(e is TargetInvocationException)
826 || (!(e.InnerException is SelfDeleteException)
827 && !(e.InnerException is ScriptDeleteException)
828 && !(e.InnerException is ScriptCoopStopException)))
829 && !(e is ThreadAbortException))
784 { 830 {
785 try 831 try
786 { 832 {
@@ -828,6 +874,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
828 m_InSelfDelete = true; 874 m_InSelfDelete = true;
829 Part.Inventory.RemoveInventoryItem(ItemID); 875 Part.Inventory.RemoveInventoryItem(ItemID);
830 } 876 }
877 else if ((e is TargetInvocationException) && (e.InnerException is ScriptCoopStopException))
878 {
879 m_log.DebugFormat(
880 "[SCRIPT INSTANCE]: Script {0}.{1} in event {2}, state {3} stopped co-operatively.",
881 PrimName, ScriptName, data.EventName, State);
882 }
831 } 883 }
832 } 884 }
833 } 885 }