aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine
diff options
context:
space:
mode:
authorJohn Hurliman2009-10-22 12:33:23 -0700
committerJohn Hurliman2009-10-22 12:33:23 -0700
commitb2ed348aa2746fbf034b713d006e40366c479d5a (patch)
tree26c114e88f54e64e1fdf17dcc7de1e54165db2bc /OpenSim/Region/ScriptEngine/DotNetEngine
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC-b2ed348aa2746fbf034b713d006e40366c479d5a.zip
opensim-SC-b2ed348aa2746fbf034b713d006e40366c479d5a.tar.gz
opensim-SC-b2ed348aa2746fbf034b713d006e40366c479d5a.tar.bz2
opensim-SC-b2ed348aa2746fbf034b713d006e40366c479d5a.tar.xz
Implemented a Watchdog class. Do not manually create Thread objects anymore, use Watchdog.StartThread(). While your thread is running call Watchdog.UpdateThread(). When it is shutting down call Watchdog.RemoveThread(). Most of the threads in OpenSim have been updated
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueThreadClass.cs12
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/MaintenanceThread.cs83
2 files changed, 46 insertions, 49 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueThreadClass.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueThreadClass.cs
index 583d2ff..51fd41a 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueThreadClass.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueThreadClass.cs
@@ -132,12 +132,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
132 /// </summary> 132 /// </summary>
133 private void Start() 133 private void Start()
134 { 134 {
135 EventQueueThread = new Thread(EventQueueThreadLoop); 135 EventQueueThread = Watchdog.StartThread(EventQueueThreadLoop, "EventQueueManagerThread_" + ThreadCount, MyThreadPriority, true);
136 EventQueueThread.IsBackground = true;
137
138 EventQueueThread.Priority = MyThreadPriority;
139 EventQueueThread.Name = "EventQueueManagerThread_" + ThreadCount;
140 EventQueueThread.Start();
141 136
142 // Look at this... Don't you wish everyone did that solid 137 // Look at this... Don't you wish everyone did that solid
143 // coding everywhere? :P 138 // coding everywhere? :P
@@ -184,6 +179,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
184 while (true) 179 while (true)
185 { 180 {
186 DoProcessQueue(); 181 DoProcessQueue();
182 Watchdog.UpdateThread();
187 } 183 }
188 } 184 }
189 catch (ThreadAbortException) 185 catch (ThreadAbortException)
@@ -214,6 +210,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
214 m_log.ErrorFormat("[{0}]: Exception {1} thrown", ScriptEngineName, e.GetType().ToString()); 210 m_log.ErrorFormat("[{0}]: Exception {1} thrown", ScriptEngineName, e.GetType().ToString());
215 throw e; 211 throw e;
216 } 212 }
213
214 Watchdog.UpdateThread();
217 } 215 }
218 } 216 }
219 catch (ThreadAbortException) 217 catch (ThreadAbortException)
@@ -226,6 +224,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
226 "[{0}]: Event queue thread terminating with exception. PLEASE REBOOT YOUR SIM - SCRIPT EVENTS WILL NOT WORK UNTIL YOU DO. Exception is {1}", 224 "[{0}]: Event queue thread terminating with exception. PLEASE REBOOT YOUR SIM - SCRIPT EVENTS WILL NOT WORK UNTIL YOU DO. Exception is {1}",
227 ScriptEngineName, e); 225 ScriptEngineName, e);
228 } 226 }
227
228 Watchdog.RemoveThread();
229 } 229 }
230 230
231 public void DoProcessQueue() 231 public void DoProcessQueue()
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/MaintenanceThread.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/MaintenanceThread.cs
index 7ffdb1a..87fdf1f 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/MaintenanceThread.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/MaintenanceThread.cs
@@ -93,10 +93,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
93 { 93 {
94 if (MaintenanceThreadThread == null) 94 if (MaintenanceThreadThread == null)
95 { 95 {
96 MaintenanceThreadThread = new Thread(MaintenanceLoop); 96 MaintenanceThreadThread = Watchdog.StartThread(MaintenanceLoop, "ScriptMaintenanceThread", ThreadPriority.Normal, true);
97 MaintenanceThreadThread.Name = "ScriptMaintenanceThread";
98 MaintenanceThreadThread.IsBackground = true;
99 MaintenanceThreadThread.Start();
100 } 97 }
101 } 98 }
102 99
@@ -164,56 +161,54 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
164 MaintenanceLoopTicks_ScriptLoadUnload_Count++; 161 MaintenanceLoopTicks_ScriptLoadUnload_Count++;
165 MaintenanceLoopTicks_Other_Count++; 162 MaintenanceLoopTicks_Other_Count++;
166 163
167 164 foreach (ScriptEngine m_ScriptEngine in new ArrayList(ScriptEngine.ScriptEngines))
168 //lock (ScriptEngine.ScriptEngines) 165 {
169 //{ 166 // lastScriptEngine = m_ScriptEngine;
170 foreach (ScriptEngine m_ScriptEngine in new ArrayList(ScriptEngine.ScriptEngines)) 167 // Re-reading config every x seconds
168 if (MaintenanceLoopTicks_Other_Count >= MaintenanceLoopTicks_Other)
171 { 169 {
172 // lastScriptEngine = m_ScriptEngine; 170 MaintenanceLoopTicks_Other_ResetCount = true;
173 // Re-reading config every x seconds 171 if (m_ScriptEngine.RefreshConfigFilens > 0)
174 if (MaintenanceLoopTicks_Other_Count >= MaintenanceLoopTicks_Other)
175 { 172 {
176 MaintenanceLoopTicks_Other_ResetCount = true; 173 // Check if its time to re-read config
177 if (m_ScriptEngine.RefreshConfigFilens > 0) 174 if (DateTime.Now.Ticks - Last_ReReadConfigFilens >
175 m_ScriptEngine.RefreshConfigFilens)
178 { 176 {
179 // Check if its time to re-read config 177 //m_log.Debug("Time passed: " + (DateTime.Now.Ticks - Last_ReReadConfigFilens) + ">" + m_ScriptEngine.RefreshConfigFilens);
180 if (DateTime.Now.Ticks - Last_ReReadConfigFilens > 178 // Its time to re-read config file
181 m_ScriptEngine.RefreshConfigFilens) 179 m_ScriptEngine.ReadConfig();
182 { 180 Last_ReReadConfigFilens = DateTime.Now.Ticks; // Reset time
183 //m_log.Debug("Time passed: " + (DateTime.Now.Ticks - Last_ReReadConfigFilens) + ">" + m_ScriptEngine.RefreshConfigFilens); 181 }
184 // Its time to re-read config file
185 m_ScriptEngine.ReadConfig();
186 Last_ReReadConfigFilens = DateTime.Now.Ticks; // Reset time
187 }
188 182
189 183
190 // Adjust number of running script threads if not correct 184 // Adjust number of running script threads if not correct
191 if (m_ScriptEngine.m_EventQueueManager != null) 185 if (m_ScriptEngine.m_EventQueueManager != null)
192 m_ScriptEngine.m_EventQueueManager.AdjustNumberOfScriptThreads(); 186 m_ScriptEngine.m_EventQueueManager.AdjustNumberOfScriptThreads();
193 187
194 // Check if any script has exceeded its max execution time 188 // Check if any script has exceeded its max execution time
195 if (EventQueueManager.EnforceMaxExecutionTime) 189 if (EventQueueManager.EnforceMaxExecutionTime)
190 {
191 // We are enforcing execution time
192 if (DateTime.Now.Ticks - Last_maxFunctionExecutionTimens >
193 EventQueueManager.maxFunctionExecutionTimens)
196 { 194 {
197 // We are enforcing execution time 195 // Its time to check again
198 if (DateTime.Now.Ticks - Last_maxFunctionExecutionTimens > 196 m_ScriptEngine.m_EventQueueManager.CheckScriptMaxExecTime(); // Do check
199 EventQueueManager.maxFunctionExecutionTimens) 197 Last_maxFunctionExecutionTimens = DateTime.Now.Ticks; // Reset time
200 {
201 // Its time to check again
202 m_ScriptEngine.m_EventQueueManager.CheckScriptMaxExecTime(); // Do check
203 Last_maxFunctionExecutionTimens = DateTime.Now.Ticks; // Reset time
204 }
205 } 198 }
206 } 199 }
207 } 200 }
208 if (MaintenanceLoopTicks_ScriptLoadUnload_Count >= MaintenanceLoopTicks_ScriptLoadUnload)
209 {
210 MaintenanceLoopTicks_ScriptLoadUnload_ResetCount = true;
211 // LOAD / UNLOAD SCRIPTS
212 if (m_ScriptEngine.m_ScriptManager != null)
213 m_ScriptEngine.m_ScriptManager.DoScriptLoadUnload();
214 }
215 } 201 }
216 //} 202 if (MaintenanceLoopTicks_ScriptLoadUnload_Count >= MaintenanceLoopTicks_ScriptLoadUnload)
203 {
204 MaintenanceLoopTicks_ScriptLoadUnload_ResetCount = true;
205 // LOAD / UNLOAD SCRIPTS
206 if (m_ScriptEngine.m_ScriptManager != null)
207 m_ScriptEngine.m_ScriptManager.DoScriptLoadUnload();
208 }
209 }
210
211 Watchdog.UpdateThread();
217 } 212 }
218 } 213 }
219 catch(ThreadAbortException) 214 catch(ThreadAbortException)
@@ -225,6 +220,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
225 m_log.ErrorFormat("Exception in MaintenanceLoopThread. Thread will recover after 5 sec throttle. Exception: {0}", ex.ToString()); 220 m_log.ErrorFormat("Exception in MaintenanceLoopThread. Thread will recover after 5 sec throttle. Exception: {0}", ex.ToString());
226 } 221 }
227 } 222 }
223
224 Watchdog.RemoveThread();
228 } 225 }
229 #endregion 226 #endregion
230 227