diff options
Diffstat (limited to 'OpenSim/Framework/Monitoring/Watchdog.cs')
-rw-r--r-- | OpenSim/Framework/Monitoring/Watchdog.cs | 61 |
1 files changed, 49 insertions, 12 deletions
diff --git a/OpenSim/Framework/Monitoring/Watchdog.cs b/OpenSim/Framework/Monitoring/Watchdog.cs index a644fa5..9cac451 100644 --- a/OpenSim/Framework/Monitoring/Watchdog.cs +++ b/OpenSim/Framework/Monitoring/Watchdog.cs | |||
@@ -96,7 +96,7 @@ namespace OpenSim.Framework.Monitoring | |||
96 | FirstTick = Environment.TickCount & Int32.MaxValue; | 96 | FirstTick = Environment.TickCount & Int32.MaxValue; |
97 | LastTick = FirstTick; | 97 | LastTick = FirstTick; |
98 | 98 | ||
99 | Stat | 99 | Stat |
100 | = new Stat( | 100 | = new Stat( |
101 | name, | 101 | name, |
102 | string.Format("Last update of thread {0}", name), | 102 | string.Format("Last update of thread {0}", name), |
@@ -180,6 +180,30 @@ namespace OpenSim.Framework.Monitoring | |||
180 | m_watchdogTimer.Elapsed += WatchdogTimerElapsed; | 180 | m_watchdogTimer.Elapsed += WatchdogTimerElapsed; |
181 | } | 181 | } |
182 | 182 | ||
183 | public static void Stop() | ||
184 | { | ||
185 | if(m_threads == null) | ||
186 | return; | ||
187 | |||
188 | lock(m_threads) | ||
189 | { | ||
190 | m_enabled = false; | ||
191 | if(m_watchdogTimer != null) | ||
192 | { | ||
193 | m_watchdogTimer.Dispose(); | ||
194 | m_watchdogTimer = null; | ||
195 | } | ||
196 | |||
197 | foreach(ThreadWatchdogInfo twi in m_threads.Values) | ||
198 | { | ||
199 | Thread t = twi.Thread; | ||
200 | if(t.IsAlive) | ||
201 | t.Abort(); | ||
202 | } | ||
203 | m_threads.Clear(); | ||
204 | } | ||
205 | } | ||
206 | |||
183 | /// <summary> | 207 | /// <summary> |
184 | /// Add a thread to the watchdog tracker. | 208 | /// Add a thread to the watchdog tracker. |
185 | /// </summary> | 209 | /// </summary> |
@@ -230,14 +254,12 @@ namespace OpenSim.Framework.Monitoring | |||
230 | 254 | ||
231 | twi.Cleanup(); | 255 | twi.Cleanup(); |
232 | m_threads.Remove(threadID); | 256 | m_threads.Remove(threadID); |
233 | |||
234 | return true; | 257 | return true; |
235 | } | 258 | } |
236 | else | 259 | else |
237 | { | 260 | { |
238 | m_log.WarnFormat( | 261 | m_log.WarnFormat( |
239 | "[WATCHDOG]: Requested to remove thread with ID {0} but this is not being monitored", threadID); | 262 | "[WATCHDOG]: Requested to remove thread with ID {0} but this is not being monitored", threadID); |
240 | |||
241 | return false; | 263 | return false; |
242 | } | 264 | } |
243 | } | 265 | } |
@@ -317,6 +339,8 @@ namespace OpenSim.Framework.Monitoring | |||
317 | /// <param name="e"></param> | 339 | /// <param name="e"></param> |
318 | private static void WatchdogTimerElapsed(object sender, System.Timers.ElapsedEventArgs e) | 340 | private static void WatchdogTimerElapsed(object sender, System.Timers.ElapsedEventArgs e) |
319 | { | 341 | { |
342 | if(!m_enabled) | ||
343 | return; | ||
320 | int now = Environment.TickCount & Int32.MaxValue; | 344 | int now = Environment.TickCount & Int32.MaxValue; |
321 | int msElapsed = now - LastWatchdogThreadTick; | 345 | int msElapsed = now - LastWatchdogThreadTick; |
322 | 346 | ||
@@ -332,27 +356,36 @@ namespace OpenSim.Framework.Monitoring | |||
332 | if (callback != null) | 356 | if (callback != null) |
333 | { | 357 | { |
334 | List<ThreadWatchdogInfo> callbackInfos = null; | 358 | List<ThreadWatchdogInfo> callbackInfos = null; |
359 | List<ThreadWatchdogInfo> threadsToRemove = null; | ||
360 | |||
361 | const ThreadState thgone = ThreadState.Stopped; | ||
335 | 362 | ||
336 | lock (m_threads) | 363 | lock (m_threads) |
337 | { | 364 | { |
338 | foreach (ThreadWatchdogInfo threadInfo in m_threads.Values) | 365 | foreach(ThreadWatchdogInfo threadInfo in m_threads.Values) |
339 | { | 366 | { |
340 | if (threadInfo.Thread.ThreadState == ThreadState.Stopped) | 367 | if(!m_enabled) |
368 | return; | ||
369 | if((threadInfo.Thread.ThreadState & thgone) != 0) | ||
341 | { | 370 | { |
342 | RemoveThread(threadInfo.Thread.ManagedThreadId); | 371 | if(threadsToRemove == null) |
372 | threadsToRemove = new List<ThreadWatchdogInfo>(); | ||
343 | 373 | ||
344 | if (callbackInfos == null) | 374 | threadsToRemove.Add(threadInfo); |
375 | /* | ||
376 | if(callbackInfos == null) | ||
345 | callbackInfos = new List<ThreadWatchdogInfo>(); | 377 | callbackInfos = new List<ThreadWatchdogInfo>(); |
346 | 378 | ||
347 | callbackInfos.Add(threadInfo); | 379 | callbackInfos.Add(threadInfo); |
380 | */ | ||
348 | } | 381 | } |
349 | else if (!threadInfo.IsTimedOut && now - threadInfo.LastTick >= threadInfo.Timeout) | 382 | else if(!threadInfo.IsTimedOut && now - threadInfo.LastTick >= threadInfo.Timeout) |
350 | { | 383 | { |
351 | threadInfo.IsTimedOut = true; | 384 | threadInfo.IsTimedOut = true; |
352 | 385 | ||
353 | if (threadInfo.AlarmIfTimeout) | 386 | if(threadInfo.AlarmIfTimeout) |
354 | { | 387 | { |
355 | if (callbackInfos == null) | 388 | if(callbackInfos == null) |
356 | callbackInfos = new List<ThreadWatchdogInfo>(); | 389 | callbackInfos = new List<ThreadWatchdogInfo>(); |
357 | 390 | ||
358 | // Send a copy of the watchdog info to prevent race conditions where the watchdog | 391 | // Send a copy of the watchdog info to prevent race conditions where the watchdog |
@@ -361,9 +394,13 @@ namespace OpenSim.Framework.Monitoring | |||
361 | } | 394 | } |
362 | } | 395 | } |
363 | } | 396 | } |
397 | |||
398 | if(threadsToRemove != null) | ||
399 | foreach(ThreadWatchdogInfo twi in threadsToRemove) | ||
400 | RemoveThread(twi.Thread.ManagedThreadId); | ||
364 | } | 401 | } |
365 | 402 | ||
366 | if (callbackInfos != null) | 403 | if(callbackInfos != null) |
367 | foreach (ThreadWatchdogInfo callbackInfo in callbackInfos) | 404 | foreach (ThreadWatchdogInfo callbackInfo in callbackInfos) |
368 | callback(callbackInfo); | 405 | callback(callbackInfo); |
369 | } | 406 | } |
@@ -377,4 +414,4 @@ namespace OpenSim.Framework.Monitoring | |||
377 | m_watchdogTimer.Start(); | 414 | m_watchdogTimer.Start(); |
378 | } | 415 | } |
379 | } | 416 | } |
380 | } \ No newline at end of file | 417 | } |