aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorTedd Hansen2008-02-21 10:43:24 +0000
committerTedd Hansen2008-02-21 10:43:24 +0000
commit7102ac77698f4bfd7406d6e8871db7b006c2cae2 (patch)
tree7253775d1a6ae64e2469b1ef79863aaebe83e1d1 /OpenSim/Framework
parentRemove a couple compiler warnings. (diff)
downloadopensim-SC-7102ac77698f4bfd7406d6e8871db7b006c2cae2.zip
opensim-SC-7102ac77698f4bfd7406d6e8871db7b006c2cae2.tar.gz
opensim-SC-7102ac77698f4bfd7406d6e8871db7b006c2cae2.tar.bz2
opensim-SC-7102ac77698f4bfd7406d6e8871db7b006c2cae2.tar.xz
"threads" command now works. I've added manual tracking of threads (only if compiled in DEBUG mode)... Its ugly and even requires a separate thread to track the treads, but it will be very valuable in debugging.
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetCache.cs1
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetServerBase.cs1
-rw-r--r--OpenSim/Framework/Servers/BaseHttpServer.cs1
-rw-r--r--OpenSim/Framework/ThreadTracker.cs106
4 files changed, 109 insertions, 0 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs
index 8f8e362..15b52b0 100644
--- a/OpenSim/Framework/Communications/Cache/AssetCache.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs
@@ -171,6 +171,7 @@ namespace OpenSim.Framework.Communications.Cache
171 m_assetCacheThread.Name = "AssetCacheThread"; 171 m_assetCacheThread.Name = "AssetCacheThread";
172 m_assetCacheThread.IsBackground = true; 172 m_assetCacheThread.IsBackground = true;
173 m_assetCacheThread.Start(); 173 m_assetCacheThread.Start();
174 OpenSim.Framework.ThreadTracker.Add(m_assetCacheThread);
174 } 175 }
175 176
176 /// <summary> 177 /// <summary>
diff --git a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
index a3530bd..cae4231 100644
--- a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
@@ -101,6 +101,7 @@ namespace OpenSim.Framework.Communications.Cache
101 m_localAssetServerThread.Name = "LocalAssetServerThread"; 101 m_localAssetServerThread.Name = "LocalAssetServerThread";
102 m_localAssetServerThread.IsBackground = true; 102 m_localAssetServerThread.IsBackground = true;
103 m_localAssetServerThread.Start(); 103 m_localAssetServerThread.Start();
104 OpenSim.Framework.ThreadTracker.Add(m_localAssetServerThread);
104 } 105 }
105 106
106 private void RunRequests() 107 private void RunRequests()
diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs
index 662eefd..dc540f9 100644
--- a/OpenSim/Framework/Servers/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/BaseHttpServer.cs
@@ -550,6 +550,7 @@ namespace OpenSim.Framework.Servers
550 m_workerThread.Name = "HttpThread"; 550 m_workerThread.Name = "HttpThread";
551 m_workerThread.IsBackground = true; 551 m_workerThread.IsBackground = true;
552 m_workerThread.Start(); 552 m_workerThread.Start();
553 OpenSim.Framework.ThreadTracker.Add(m_workerThread);
553 } 554 }
554 555
555 private void StartHTTP() 556 private void StartHTTP()
diff --git a/OpenSim/Framework/ThreadTracker.cs b/OpenSim/Framework/ThreadTracker.cs
new file mode 100644
index 0000000..42e3879
--- /dev/null
+++ b/OpenSim/Framework/ThreadTracker.cs
@@ -0,0 +1,106 @@
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Text;
5using System.Threading;
6
7namespace OpenSim.Framework
8{
9 public static class ThreadTracker
10 {
11 public static List<ThreadTrackerItem> m_Threads;
12 public static System.Threading.Thread ThreadTrackerThread;
13 private static readonly long ThreadTimeout = 30 * 10000000;
14
15 static ThreadTracker()
16 {
17#if DEBUG
18 m_Threads = new List<ThreadTrackerItem>();
19 ThreadTrackerThread = new Thread(ThreadTrackerThreadLoop);
20 ThreadTrackerThread.Name = "ThreadTrackerThread";
21 ThreadTrackerThread.IsBackground = true;
22 ThreadTrackerThread.Priority = System.Threading.ThreadPriority.BelowNormal;
23 ThreadTrackerThread.Start();
24#endif
25 }
26
27 private static void ThreadTrackerThreadLoop()
28 {
29 while (true)
30 {
31 Thread.Sleep(5000);
32 CleanUp();
33 }
34 }
35
36 public static void Add(System.Threading.Thread thread)
37 {
38#if DEBUG
39 lock (m_Threads)
40 {
41 ThreadTrackerItem tti = new ThreadTrackerItem();
42 tti.Thread = thread;
43 tti.LastSeenActive = DateTime.Now.Ticks;
44 m_Threads.Add(tti);
45 }
46#endif
47 }
48
49 public static void Remove(System.Threading.Thread thread)
50 {
51#if DEBUG
52 lock (m_Threads)
53 {
54 foreach (ThreadTrackerItem tti in new ArrayList(m_Threads))
55 {
56 if (tti.Thread == thread)
57 m_Threads.Remove(tti);
58 }
59 }
60#endif
61 }
62
63 public static void CleanUp()
64 {
65 lock (m_Threads)
66 {
67 foreach (ThreadTrackerItem tti in new ArrayList(m_Threads))
68 {
69 if (tti.Thread.IsAlive)
70 {
71 // Its active
72 tti.LastSeenActive = DateTime.Now.Ticks;
73 }
74 else
75 {
76 // Its not active -- if its expired then remove it
77 if (tti.LastSeenActive + ThreadTimeout < DateTime.Now.Ticks)
78 m_Threads.Remove(tti);
79 }
80 }
81 }
82 }
83
84 public static List<Thread> GetThreads()
85 {
86 if (m_Threads == null)
87 return null;
88
89 List<Thread> threads = new List<Thread>();
90 lock (m_Threads)
91 {
92 foreach (ThreadTrackerItem tti in new ArrayList(m_Threads))
93 {
94 threads.Add(tti.Thread);
95 }
96 }
97 return threads;
98 }
99
100 public class ThreadTrackerItem
101 {
102 public System.Threading.Thread Thread;
103 public long LastSeenActive;
104 }
105 }
106}