aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/ThreadTracker.cs212
1 files changed, 106 insertions, 106 deletions
diff --git a/OpenSim/Framework/ThreadTracker.cs b/OpenSim/Framework/ThreadTracker.cs
index 42e3879..2f6d70d 100644
--- a/OpenSim/Framework/ThreadTracker.cs
+++ b/OpenSim/Framework/ThreadTracker.cs
@@ -1,106 +1,106 @@
1using System; 1using System;
2using System.Collections; 2using System.Collections;
3using System.Collections.Generic; 3using System.Collections.Generic;
4using System.Text; 4using System.Text;
5using System.Threading; 5using System.Threading;
6 6
7namespace OpenSim.Framework 7namespace OpenSim.Framework
8{ 8{
9 public static class ThreadTracker 9 public static class ThreadTracker
10 { 10 {
11 public static List<ThreadTrackerItem> m_Threads; 11 public static List<ThreadTrackerItem> m_Threads;
12 public static System.Threading.Thread ThreadTrackerThread; 12 public static System.Threading.Thread ThreadTrackerThread;
13 private static readonly long ThreadTimeout = 30 * 10000000; 13 private static readonly long ThreadTimeout = 30 * 10000000;
14 14
15 static ThreadTracker() 15 static ThreadTracker()
16 { 16 {
17#if DEBUG 17#if DEBUG
18 m_Threads = new List<ThreadTrackerItem>(); 18 m_Threads = new List<ThreadTrackerItem>();
19 ThreadTrackerThread = new Thread(ThreadTrackerThreadLoop); 19 ThreadTrackerThread = new Thread(ThreadTrackerThreadLoop);
20 ThreadTrackerThread.Name = "ThreadTrackerThread"; 20 ThreadTrackerThread.Name = "ThreadTrackerThread";
21 ThreadTrackerThread.IsBackground = true; 21 ThreadTrackerThread.IsBackground = true;
22 ThreadTrackerThread.Priority = System.Threading.ThreadPriority.BelowNormal; 22 ThreadTrackerThread.Priority = System.Threading.ThreadPriority.BelowNormal;
23 ThreadTrackerThread.Start(); 23 ThreadTrackerThread.Start();
24#endif 24#endif
25 } 25 }
26 26
27 private static void ThreadTrackerThreadLoop() 27 private static void ThreadTrackerThreadLoop()
28 { 28 {
29 while (true) 29 while (true)
30 { 30 {
31 Thread.Sleep(5000); 31 Thread.Sleep(5000);
32 CleanUp(); 32 CleanUp();
33 } 33 }
34 } 34 }
35 35
36 public static void Add(System.Threading.Thread thread) 36 public static void Add(System.Threading.Thread thread)
37 { 37 {
38#if DEBUG 38#if DEBUG
39 lock (m_Threads) 39 lock (m_Threads)
40 { 40 {
41 ThreadTrackerItem tti = new ThreadTrackerItem(); 41 ThreadTrackerItem tti = new ThreadTrackerItem();
42 tti.Thread = thread; 42 tti.Thread = thread;
43 tti.LastSeenActive = DateTime.Now.Ticks; 43 tti.LastSeenActive = DateTime.Now.Ticks;
44 m_Threads.Add(tti); 44 m_Threads.Add(tti);
45 } 45 }
46#endif 46#endif
47 } 47 }
48 48
49 public static void Remove(System.Threading.Thread thread) 49 public static void Remove(System.Threading.Thread thread)
50 { 50 {
51#if DEBUG 51#if DEBUG
52 lock (m_Threads) 52 lock (m_Threads)
53 { 53 {
54 foreach (ThreadTrackerItem tti in new ArrayList(m_Threads)) 54 foreach (ThreadTrackerItem tti in new ArrayList(m_Threads))
55 { 55 {
56 if (tti.Thread == thread) 56 if (tti.Thread == thread)
57 m_Threads.Remove(tti); 57 m_Threads.Remove(tti);
58 } 58 }
59 } 59 }
60#endif 60#endif
61 } 61 }
62 62
63 public static void CleanUp() 63 public static void CleanUp()
64 { 64 {
65 lock (m_Threads) 65 lock (m_Threads)
66 { 66 {
67 foreach (ThreadTrackerItem tti in new ArrayList(m_Threads)) 67 foreach (ThreadTrackerItem tti in new ArrayList(m_Threads))
68 { 68 {
69 if (tti.Thread.IsAlive) 69 if (tti.Thread.IsAlive)
70 { 70 {
71 // Its active 71 // Its active
72 tti.LastSeenActive = DateTime.Now.Ticks; 72 tti.LastSeenActive = DateTime.Now.Ticks;
73 } 73 }
74 else 74 else
75 { 75 {
76 // Its not active -- if its expired then remove it 76 // Its not active -- if its expired then remove it
77 if (tti.LastSeenActive + ThreadTimeout < DateTime.Now.Ticks) 77 if (tti.LastSeenActive + ThreadTimeout < DateTime.Now.Ticks)
78 m_Threads.Remove(tti); 78 m_Threads.Remove(tti);
79 } 79 }
80 } 80 }
81 } 81 }
82 } 82 }
83 83
84 public static List<Thread> GetThreads() 84 public static List<Thread> GetThreads()
85 { 85 {
86 if (m_Threads == null) 86 if (m_Threads == null)
87 return null; 87 return null;
88 88
89 List<Thread> threads = new List<Thread>(); 89 List<Thread> threads = new List<Thread>();
90 lock (m_Threads) 90 lock (m_Threads)
91 { 91 {
92 foreach (ThreadTrackerItem tti in new ArrayList(m_Threads)) 92 foreach (ThreadTrackerItem tti in new ArrayList(m_Threads))
93 { 93 {
94 threads.Add(tti.Thread); 94 threads.Add(tti.Thread);
95 } 95 }
96 } 96 }
97 return threads; 97 return threads;
98 } 98 }
99 99
100 public class ThreadTrackerItem 100 public class ThreadTrackerItem
101 { 101 {
102 public System.Threading.Thread Thread; 102 public System.Threading.Thread Thread;
103 public long LastSeenActive; 103 public long LastSeenActive;
104 } 104 }
105 } 105 }
106} 106}