diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/XMREngine/XMRInstMain.cs | 231 |
1 files changed, 231 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/XMRInstMain.cs b/OpenSim/Region/ScriptEngine/XMREngine/XMRInstMain.cs new file mode 100644 index 0000000..3573be3 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/XMREngine/XMRInstMain.cs | |||
@@ -0,0 +1,231 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Threading; | ||
30 | using System.Reflection; | ||
31 | using System.Collections; | ||
32 | using System.Collections.Generic; | ||
33 | using System.Runtime.Remoting.Lifetime; | ||
34 | using System.Security.Policy; | ||
35 | using System.IO; | ||
36 | using System.Xml; | ||
37 | using System.Text; | ||
38 | using OpenMetaverse; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
41 | using OpenSim.Region.ScriptEngine.Shared; | ||
42 | using OpenSim.Region.ScriptEngine.Shared.Api; | ||
43 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | ||
44 | using OpenSim.Region.ScriptEngine.XMREngine; | ||
45 | using OpenSim.Region.Framework.Scenes; | ||
46 | using log4net; | ||
47 | |||
48 | using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; | ||
49 | using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; | ||
50 | using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; | ||
51 | using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; | ||
52 | using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; | ||
53 | using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; | ||
54 | using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; | ||
55 | |||
56 | // This class exists in the main app domain | ||
57 | // | ||
58 | namespace OpenSim.Region.ScriptEngine.XMREngine | ||
59 | { | ||
60 | /** | ||
61 | * @brief Which queue it is in as far as running is concerned, | ||
62 | * ie, m_StartQueue, m_YieldQueue, m_SleepQueue, etc. | ||
63 | * Allowed transitions: | ||
64 | * Starts in CONSTRUCT when constructed | ||
65 | * CONSTRUCT->ONSTARTQ : only by thread that constructed and compiled it | ||
66 | * IDLE->ONSTARTQ,RESETTING : by any thread but must have m_QueueLock when transitioning | ||
67 | * ONSTARTQ->RUNNING,RESETTING : only by thread that removed it from m_StartQueue | ||
68 | * ONYIELDQ->RUNNING,RESETTING : only by thread that removed it from m_YieldQueue | ||
69 | * ONSLEEPQ->REMDFROMSLPQ : by any thread but must have m_SleepQueue when transitioning | ||
70 | * REMDFROMSLPQ->ONYIELDQ,RESETTING : only by thread that removed it from m_SleepQueue | ||
71 | * RUNNING->whatever1 : only by thread that transitioned it to RUNNING | ||
72 | * whatever1 = IDLE,ONSLEEPQ,ONYIELDQ,ONSTARTQ,SUSPENDED,FINISHED | ||
73 | * FINSHED->whatever2 : only by thread that transitioned it to FINISHED | ||
74 | * whatever2 = IDLE,ONSTARTQ,DISPOSED | ||
75 | * SUSPENDED->ONSTARTQ : by any thread (NOT YET IMPLEMENTED, should be under some kind of lock?) | ||
76 | * RESETTING->ONSTARTQ : only by the thread that transitioned it to RESETTING | ||
77 | */ | ||
78 | public enum XMRInstState { | ||
79 | CONSTRUCT, // it is being constructed | ||
80 | IDLE, // nothing happening (finished last event and m_EventQueue is empty) | ||
81 | ONSTARTQ, // inserted on m_Engine.m_StartQueue | ||
82 | RUNNING, // currently being executed by RunOne() | ||
83 | ONSLEEPQ, // inserted on m_Engine.m_SleepQueue | ||
84 | REMDFROMSLPQ, // removed from m_SleepQueue but not yet on m_YieldQueue | ||
85 | ONYIELDQ, // inserted on m_Engine.m_YieldQueue | ||
86 | FINISHED, // just finished handling an event | ||
87 | SUSPENDED, // m_SuspendCount > 0 | ||
88 | RESETTING, // being reset via external call | ||
89 | DISPOSED // has been disposed | ||
90 | } | ||
91 | |||
92 | public partial class XMRInstance : XMRInstAbstract, IDisposable | ||
93 | { | ||
94 | /******************************************************************\ | ||
95 | * This module contains the instance variables for XMRInstance. * | ||
96 | \******************************************************************/ | ||
97 | |||
98 | public const int MAXEVENTQUEUE = 64; | ||
99 | |||
100 | public static readonly DetectParams[] zeroDetectParams = new DetectParams[0]; | ||
101 | public static readonly object[] zeroObjectArray = new object[0]; | ||
102 | |||
103 | public static readonly ILog m_log = | ||
104 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
105 | |||
106 | // For a given m_Item.AssetID, do we have the compiled object code and where | ||
107 | // is it? | ||
108 | public static object m_CompileLock = new object(); | ||
109 | private static Dictionary<string,ScriptObjCode> m_CompiledScriptObjCode = new Dictionary<string,ScriptObjCode>(); | ||
110 | |||
111 | public XMRInstance m_NextInst; // used by XMRInstQueue | ||
112 | public XMRInstance m_PrevInst; | ||
113 | public XMRInstState m_IState; | ||
114 | |||
115 | public bool m_ForceRecomp = false; | ||
116 | public SceneObjectPart m_Part = null; | ||
117 | public uint m_LocalID = 0; | ||
118 | public TaskInventoryItem m_Item = null; | ||
119 | public UUID m_ItemID; | ||
120 | public UUID m_PartUUID; | ||
121 | private string m_CameFrom; | ||
122 | private string m_ScriptObjCodeKey; | ||
123 | |||
124 | private XMREngine m_Engine = null; | ||
125 | private string m_ScriptBasePath; | ||
126 | private string m_StateFileName; | ||
127 | public string m_SourceCode; | ||
128 | public bool m_PostOnRez; | ||
129 | private DetectParams[] m_DetectParams = null; | ||
130 | public int m_StartParam = 0; | ||
131 | public StateSource m_StateSource; | ||
132 | public string m_DescName; | ||
133 | private bool[] m_HaveEventHandlers; | ||
134 | public int m_StackSize; | ||
135 | public int m_HeapSize; | ||
136 | private ArrayList m_CompilerErrors; | ||
137 | private DateTime m_LastRanAt = DateTime.MinValue; | ||
138 | private string m_RunOnePhase = "hasn't run"; | ||
139 | private string m_CheckRunPhase = "hasn't checked"; | ||
140 | public int m_InstEHEvent = 0; // number of events dequeued (StartEventHandler called) | ||
141 | public int m_InstEHSlice = 0; // number of times handler timesliced (ResumeEx called) | ||
142 | public double m_CPUTime = 0; // accumulated CPU time (milliseconds) | ||
143 | public double m_SliceStart = 0; // when did current exec start | ||
144 | |||
145 | // If code needs to have both m_QueueLock and m_RunLock, | ||
146 | // be sure to lock m_RunLock first then m_QueueLock, as | ||
147 | // that is the order used in RunOne(). | ||
148 | // These locks are currently separated to allow the script | ||
149 | // to call API routines that queue events back to the script. | ||
150 | // If we just had one lock, then the queuing would deadlock. | ||
151 | |||
152 | // guards m_DetachQuantum, m_EventQueue, m_EventCounts, m_Running, m_Suspended | ||
153 | public Object m_QueueLock = new Object(); | ||
154 | |||
155 | // true iff allowed to accept new events | ||
156 | public bool m_Running = true; | ||
157 | |||
158 | // queue of events that haven't been acted upon yet | ||
159 | public LinkedList<EventParams> m_EventQueue = new LinkedList<EventParams> (); | ||
160 | |||
161 | // number of events of each code currently in m_EventQueue. | ||
162 | private int[] m_EventCounts = new int[(int)ScriptEventCode.Size]; | ||
163 | |||
164 | // locked whilst running on the microthread stack (or about to run on it or just ran on it) | ||
165 | private Object m_RunLock = new Object(); | ||
166 | |||
167 | // script won't step while > 0. bus-atomic updates only. | ||
168 | private int m_SuspendCount = 0; | ||
169 | |||
170 | // don't run any of script until this time | ||
171 | // or until one of these events are queued | ||
172 | public DateTime m_SleepUntil = DateTime.MinValue; | ||
173 | public int m_SleepEventMask1 = 0; | ||
174 | public int m_SleepEventMask2 = 0; | ||
175 | |||
176 | private XMRLSL_Api m_XMRLSLApi; | ||
177 | |||
178 | /* | ||
179 | * We will use this microthread to run the scripts event handlers. | ||
180 | */ | ||
181 | private IScriptUThread microthread; | ||
182 | |||
183 | /* | ||
184 | * Set to perform migration. | ||
185 | */ | ||
186 | public bool stackFramesRestored; // set true by CheckRun() when stack has been | ||
187 | // restored and is about to suspend the microthread | ||
188 | public bool captureStackFrames; // set true to tell CheckRun() to throw a | ||
189 | // StackCaptureException() causing it to capture a | ||
190 | // snapshot of the script's stack | ||
191 | |||
192 | /* | ||
193 | * Makes sure migration data version is same on both ends. | ||
194 | */ | ||
195 | public static byte migrationVersion = 10; | ||
196 | |||
197 | // Incremented each time script gets reset. | ||
198 | public int m_ResetCount = 0; | ||
199 | |||
200 | // Scripts start suspended now. This means that event queues will | ||
201 | // accept events, but will not actually run them until the core | ||
202 | // tells it it's OK. This is needed to prevent loss of link messages | ||
203 | // in complex objects, where no event can be allowed to run until | ||
204 | // all possible link message receivers' queues are established. | ||
205 | // Guarded by m_QueueLock. | ||
206 | public bool m_Suspended = true; | ||
207 | |||
208 | // We really don't want to save state for a script that hasn't had | ||
209 | // a chance to run, because it's state will be blank. That would | ||
210 | // cause attachment state loss. | ||
211 | public bool m_HasRun = false; | ||
212 | |||
213 | // When llDie is executed within the attach(NULL_KEY) event of | ||
214 | // a script being detached to inventory, the DeleteSceneObject call | ||
215 | // it causes will delete the script instances before their state can | ||
216 | // be saved. Therefore, the instance needs to know that it's being | ||
217 | // detached to inventory, rather than to ground. | ||
218 | // Also, the attach(NULL_KEY) event needs to run with priority, and | ||
219 | // it also needs to have a limited quantum. | ||
220 | // If this is nonzero, we're detaching to inventory. | ||
221 | // Guarded by m_QueueLock. | ||
222 | private int m_DetachQuantum = 0; | ||
223 | |||
224 | // Finally, we need to wait until the quantum is done, or the script | ||
225 | // suspends itself. This should be efficient, so we use an event | ||
226 | // for it instead of spinning busy. | ||
227 | // It's born ready, but will be reset when the detach is posted. | ||
228 | // It will then be set again on suspend/completion | ||
229 | private ManualResetEvent m_DetachReady = new ManualResetEvent(true); | ||
230 | } | ||
231 | } | ||