aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/Watchdog.cs60
1 files changed, 30 insertions, 30 deletions
diff --git a/OpenSim/Framework/Watchdog.cs b/OpenSim/Framework/Watchdog.cs
index b905609..5d46905 100644
--- a/OpenSim/Framework/Watchdog.cs
+++ b/OpenSim/Framework/Watchdog.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Threading; 30using System.Threading;
31using log4net;
31 32
32namespace OpenSim.Framework 33namespace OpenSim.Framework
33{ 34{
@@ -66,6 +67,7 @@ namespace OpenSim.Framework
66 /// stopped or has not called UpdateThread() in time</summary> 67 /// stopped or has not called UpdateThread() in time</summary>
67 public static event WatchdogTimeout OnWatchdogTimeout; 68 public static event WatchdogTimeout OnWatchdogTimeout;
68 69
70 private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
69 private static Dictionary<int, ThreadWatchdogInfo> m_threads; 71 private static Dictionary<int, ThreadWatchdogInfo> m_threads;
70 private static System.Timers.Timer m_watchdogTimer; 72 private static System.Timers.Timer m_watchdogTimer;
71 73
@@ -95,9 +97,6 @@ namespace OpenSim.Framework
95 thread.IsBackground = isBackground; 97 thread.IsBackground = isBackground;
96 thread.Start(); 98 thread.Start();
97 99
98 lock (m_threads)
99 m_threads.Add(thread.ManagedThreadId, new ThreadWatchdogInfo(thread));
100
101 return thread; 100 return thread;
102 } 101 }
103 102
@@ -110,24 +109,6 @@ namespace OpenSim.Framework
110 } 109 }
111 110
112 /// <summary> 111 /// <summary>
113 /// Marks a thread as alive
114 /// </summary>
115 /// <param name="threadID">The ManagedThreadId of the thread to mark as
116 /// alive</param>
117 public static void UpdateThread(int threadID)
118 {
119 ThreadWatchdogInfo threadInfo;
120
121 lock (m_threads)
122 {
123 if (m_threads.TryGetValue(threadID, out threadInfo))
124 {
125 threadInfo.LastTick = Environment.TickCount & Int32.MaxValue;
126 }
127 }
128 }
129
130 /// <summary>
131 /// Stops watchdog tracking on the current thread 112 /// Stops watchdog tracking on the current thread
132 /// </summary> 113 /// </summary>
133 /// <returns>True if the thread was removed from the list of tracked 114 /// <returns>True if the thread was removed from the list of tracked
@@ -137,19 +118,38 @@ namespace OpenSim.Framework
137 return RemoveThread(Thread.CurrentThread.ManagedThreadId); 118 return RemoveThread(Thread.CurrentThread.ManagedThreadId);
138 } 119 }
139 120
140 /// <summary> 121 private static void AddThread(ThreadWatchdogInfo threadInfo)
141 /// Stops watchdog tracking on a thread 122 {
142 /// </summary> 123 m_log.Debug("[WATCHDOG]: Started tracking thread \"" + threadInfo.Thread.Name + "\" (ID " + threadInfo.Thread.ManagedThreadId + ")");
143 /// <param name="threadID">The ManagedThreadId of the thread to stop 124
144 /// tracking</param> 125 lock (m_threads)
145 /// <returns>True if the thread was removed from the list of tracked 126 m_threads.Add(threadInfo.Thread.ManagedThreadId, threadInfo);
146 /// threads, otherwise false</returns> 127 }
147 public static bool RemoveThread(int threadID) 128
129 private static bool RemoveThread(int threadID)
148 { 130 {
149 lock (m_threads) 131 lock (m_threads)
150 return m_threads.Remove(threadID); 132 return m_threads.Remove(threadID);
151 } 133 }
152 134
135 private static void UpdateThread(int threadID)
136 {
137 ThreadWatchdogInfo threadInfo;
138
139 // Although TryGetValue is not a thread safe operation, we use a try/catch here instead
140 // of a lock for speed. Adding/removing threads is a very rare operation compared to
141 // UpdateThread(), and a single UpdateThread() failure here and there won't break
142 // anything
143 try
144 {
145 if (m_threads.TryGetValue(threadID, out threadInfo))
146 threadInfo.LastTick = Environment.TickCount & Int32.MaxValue;
147 else
148 AddThread(new ThreadWatchdogInfo(Thread.CurrentThread));
149 }
150 catch { }
151 }
152
153 private static void WatchdogTimerElapsed(object sender, System.Timers.ElapsedEventArgs e) 153 private static void WatchdogTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
154 { 154 {
155 WatchdogTimeout callback = OnWatchdogTimeout; 155 WatchdogTimeout callback = OnWatchdogTimeout;
@@ -160,7 +160,7 @@ namespace OpenSim.Framework
160 160
161 lock (m_threads) 161 lock (m_threads)
162 { 162 {
163 int now = Environment.TickCount; 163 int now = Environment.TickCount & Int32.MaxValue;
164 164
165 foreach (ThreadWatchdogInfo threadInfo in m_threads.Values) 165 foreach (ThreadWatchdogInfo threadInfo in m_threads.Values)
166 { 166 {