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