aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XEngine
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2013-01-17 23:39:09 +0000
committerJustin Clark-Casey (justincc)2013-01-17 23:39:09 +0000
commitc8afc8523b9caf931afb3d5b3f9874b26b866a77 (patch)
treeb1a84d82591f462ae61b3aeed4f4b6dd3c5c06e8 /OpenSim/Region/ScriptEngine/XEngine
parentMerge branch 'master' of melanie@opensimulator.org:/var/git/opensim (diff)
downloadopensim-SC-c8afc8523b9caf931afb3d5b3f9874b26b866a77.zip
opensim-SC-c8afc8523b9caf931afb3d5b3f9874b26b866a77.tar.gz
opensim-SC-c8afc8523b9caf931afb3d5b3f9874b26b866a77.tar.bz2
opensim-SC-c8afc8523b9caf931afb3d5b3f9874b26b866a77.tar.xz
Implement non-wait co-operative termination of scripts for XEngine in addition to termination on wait.
This involves inserting opensim_reserved_CheckForCoopTermination() calls in lsl -> c# translation at any place where the script could be in a loop with no wait calls. These places are for, while, do-while, label, user function call and manual event function call. Call goes through to an XEngineScriptBase which extends ScriptBase. IEngine is extended to supply necessary engine-specific parent class references and constructor parameters to Compiler. Unfortunately, since XEngineScriptBase has to be passed WaitHandle in its constructor, older compiled scripts will fail to load with an error on the OpenSim console. Such scripts will need to be recompiled, either by removing all *.dll files from the bin/ScriptEngines/<region-id> or by setting DeleteScriptsOnStartup = true in [XEngine] for one run. Automatic recompilation may be implemented in a later commit. This feature should not yet be used, default remains termination with Thread.Abort() which will work as normal once scripts are recompiled.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/Api/Runtime/XEngineScriptBase.cs61
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs17
2 files changed, 77 insertions, 1 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Api/Runtime/XEngineScriptBase.cs b/OpenSim/Region/ScriptEngine/XEngine/Api/Runtime/XEngineScriptBase.cs
new file mode 100644
index 0000000..f4211c8
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/XEngine/Api/Runtime/XEngineScriptBase.cs
@@ -0,0 +1,61 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Runtime.Remoting;
30using System.Runtime.Remoting.Lifetime;
31using System.Security.Permissions;
32using System.Threading;
33using System.Reflection;
34using System.Collections;
35using System.Collections.Generic;
36using OpenSim.Region.ScriptEngine.Interfaces;
37using OpenSim.Region.ScriptEngine.Shared;
38using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
39
40namespace OpenSim.Region.ScriptEngine.XEngine.ScriptBase
41{
42 public class XEngineScriptBase : ScriptBaseClass
43 {
44 /// <summary>
45 /// Used for script sleeps when we are using co-operative script termination.
46 /// </summary>
47 /// <remarks>null if co-operative script termination is not active</remarks>
48 WaitHandle m_coopSleepHandle;
49
50 public XEngineScriptBase(WaitHandle coopSleepHandle) : base()
51 {
52 m_coopSleepHandle = coopSleepHandle;
53 }
54
55 public void opensim_reserved_CheckForCoopTermination()
56 {
57 if (m_coopSleepHandle != null && m_coopSleepHandle.WaitOne(0))
58 throw new ScriptCoopStopException();
59 }
60 }
61} \ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index a17a018..8a02590 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -53,6 +53,7 @@ using OpenSim.Region.ScriptEngine.Shared.Instance;
53using OpenSim.Region.ScriptEngine.Shared.Api; 53using OpenSim.Region.ScriptEngine.Shared.Api;
54using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; 54using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
55using OpenSim.Region.ScriptEngine.Interfaces; 55using OpenSim.Region.ScriptEngine.Interfaces;
56using OpenSim.Region.ScriptEngine.XEngine.ScriptBase;
56using Timer = OpenSim.Region.ScriptEngine.Shared.Api.Plugins.Timer; 57using Timer = OpenSim.Region.ScriptEngine.Shared.Api.Plugins.Timer;
57 58
58using ScriptCompileQueue = OpenSim.Framework.LocklessQueue<object[]>; 59using ScriptCompileQueue = OpenSim.Framework.LocklessQueue<object[]>;
@@ -176,6 +177,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
176 get { return "XEngine"; } 177 get { return "XEngine"; }
177 } 178 }
178 179
180 public string ScriptBaseClassName { get; private set; }
181
182 public ParameterInfo[] ScriptBaseClassParameters { get; private set; }
183
184 public string[] ScriptReferencedAssemblies { get; private set; }
185
179 public Scene World 186 public Scene World
180 { 187 {
181 get { return m_Scene; } 188 get { return m_Scene; }
@@ -230,6 +237,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
230 237
231 m_ScriptConfig = configSource.Configs["XEngine"]; 238 m_ScriptConfig = configSource.Configs["XEngine"];
232 m_ConfigSource = configSource; 239 m_ConfigSource = configSource;
240
241 ScriptBaseClassName = typeof(XEngineScriptBase).FullName;
242 ScriptBaseClassParameters = typeof(XEngineScriptBase).GetConstructor(new Type[] { typeof(WaitHandle) }).GetParameters();
243 ScriptReferencedAssemblies = new string[] { Path.GetFileName(typeof(XEngineScriptBase).Assembly.Location) };
244
245 Console.WriteLine("ASSEMBLY NAME: {0}", ScriptReferencedAssemblies[0]);
233 } 246 }
234 247
235 public void AddRegion(Scene scene) 248 public void AddRegion(Scene scene)
@@ -1179,7 +1192,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1179 } 1192 }
1180 catch (Exception e) 1193 catch (Exception e)
1181 { 1194 {
1182// m_log.ErrorFormat("[XEngine]: Exception when rezzing script {0}{1}", e.Message, e.StackTrace); 1195// m_log.ErrorFormat(
1196// "[XEngine]: Exception when rezzing script with item ID {0}, {1}{2}",
1197// itemID, e.Message, e.StackTrace);
1183 1198
1184 // try 1199 // try
1185 // { 1200 // {