From 0781ac9a5e307e6ed0a0685c1dad98d5fb51b76b Mon Sep 17 00:00:00 2001 From: Teravus Ovares (Dan Olivares) Date: Thu, 13 Aug 2009 22:12:37 -0400 Subject: * Add ThreadTracker Tests, Tests default thread, Adding Testing and Removing a thread, a dead thread, and a null Thread * Fix a null thread situation --- OpenSim/Framework/ThreadTracker.cs | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'OpenSim/Framework/ThreadTracker.cs') diff --git a/OpenSim/Framework/ThreadTracker.cs b/OpenSim/Framework/ThreadTracker.cs index d8bd2c0..fa6f0b8 100644 --- a/OpenSim/Framework/ThreadTracker.cs +++ b/OpenSim/Framework/ThreadTracker.cs @@ -77,12 +77,15 @@ namespace OpenSim.Framework public static void Add(Thread thread) { #if DEBUG - lock (m_Threads) + if (thread != null) { - ThreadTrackerItem tti = new ThreadTrackerItem(); - tti.Thread = thread; - tti.LastSeenActive = DateTime.Now.Ticks; - m_Threads.Add(tti); + lock (m_Threads) + { + ThreadTrackerItem tti = new ThreadTrackerItem(); + tti.Thread = thread; + tti.LastSeenActive = DateTime.Now.Ticks; + m_Threads.Add(tti); + } } #endif } @@ -107,16 +110,25 @@ namespace OpenSim.Framework { foreach (ThreadTrackerItem tti in new ArrayList(m_Threads)) { - if (tti.Thread.IsAlive) + try { - // Its active - tti.LastSeenActive = DateTime.Now.Ticks; + + + if (tti.Thread.IsAlive) + { + // Its active + tti.LastSeenActive = DateTime.Now.Ticks; + } + else + { + // Its not active -- if its expired then remove it + if (tti.LastSeenActive + ThreadTimeout < DateTime.Now.Ticks) + m_Threads.Remove(tti); + } } - else + catch (NullReferenceException) { - // Its not active -- if its expired then remove it - if (tti.LastSeenActive + ThreadTimeout < DateTime.Now.Ticks) - m_Threads.Remove(tti); + m_Threads.Remove(tti); } } } -- cgit v1.1