aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs
diff options
context:
space:
mode:
authorUbitUmarov2018-02-07 19:52:18 +0000
committerUbitUmarov2018-02-07 19:52:18 +0000
commit01ceb4d17e80b794432062ff3bf3b85f884c9548 (patch)
treeb74cb4ddb1dea21276991ae379e084708aa3fce2 /OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs
parentadd a warning about XMR only suoprting one region per instance at this point,... (diff)
downloadopensim-SC-01ceb4d17e80b794432062ff3bf3b85f884c9548.zip
opensim-SC-01ceb4d17e80b794432062ff3bf3b85f884c9548.tar.gz
opensim-SC-01ceb4d17e80b794432062ff3bf3b85f884c9548.tar.bz2
opensim-SC-01ceb4d17e80b794432062ff3bf3b85f884c9548.tar.xz
try to fix xmr on multiregions per instance. Ugly spargetti ...; remove fixes for 2 llparcel functions that should not be needed; remove xmr own API, it has no business having one.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs180
1 files changed, 15 insertions, 165 deletions
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs b/OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs
index 6470477..7103556 100644
--- a/OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs
+++ b/OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs
@@ -32,7 +32,6 @@ using System.Threading;
32 32
33namespace OpenSim.Region.ScriptEngine.XMREngine 33namespace OpenSim.Region.ScriptEngine.XMREngine
34{ 34{
35
36 /** 35 /**
37 * @brief There are NUMSCRIPTHREADWKRS of these. 36 * @brief There are NUMSCRIPTHREADWKRS of these.
38 * Each sits in a loop checking the Start and Yield queues for 37 * Each sits in a loop checking the Start and Yield queues for
@@ -40,35 +39,7 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
40 */ 39 */
41 public class XMRScriptThread 40 public class XMRScriptThread
42 { 41 {
43 private static int m_WakeUpOne = 0; 42 public bool m_WakeUpThis = false;
44 public static object m_WakeUpLock = new object();
45 private static Dictionary<Thread,XMRScriptThread> m_AllThreads = new Dictionary<Thread,XMRScriptThread> ();
46
47 /**
48 * @brief Something was just added to the Start or Yield queue so
49 * wake one of the XMRScriptThread instances to run it.
50 */
51 public static void WakeUpOne()
52 {
53 lock (m_WakeUpLock)
54 {
55 m_WakeUpOne ++;
56 Monitor.Pulse (m_WakeUpLock);
57 }
58 }
59
60 public static XMRScriptThread CurrentScriptThread ()
61 {
62 XMRScriptThread st;
63 lock (m_AllThreads) {
64 m_AllThreads.TryGetValue (Thread.CurrentThread, out st);
65 }
66 return st;
67 }
68
69 private bool m_Exiting = false;
70 private bool m_SuspendScriptThreadFlag = false;
71 private bool m_WakeUpThis = false;
72 public DateTime m_LastRanAt = DateTime.MinValue; 43 public DateTime m_LastRanAt = DateTime.MinValue;
73 public int m_ScriptThreadTID = 0; 44 public int m_ScriptThreadTID = 0;
74 public long m_ScriptExecTime = 0; 45 public long m_ScriptExecTime = 0;
@@ -80,164 +51,43 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
80 { 51 {
81 engine = eng; 52 engine = eng;
82 if(i < 0) 53 if(i < 0)
83 thd = XMREngine.StartMyThread (RunScriptThread, "xmrengine script", ThreadPriority.Normal); 54 thd = XMREngine.StartMyThread(RunScriptThread, "xmrengine script", ThreadPriority.Normal);
84 else 55 else
85 thd = XMREngine.StartMyThread (RunScriptThread, "xmrengineExec" + i.ToString(), ThreadPriority.Normal); 56 thd = XMREngine.StartMyThread(RunScriptThread, "xmrengineExec" + i.ToString(), ThreadPriority.Normal);
86 lock (m_AllThreads) 57 engine.AddThread(thd, this);
87 m_AllThreads.Add (thd, this); 58 m_ScriptThreadTID = thd.ManagedThreadId;
88 }
89
90 public void SuspendThread()
91 {
92 m_SuspendScriptThreadFlag = true;
93 WakeUpScriptThread();
94 }
95
96 public void ResumeThread()
97 {
98 m_SuspendScriptThreadFlag = false;
99 WakeUpScriptThread();
100 } 59 }
101 60
102 public void Terminate() 61 public void Terminate()
103 { 62 {
104 m_Exiting = true; 63 m_WakeUpThis = true;
105 WakeUpScriptThread();
106 if(!thd.Join(250)) 64 if(!thd.Join(250))
107 thd.Abort(); 65 thd.Abort();
108 lock (m_AllThreads)
109 m_AllThreads.Remove (thd);
110 66
111 thd = null; 67 engine.RemoveThread(thd);
112 }
113 68
114 public void TimeSlice() 69 thd = null;
115 {
116 XMRInstance instance = m_RunInstance;
117 if (instance != null)
118 instance.suspendOnCheckRunTemp = true;
119 } 70 }
120 71
121 /** 72 /**
122 * @brief Wake up this XMRScriptThread instance. 73 * @brief Wake up this XMRScriptThread instance.
123 */ 74 */
124 private void WakeUpScriptThread() 75 public void WakeUpScriptThread()
125 { 76 {
126 lock (m_WakeUpLock)
127 {
128 m_WakeUpThis = true; 77 m_WakeUpThis = true;
129 Monitor.PulseAll (m_WakeUpLock);
130 }
131 } 78 }
132 79
133 /** 80 /**
134 * @brief Thread that runs the scripts. 81 * @brief A script instance was just removed from the Start or Yield Queue.
82 * So run it for a little bit then stick in whatever queue it should go in.
135 */ 83 */
84
136 private void RunScriptThread() 85 private void RunScriptThread()
137 { 86 {
138 XMRInstance inst; 87 engine.RunScriptThread(this);
139 m_ScriptThreadTID = System.Threading.Thread.CurrentThread.ManagedThreadId;
140
141 while (!m_Exiting)
142 {
143 XMREngine.UpdateMyThread ();
144
145 /*
146 * Handle 'xmr resume/suspend' commands.
147 */
148 if (m_SuspendScriptThreadFlag)
149 {
150 lock (m_WakeUpLock) {
151 while (m_SuspendScriptThreadFlag &&
152 !m_Exiting &&
153 (engine.m_ThunkQueue.Count == 0))
154 {
155 Monitor.Wait (m_WakeUpLock, Watchdog.DEFAULT_WATCHDOG_TIMEOUT_MS / 2);
156 XMREngine.UpdateMyThread ();
157 }
158 }
159 }
160
161 /*
162 * Maybe there are some scripts waiting to be migrated in or out.
163 */
164 ThreadStart thunk = null;
165 lock (m_WakeUpLock)
166 {
167 if (engine.m_ThunkQueue.Count > 0)
168 thunk = engine.m_ThunkQueue.Dequeue ();
169 }
170 if (thunk != null)
171 {
172 inst = (XMRInstance)thunk.Target;
173 thunk ();
174 continue;
175 }
176
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.
183
184 int numStarts;
185 for (numStarts = 5; -- numStarts >= 0;)
186 {
187 lock (engine.m_StartQueue)
188 {
189 inst = engine.m_StartQueue.RemoveHead();
190 }
191 if (inst == null) break;
192 if (inst.m_IState != XMRInstState.ONSTARTQ) throw new Exception("bad state");
193 RunInstance (inst);
194 }
195
196 // If there is something to run, run it
197 // then rescan from the beginning in case
198 // a lot of things have changed meanwhile.
199 //
200 // These are considered lower priority than
201 // m_StartQueue as they have been taking at
202 // least one quantum of CPU time and event
203 // handlers are supposed to be quick.
204
205 lock (engine.m_YieldQueue)
206 {
207 inst = engine.m_YieldQueue.RemoveHead();
208 }
209 if (inst != null)
210 {
211 if (inst.m_IState != XMRInstState.ONYIELDQ) throw new Exception("bad state");
212 RunInstance(inst);
213 numStarts = -1;
214 }
215
216 // If we left something dangling in the m_StartQueue or m_YieldQueue, go back to check it.
217 if (numStarts < 0)
218 continue;
219 }
220
221 // Nothing to do, sleep.
222
223 lock (m_WakeUpLock)
224 {
225 if (!m_WakeUpThis && (m_WakeUpOne <= 0) && !m_Exiting)
226 Monitor.Wait(m_WakeUpLock, Watchdog.DEFAULT_WATCHDOG_TIMEOUT_MS / 2);
227
228 m_WakeUpThis = false;
229 if ((m_WakeUpOne > 0) && (-- m_WakeUpOne > 0))
230 Monitor.Pulse (m_WakeUpLock);
231 }
232 }
233 XMREngine.MyThreadExiting ();
234 } 88 }
235 89
236 /** 90 public void RunInstance (XMRInstance inst)
237 * @brief A script instance was just removed from the Start or Yield Queue.
238 * So run it for a little bit then stick in whatever queue it should go in.
239 */
240 private void RunInstance (XMRInstance inst)
241 { 91 {
242 m_LastRanAt = DateTime.UtcNow; 92 m_LastRanAt = DateTime.UtcNow;
243 m_ScriptExecTime -= (long)(m_LastRanAt - DateTime.MinValue).TotalMilliseconds; 93 m_ScriptExecTime -= (long)(m_LastRanAt - DateTime.MinValue).TotalMilliseconds;