diff --git a/OpenSim/Framework/Monitoring/Watchdog.cs b/OpenSim/Framework/Monitoring/Watchdog.cs index 83f8e016bb..b2c1fb178c 100644 --- a/OpenSim/Framework/Monitoring/Watchdog.cs +++ b/OpenSim/Framework/Monitoring/Watchdog.cs @@ -332,41 +332,37 @@ namespace OpenSim.Framework.Monitoring if (callback != null) { List callbackInfos = null; - - // get a copy since we may change m_threads List threadsInfo; + lock (m_threads) - threadsInfo = m_threads.Values.ToList(); - - foreach (ThreadWatchdogInfo threadInfo in threadsInfo) { - lock (m_threads) + // get a copy since we may change m_threads + threadsInfo = m_threads.Values.ToList(); + + foreach(ThreadWatchdogInfo threadInfo in threadsInfo) { - if(!m_threads.ContainsValue(threadInfo)) - continue; - } - - if(threadInfo.Thread.ThreadState == ThreadState.Stopped) - { - RemoveThread(threadInfo.Thread.ManagedThreadId); - - if(callbackInfos == null) - callbackInfos = new List(); - - callbackInfos.Add(threadInfo); - } - else if(!threadInfo.IsTimedOut && now - threadInfo.LastTick >= threadInfo.Timeout) - { - threadInfo.IsTimedOut = true; - - if(threadInfo.AlarmIfTimeout) + if(threadInfo.Thread.ThreadState == ThreadState.Stopped) { + RemoveThread(threadInfo.Thread.ManagedThreadId); + if(callbackInfos == null) callbackInfos = new List(); - // Send a copy of the watchdog info to prevent race conditions where the watchdog - // thread updates the monitoring info after an alarm has been sent out. - callbackInfos.Add(new ThreadWatchdogInfo(threadInfo)); + callbackInfos.Add(threadInfo); + } + else if(!threadInfo.IsTimedOut && now - threadInfo.LastTick >= threadInfo.Timeout) + { + threadInfo.IsTimedOut = true; + + if(threadInfo.AlarmIfTimeout) + { + if(callbackInfos == null) + callbackInfos = new List(); + + // Send a copy of the watchdog info to prevent race conditions where the watchdog + // thread updates the monitoring info after an alarm has been sent out. + callbackInfos.Add(new ThreadWatchdogInfo(threadInfo)); + } } } }