aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorBlueWall2012-02-25 14:33:56 -0500
committerBlueWall2012-02-25 14:33:56 -0500
commit4177571a786f6ece38b29dc60328348fbe45b481 (patch)
treebc06a7f13fc5e751cfab5ef58bd3e9b612e12ba9 /OpenSim/Framework
parentMerge branch 'master' into v3_support (diff)
parentPRIM_SCULPT_FLAG_INVERT, PRIM_SCULPT_FLAG_MIRROR implemented (diff)
downloadopensim-SC_OLD-4177571a786f6ece38b29dc60328348fbe45b481.zip
opensim-SC_OLD-4177571a786f6ece38b29dc60328348fbe45b481.tar.gz
opensim-SC_OLD-4177571a786f6ece38b29dc60328348fbe45b481.tar.bz2
opensim-SC_OLD-4177571a786f6ece38b29dc60328348fbe45b481.tar.xz
Merge branch 'master' of ssh://opensimulator.org/var/git/opensim into v3_support
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/Servers/BaseOpenSimServer.cs2
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs2
-rw-r--r--OpenSim/Framework/Watchdog.cs72
3 files changed, 57 insertions, 19 deletions
diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
index 0dd01af..6a3135e 100644
--- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs
+++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
@@ -247,7 +247,7 @@ namespace OpenSim.Framework.Servers
247 string reportFormat = "{0,6} {1,35} {2,16} {3,13} {4,10} {5,30}"; 247 string reportFormat = "{0,6} {1,35} {2,16} {3,13} {4,10} {5,30}";
248 248
249 StringBuilder sb = new StringBuilder(); 249 StringBuilder sb = new StringBuilder();
250 Watchdog.ThreadWatchdogInfo[] threads = Watchdog.GetThreads(); 250 Watchdog.ThreadWatchdogInfo[] threads = Watchdog.GetThreadsInfo();
251 251
252 sb.Append(threads.Length + " threads are being tracked:" + Environment.NewLine); 252 sb.Append(threads.Length + " threads are being tracked:" + Environment.NewLine);
253 253
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
index 2206feb..0062d4e 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
@@ -65,6 +65,7 @@ namespace OpenSim.Framework.Servers.HttpServer
65 String.Format("PollServiceWorkerThread{0}", i), 65 String.Format("PollServiceWorkerThread{0}", i),
66 ThreadPriority.Normal, 66 ThreadPriority.Normal,
67 false, 67 false,
68 true,
68 int.MaxValue); 69 int.MaxValue);
69 } 70 }
70 71
@@ -73,6 +74,7 @@ namespace OpenSim.Framework.Servers.HttpServer
73 "PollServiceWatcherThread", 74 "PollServiceWatcherThread",
74 ThreadPriority.Normal, 75 ThreadPriority.Normal,
75 false, 76 false,
77 true,
76 1000 * 60 * 10); 78 1000 * 60 * 10);
77 } 79 }
78 80
diff --git a/OpenSim/Framework/Watchdog.cs b/OpenSim/Framework/Watchdog.cs
index 2dd6ebe..e93e50e 100644
--- a/OpenSim/Framework/Watchdog.cs
+++ b/OpenSim/Framework/Watchdog.cs
@@ -72,6 +72,11 @@ namespace OpenSim.Framework
72 /// </summary> 72 /// </summary>
73 public bool IsTimedOut { get; set; } 73 public bool IsTimedOut { get; set; }
74 74
75 /// <summary>
76 /// Will this thread trigger the alarm function if it has timed out?
77 /// </summary>
78 public bool AlarmIfTimeout { get; set; }
79
75 public ThreadWatchdogInfo(Thread thread, int timeout) 80 public ThreadWatchdogInfo(Thread thread, int timeout)
76 { 81 {
77 Thread = thread; 82 Thread = thread;
@@ -112,12 +117,13 @@ namespace OpenSim.Framework
112 /// <param name="start">The method that will be executed in a new thread</param> 117 /// <param name="start">The method that will be executed in a new thread</param>
113 /// <param name="name">A name to give to the new thread</param> 118 /// <param name="name">A name to give to the new thread</param>
114 /// <param name="priority">Priority to run the thread at</param> 119 /// <param name="priority">Priority to run the thread at</param>
115 /// <param name="isBackground">True to run this thread as a background 120 /// <param name="isBackground">True to run this thread as a background thread, otherwise false</param>
116 /// thread, otherwise false</param> 121 /// <param name="alarmIfTimeout">Trigger an alarm function is we have timed out</param>
117 /// <returns>The newly created Thread object</returns> 122 /// <returns>The newly created Thread object</returns>
118 public static Thread StartThread(ThreadStart start, string name, ThreadPriority priority, bool isBackground) 123 public static Thread StartThread(
124 ThreadStart start, string name, ThreadPriority priority, bool isBackground, bool alarmIfTimeout)
119 { 125 {
120 return StartThread(start, name, priority, isBackground, WATCHDOG_TIMEOUT_MS); 126 return StartThread(start, name, priority, isBackground, alarmIfTimeout, WATCHDOG_TIMEOUT_MS);
121 } 127 }
122 128
123 /// <summary> 129 /// <summary>
@@ -128,21 +134,21 @@ namespace OpenSim.Framework
128 /// <param name="priority">Priority to run the thread at</param> 134 /// <param name="priority">Priority to run the thread at</param>
129 /// <param name="isBackground">True to run this thread as a background 135 /// <param name="isBackground">True to run this thread as a background
130 /// thread, otherwise false</param> 136 /// thread, otherwise false</param>
131 /// <param name="timeout"> 137 /// <param name="alarmIfTimeout">Trigger an alarm function is we have timed out</param>
132 /// Number of milliseconds to wait until we issue a warning about timeout. 138 /// <param name="timeout">Number of milliseconds to wait until we issue a warning about timeout.</param>
133 /// </para>
134 /// <returns>The newly created Thread object</returns> 139 /// <returns>The newly created Thread object</returns>
135 public static Thread StartThread( 140 public static Thread StartThread(
136 ThreadStart start, string name, ThreadPriority priority, bool isBackground, int timeout) 141 ThreadStart start, string name, ThreadPriority priority, bool isBackground, bool alarmIfTimeout, int timeout)
137 { 142 {
138 Thread thread = new Thread(start); 143 Thread thread = new Thread(start);
139 thread.Name = name; 144 thread.Name = name;
140 thread.Priority = priority; 145 thread.Priority = priority;
141 thread.IsBackground = isBackground; 146 thread.IsBackground = isBackground;
142 147
143 ThreadWatchdogInfo twi = new ThreadWatchdogInfo(thread, timeout); 148 ThreadWatchdogInfo twi = new ThreadWatchdogInfo(thread, timeout) { AlarmIfTimeout = alarmIfTimeout };
144 149
145 m_log.Debug("[WATCHDOG]: Started tracking thread \"" + twi.Thread.Name + "\" (ID " + twi.Thread.ManagedThreadId + ")"); 150 m_log.DebugFormat(
151 "[WATCHDOG]: Started tracking thread {0}, ID {1}", twi.Thread.Name, twi.Thread.ManagedThreadId);
146 152
147 lock (m_threads) 153 lock (m_threads)
148 m_threads.Add(twi.Thread.ManagedThreadId, twi); 154 m_threads.Add(twi.Thread.ManagedThreadId, twi);
@@ -224,19 +230,39 @@ namespace OpenSim.Framework
224 /// Get currently watched threads for diagnostic purposes 230 /// Get currently watched threads for diagnostic purposes
225 /// </summary> 231 /// </summary>
226 /// <returns></returns> 232 /// <returns></returns>
227 public static ThreadWatchdogInfo[] GetThreads() 233 public static ThreadWatchdogInfo[] GetThreadsInfo()
228 { 234 {
229 lock (m_threads) 235 lock (m_threads)
230 return m_threads.Values.ToArray(); 236 return m_threads.Values.ToArray();
231 } 237 }
232 238
239 /// <summary>
240 /// Return the current thread's watchdog info.
241 /// </summary>
242 /// <returns>The watchdog info. null if the thread isn't being monitored.</returns>
243 public static ThreadWatchdogInfo GetCurrentThreadInfo()
244 {
245 lock (m_threads)
246 {
247 if (m_threads.ContainsKey(Thread.CurrentThread.ManagedThreadId))
248 return m_threads[Thread.CurrentThread.ManagedThreadId];
249 }
250
251 return null;
252 }
253
254 /// <summary>
255 /// Check watched threads. Fire alarm if appropriate.
256 /// </summary>
257 /// <param name="sender"></param>
258 /// <param name="e"></param>
233 private static void WatchdogTimerElapsed(object sender, System.Timers.ElapsedEventArgs e) 259 private static void WatchdogTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
234 { 260 {
235 WatchdogTimeout callback = OnWatchdogTimeout; 261 WatchdogTimeout callback = OnWatchdogTimeout;
236 262
237 if (callback != null) 263 if (callback != null)
238 { 264 {
239 ThreadWatchdogInfo timedOut = null; 265 List<ThreadWatchdogInfo> callbackInfos = null;
240 266
241 lock (m_threads) 267 lock (m_threads)
242 { 268 {
@@ -246,21 +272,31 @@ namespace OpenSim.Framework
246 { 272 {
247 if (threadInfo.Thread.ThreadState == ThreadState.Stopped) 273 if (threadInfo.Thread.ThreadState == ThreadState.Stopped)
248 { 274 {
249 timedOut = threadInfo;
250 RemoveThread(threadInfo.Thread.ManagedThreadId); 275 RemoveThread(threadInfo.Thread.ManagedThreadId);
251 break; 276
277 if (callbackInfos == null)
278 callbackInfos = new List<ThreadWatchdogInfo>();
279
280 callbackInfos.Add(threadInfo);
252 } 281 }
253 else if (!threadInfo.IsTimedOut && now - threadInfo.LastTick >= threadInfo.Timeout) 282 else if (!threadInfo.IsTimedOut && now - threadInfo.LastTick >= threadInfo.Timeout)
254 { 283 {
255 threadInfo.IsTimedOut = true; 284 threadInfo.IsTimedOut = true;
256 timedOut = threadInfo; 285
257 break; 286 if (threadInfo.AlarmIfTimeout)
287 {
288 if (callbackInfos == null)
289 callbackInfos = new List<ThreadWatchdogInfo>();
290
291 callbackInfos.Add(threadInfo);
292 }
258 } 293 }
259 } 294 }
260 } 295 }
261 296
262 if (timedOut != null) 297 if (callbackInfos != null)
263 callback(timedOut.Thread, timedOut.LastTick); 298 foreach (ThreadWatchdogInfo callbackInfo in callbackInfos)
299 callback(callbackInfo.Thread, callbackInfo.LastTick);
264 } 300 }
265 301
266 m_watchdogTimer.Start(); 302 m_watchdogTimer.Start();