From e7c877407f2a72a9519eb53debca5aeef20cded9 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Tue, 6 Oct 2009 02:38:00 -0700 Subject: * Continued work on the new LLUDP implementation. Appears to be functioning, although not everything is reimplemented yet * Replaced logic in ThreadTracker with a call to System.Diagnostics that does the same thing * Added Util.StringToBytes256() and Util.StringToBytes1024() to clamp output at byte[256] and byte[1024], respectively * Fixed formatting for a MySQLAssetData error logging line --- OpenSim/Framework/ThreadTracker.cs | 127 ++----------------------------------- 1 file changed, 5 insertions(+), 122 deletions(-) (limited to 'OpenSim/Framework/ThreadTracker.cs') diff --git a/OpenSim/Framework/ThreadTracker.cs b/OpenSim/Framework/ThreadTracker.cs index d3a239d..b68d9b3 100644 --- a/OpenSim/Framework/ThreadTracker.cs +++ b/OpenSim/Framework/ThreadTracker.cs @@ -26,138 +26,21 @@ */ using System; -using System.Collections; using System.Collections.Generic; using System.Reflection; -using System.Threading; +using System.Diagnostics; using log4net; namespace OpenSim.Framework { public static class ThreadTracker { - private static readonly ILog m_log - = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private static readonly long ThreadTimeout = 30 * 10000000; - public static List m_Threads; - public static Thread ThreadTrackerThread; + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - static ThreadTracker() + public static ProcessThreadCollection GetThreads() { -#if DEBUG - m_Threads = new List(); - ThreadTrackerThread = new Thread(ThreadTrackerThreadLoop); - ThreadTrackerThread.Name = "ThreadTrackerThread"; - ThreadTrackerThread.IsBackground = true; - ThreadTrackerThread.Priority = ThreadPriority.BelowNormal; - ThreadTrackerThread.Start(); - Add(ThreadTrackerThread); -#endif + Process thisProc = Process.GetCurrentProcess(); + return thisProc.Threads; } - - private static void ThreadTrackerThreadLoop() - { - try - { - while (true) - { - Thread.Sleep(5000); - CleanUp(); - } - } - catch (Exception e) - { - m_log.ErrorFormat( - "[THREAD TRACKER]: Thread tracker cleanup thread terminating with exception. Please report this error. Exception is {0}", - e); - } - } - - public static void Add(Thread thread) - { -#if DEBUG - if (thread != null) - { - lock (m_Threads) - { - ThreadTrackerItem tti = new ThreadTrackerItem(); - tti.Thread = thread; - tti.LastSeenActive = DateTime.Now.Ticks; - m_Threads.Add(tti); - } - } -#endif - } - - public static void Remove(Thread thread) - { -#if DEBUG - lock (m_Threads) - { - foreach (ThreadTrackerItem tti in new ArrayList(m_Threads)) - { - if (tti.Thread == thread) - m_Threads.Remove(tti); - } - } -#endif - } - - public static void CleanUp() - { - lock (m_Threads) - { - foreach (ThreadTrackerItem tti in new ArrayList(m_Threads)) - { - try - { - - - 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); - } - } - catch (NullReferenceException) - { - m_Threads.Remove(tti); - } - } - } - } - - public static List GetThreads() - { - if (m_Threads == null) - return null; - - List threads = new List(); - lock (m_Threads) - { - foreach (ThreadTrackerItem tti in new ArrayList(m_Threads)) - { - threads.Add(tti.Thread); - } - } - return threads; - } - - #region Nested type: ThreadTrackerItem - - public class ThreadTrackerItem - { - public long LastSeenActive; - public Thread Thread; - } - - #endregion } } -- cgit v1.1