diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs | 59 |
1 files changed, 39 insertions, 20 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs index 0458a50..c329246 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs | |||
@@ -41,6 +41,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
41 | { | 41 | { |
42 | //public ScriptEngine m_ScriptEngine; | 42 | //public ScriptEngine m_ScriptEngine; |
43 | private int MaintenanceLoopms; | 43 | private int MaintenanceLoopms; |
44 | private int MaintenanceLoopTicks_ScriptLoadUnload; | ||
45 | private int MaintenanceLoopTicks_Other; | ||
46 | |||
44 | 47 | ||
45 | public MaintenanceThread() | 48 | public MaintenanceThread() |
46 | { | 49 | { |
@@ -63,6 +66,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
63 | foreach (ScriptEngine m_ScriptEngine in ScriptEngine.ScriptEngines) | 66 | foreach (ScriptEngine m_ScriptEngine in ScriptEngine.ScriptEngines) |
64 | { | 67 | { |
65 | MaintenanceLoopms = m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopms", 50); | 68 | MaintenanceLoopms = m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopms", 50); |
69 | MaintenanceLoopTicks_ScriptLoadUnload = m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopTicks_ScriptLoadUnload", 1); | ||
70 | MaintenanceLoopTicks_Other = m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopTicks_Other", 10); | ||
71 | |||
66 | return; | 72 | return; |
67 | } | 73 | } |
68 | } | 74 | } |
@@ -123,6 +129,10 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
123 | 129 | ||
124 | long Last_maxFunctionExecutionTimens = 0; // DateTime.Now.Ticks; | 130 | long Last_maxFunctionExecutionTimens = 0; // DateTime.Now.Ticks; |
125 | long Last_ReReadConfigFilens = DateTime.Now.Ticks; | 131 | long Last_ReReadConfigFilens = DateTime.Now.Ticks; |
132 | long Last_MaintenanceRun = 0; | ||
133 | int MaintenanceLoopTicks_ScriptLoadUnload_Count = 0; | ||
134 | int MaintenanceLoopTicks_Other_Count = 0; | ||
135 | |||
126 | while (true) | 136 | while (true) |
127 | { | 137 | { |
128 | try | 138 | try |
@@ -132,15 +142,20 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
132 | System.Threading.Thread.Sleep(MaintenanceLoopms); // Sleep before next pass | 142 | System.Threading.Thread.Sleep(MaintenanceLoopms); // Sleep before next pass |
133 | //if (PleaseShutdown) | 143 | //if (PleaseShutdown) |
134 | // return; | 144 | // return; |
145 | MaintenanceLoopTicks_ScriptLoadUnload_Count++; | ||
146 | MaintenanceLoopTicks_Other_Count++; | ||
147 | |||
135 | 148 | ||
136 | foreach (ScriptEngine m_ScriptEngine in new ArrayList(ScriptEngine.ScriptEngines)) | 149 | foreach (ScriptEngine m_ScriptEngine in new ArrayList(ScriptEngine.ScriptEngines)) |
137 | { | 150 | { |
138 | lastScriptEngine = m_ScriptEngine; | 151 | lastScriptEngine = m_ScriptEngine; |
139 | if (m_ScriptEngine != null) | 152 | // Re-reading config every x seconds |
153 | if (m_ScriptEngine.RefreshConfigFilens > 0) | ||
140 | { | 154 | { |
141 | // Re-reading config every x seconds | 155 | |
142 | if (m_ScriptEngine.RefreshConfigFilens > 0) | 156 | if (MaintenanceLoopTicks_Other_Count >= MaintenanceLoopTicks_Other) |
143 | { | 157 | { |
158 | MaintenanceLoopTicks_Other_Count = 0; | ||
144 | // Check if its time to re-read config | 159 | // Check if its time to re-read config |
145 | if (DateTime.Now.Ticks - Last_ReReadConfigFilens > | 160 | if (DateTime.Now.Ticks - Last_ReReadConfigFilens > |
146 | m_ScriptEngine.RefreshConfigFilens) | 161 | m_ScriptEngine.RefreshConfigFilens) |
@@ -150,29 +165,33 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
150 | m_ScriptEngine.ReadConfig(); | 165 | m_ScriptEngine.ReadConfig(); |
151 | Last_ReReadConfigFilens = DateTime.Now.Ticks; // Reset time | 166 | Last_ReReadConfigFilens = DateTime.Now.Ticks; // Reset time |
152 | } | 167 | } |
153 | } | ||
154 | 168 | ||
155 | // Adjust number of running script threads if not correct | ||
156 | if (m_ScriptEngine.m_EventQueueManager != null) | ||
157 | m_ScriptEngine.m_EventQueueManager.AdjustNumberOfScriptThreads(); | ||
158 | 169 | ||
159 | // Check if any script has exceeded its max execution time | 170 | // Adjust number of running script threads if not correct |
160 | if (EventQueueManager.EnforceMaxExecutionTime) | 171 | if (m_ScriptEngine.m_EventQueueManager != null) |
161 | { | 172 | m_ScriptEngine.m_EventQueueManager.AdjustNumberOfScriptThreads(); |
162 | // We are enforcing execution time | 173 | |
163 | if (DateTime.Now.Ticks - Last_maxFunctionExecutionTimens > | 174 | // Check if any script has exceeded its max execution time |
164 | EventQueueManager.maxFunctionExecutionTimens) | 175 | if (EventQueueManager.EnforceMaxExecutionTime) |
165 | { | 176 | { |
166 | // Its time to check again | 177 | // We are enforcing execution time |
167 | m_ScriptEngine.m_EventQueueManager.CheckScriptMaxExecTime(); // Do check | 178 | if (DateTime.Now.Ticks - Last_maxFunctionExecutionTimens > |
168 | Last_maxFunctionExecutionTimens = DateTime.Now.Ticks; // Reset time | 179 | EventQueueManager.maxFunctionExecutionTimens) |
180 | { | ||
181 | // Its time to check again | ||
182 | m_ScriptEngine.m_EventQueueManager.CheckScriptMaxExecTime(); // Do check | ||
183 | Last_maxFunctionExecutionTimens = DateTime.Now.Ticks; // Reset time | ||
184 | } | ||
169 | } | 185 | } |
170 | } | 186 | } |
171 | 187 | ||
172 | // LOAD / UNLOAD SCRIPTS | 188 | if (MaintenanceLoopTicks_ScriptLoadUnload_Count >= MaintenanceLoopTicks_ScriptLoadUnload) |
173 | if (m_ScriptEngine.m_ScriptManager != null) | 189 | { |
174 | m_ScriptEngine.m_ScriptManager.DoScriptLoadUnload(); | 190 | MaintenanceLoopTicks_ScriptLoadUnload_Count = 0; |
175 | 191 | // LOAD / UNLOAD SCRIPTS | |
192 | if (m_ScriptEngine.m_ScriptManager != null) | ||
193 | m_ScriptEngine.m_ScriptManager.DoScriptLoadUnload(); | ||
194 | } | ||
176 | } | 195 | } |
177 | } | 196 | } |
178 | } | 197 | } |