aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs118
1 files changed, 53 insertions, 65 deletions
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs b/OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs
index ddb3698..6470477 100644
--- a/OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs
+++ b/OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs
@@ -25,7 +25,6 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using Mono.Tasklets;
29using OpenSim.Framework.Monitoring; 28using OpenSim.Framework.Monitoring;
30using System; 29using System;
31using System.Collections.Generic; 30using System.Collections.Generic;
@@ -70,7 +69,6 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
70 private bool m_Exiting = false; 69 private bool m_Exiting = false;
71 private bool m_SuspendScriptThreadFlag = false; 70 private bool m_SuspendScriptThreadFlag = false;
72 private bool m_WakeUpThis = false; 71 private bool m_WakeUpThis = false;
73 private bool m_Continuations = false;
74 public DateTime m_LastRanAt = DateTime.MinValue; 72 public DateTime m_LastRanAt = DateTime.MinValue;
75 public int m_ScriptThreadTID = 0; 73 public int m_ScriptThreadTID = 0;
76 public long m_ScriptExecTime = 0; 74 public long m_ScriptExecTime = 0;
@@ -78,15 +76,15 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
78 private XMREngine engine; 76 private XMREngine engine;
79 public XMRInstance m_RunInstance = null; 77 public XMRInstance m_RunInstance = null;
80 78
81 public XMRScriptThread(XMREngine eng) 79 public XMRScriptThread(XMREngine eng, int i)
82 { 80 {
83 engine = eng; 81 engine = eng;
84 m_Continuations = engine.uThreadCtor.DeclaringType == typeof (ScriptUThread_Con); 82 if(i < 0)
85// thd = XMREngine.StartMyThread (RunScriptThread, "xmrengine script", ThreadPriority.BelowNormal); 83 thd = XMREngine.StartMyThread (RunScriptThread, "xmrengine script", ThreadPriority.Normal);
86 thd = XMREngine.StartMyThread (RunScriptThread, "xmrengine script", ThreadPriority.Normal); 84 else
85 thd = XMREngine.StartMyThread (RunScriptThread, "xmrengineExec" + i.ToString(), ThreadPriority.Normal);
87 lock (m_AllThreads) 86 lock (m_AllThreads)
88 m_AllThreads.Add (thd, this); 87 m_AllThreads.Add (thd, this);
89
90 } 88 }
91 89
92 public void SuspendThread() 90 public void SuspendThread()
@@ -125,7 +123,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
125 */ 123 */
126 private void WakeUpScriptThread() 124 private void WakeUpScriptThread()
127 { 125 {
128 lock (m_WakeUpLock) { 126 lock (m_WakeUpLock)
127 {
129 m_WakeUpThis = true; 128 m_WakeUpThis = true;
130 Monitor.PulseAll (m_WakeUpLock); 129 Monitor.PulseAll (m_WakeUpLock);
131 } 130 }
@@ -137,24 +136,22 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
137 private void RunScriptThread() 136 private void RunScriptThread()
138 { 137 {
139 XMRInstance inst; 138 XMRInstance inst;
140 Mono.Tasklets.Continuation engstack = null;
141 if (m_Continuations) {
142 engstack = new Mono.Tasklets.Continuation ();
143 engstack.Mark ();
144 }
145 m_ScriptThreadTID = System.Threading.Thread.CurrentThread.ManagedThreadId; 139 m_ScriptThreadTID = System.Threading.Thread.CurrentThread.ManagedThreadId;
146 140
147 while (!m_Exiting) { 141 while (!m_Exiting)
142 {
148 XMREngine.UpdateMyThread (); 143 XMREngine.UpdateMyThread ();
149 144
150 /* 145 /*
151 * Handle 'xmr resume/suspend' commands. 146 * Handle 'xmr resume/suspend' commands.
152 */ 147 */
153 if (m_SuspendScriptThreadFlag) { 148 if (m_SuspendScriptThreadFlag)
149 {
154 lock (m_WakeUpLock) { 150 lock (m_WakeUpLock) {
155 while (m_SuspendScriptThreadFlag && 151 while (m_SuspendScriptThreadFlag &&
156 !m_Exiting && 152 !m_Exiting &&
157 (engine.m_ThunkQueue.Count == 0)) { 153 (engine.m_ThunkQueue.Count == 0))
154 {
158 Monitor.Wait (m_WakeUpLock, Watchdog.DEFAULT_WATCHDOG_TIMEOUT_MS / 2); 155 Monitor.Wait (m_WakeUpLock, Watchdog.DEFAULT_WATCHDOG_TIMEOUT_MS / 2);
159 XMREngine.UpdateMyThread (); 156 XMREngine.UpdateMyThread ();
160 } 157 }
@@ -165,81 +162,72 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
165 * Maybe there are some scripts waiting to be migrated in or out. 162 * Maybe there are some scripts waiting to be migrated in or out.
166 */ 163 */
167 ThreadStart thunk = null; 164 ThreadStart thunk = null;
168 lock (m_WakeUpLock) { 165 lock (m_WakeUpLock)
169 if (engine.m_ThunkQueue.Count > 0) { 166 {
167 if (engine.m_ThunkQueue.Count > 0)
170 thunk = engine.m_ThunkQueue.Dequeue (); 168 thunk = engine.m_ThunkQueue.Dequeue ();
171 }
172 } 169 }
173 if (thunk != null) { 170 if (thunk != null)
171 {
174 inst = (XMRInstance)thunk.Target; 172 inst = (XMRInstance)thunk.Target;
175 if (m_Continuations && (inst.scrstack == null)) {
176 inst.engstack = engstack;
177 inst.scrstack = new Mono.Tasklets.Continuation ();
178 inst.scrstack.Mark ();
179 }
180 thunk (); 173 thunk ();
181 continue; 174 continue;
182 } 175 }
183 176
184 if (engine.m_StartProcessing) { 177 if (engine.m_StartProcessing)
178 {
179 // If event just queued to any idle scripts
180 // start them right away. But only start so
181 // many so we can make some progress on yield
182 // queue.
185 183
186 /*
187 * If event just queued to any idle scripts
188 * start them right away. But only start so
189 * many so we can make some progress on yield
190 * queue.
191 */
192 int numStarts; 184 int numStarts;
193 for (numStarts = 5; -- numStarts >= 0;) { 185 for (numStarts = 5; -- numStarts >= 0;)
194 lock (engine.m_StartQueue) { 186 {
187 lock (engine.m_StartQueue)
188 {
195 inst = engine.m_StartQueue.RemoveHead(); 189 inst = engine.m_StartQueue.RemoveHead();
196 } 190 }
197 if (inst == null) break; 191 if (inst == null) break;
198 if (inst.m_IState != XMRInstState.ONSTARTQ) throw new Exception("bad state"); 192 if (inst.m_IState != XMRInstState.ONSTARTQ) throw new Exception("bad state");
199 if (m_Continuations && (inst.scrstack == null)) {
200 inst.engstack = engstack;
201 inst.scrstack = new Mono.Tasklets.Continuation ();
202 inst.scrstack.Mark ();
203 }
204 RunInstance (inst); 193 RunInstance (inst);
205 } 194 }
206 195
207 /* 196 // If there is something to run, run it
208 * If there is something to run, run it 197 // then rescan from the beginning in case
209 * then rescan from the beginning in case 198 // a lot of things have changed meanwhile.
210 * a lot of things have changed meanwhile. 199 //
211 * 200 // These are considered lower priority than
212 * These are considered lower priority than 201 // m_StartQueue as they have been taking at
213 * m_StartQueue as they have been taking at 202 // least one quantum of CPU time and event
214 * least one quantum of CPU time and event 203 // handlers are supposed to be quick.
215 * handlers are supposed to be quick. 204
216 */ 205 lock (engine.m_YieldQueue)
217 lock (engine.m_YieldQueue) { 206 {
218 inst = engine.m_YieldQueue.RemoveHead(); 207 inst = engine.m_YieldQueue.RemoveHead();
219 } 208 }
220 if (inst != null) { 209 if (inst != null)
210 {
221 if (inst.m_IState != XMRInstState.ONYIELDQ) throw new Exception("bad state"); 211 if (inst.m_IState != XMRInstState.ONYIELDQ) throw new Exception("bad state");
222 RunInstance (inst); 212 RunInstance(inst);
223 numStarts = -1; 213 numStarts = -1;
224 } 214 }
225 215
226 /* 216 // If we left something dangling in the m_StartQueue or m_YieldQueue, go back to check it.
227 * If we left something dangling in the m_StartQueue or m_YieldQueue, go back to check it. 217 if (numStarts < 0)
228 */ 218 continue;
229 if (numStarts < 0) continue;
230 } 219 }
231 220
232 /* 221 // Nothing to do, sleep.
233 * Nothing to do, sleep. 222
234 */ 223 lock (m_WakeUpLock)
235 lock (m_WakeUpLock) { 224 {
236 if (!m_WakeUpThis && (m_WakeUpOne <= 0) && !m_Exiting) { 225 if (!m_WakeUpThis && (m_WakeUpOne <= 0) && !m_Exiting)
237 Monitor.Wait (m_WakeUpLock, Watchdog.DEFAULT_WATCHDOG_TIMEOUT_MS / 2); 226 Monitor.Wait(m_WakeUpLock, Watchdog.DEFAULT_WATCHDOG_TIMEOUT_MS / 2);
238 } 227
239 m_WakeUpThis = false; 228 m_WakeUpThis = false;
240 if ((m_WakeUpOne > 0) && (-- m_WakeUpOne > 0)) { 229 if ((m_WakeUpOne > 0) && (-- m_WakeUpOne > 0))
241 Monitor.Pulse (m_WakeUpLock); 230 Monitor.Pulse (m_WakeUpLock);
242 }
243 } 231 }
244 } 232 }
245 XMREngine.MyThreadExiting (); 233 XMREngine.MyThreadExiting ();