diff options
author | John Hurliman | 2009-10-26 14:41:27 -0700 |
---|---|---|
committer | John Hurliman | 2009-10-26 14:41:27 -0700 |
commit | ac7ccdf7d77810aef0a3ad70f1504fdb111dc0aa (patch) | |
tree | e27db00548a86fbf370b481ab0848bd3d30f21aa /OpenSim/Framework/Watchdog.cs | |
parent | Changed UseCircuitCode handling to be synchronous or asynchronous depending o... (diff) | |
download | opensim-SC_OLD-ac7ccdf7d77810aef0a3ad70f1504fdb111dc0aa.zip opensim-SC_OLD-ac7ccdf7d77810aef0a3ad70f1504fdb111dc0aa.tar.gz opensim-SC_OLD-ac7ccdf7d77810aef0a3ad70f1504fdb111dc0aa.tar.bz2 opensim-SC_OLD-ac7ccdf7d77810aef0a3ad70f1504fdb111dc0aa.tar.xz |
* Changed the watchdog timer to improve the speed of UpdateThread(), only track threads once the first call to UpdateThread() has been made, and allow re-tracking of threads that timed out but revived later
* Added a commented out call to Watchdog.UpdateThread() in OdeScene. If it turns out that loading a large OAR file or some other operation is timing out the heartbeat thread, we'll need to uncomment it
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Watchdog.cs | 60 |
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 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Threading; | 30 | using System.Threading; |
31 | using log4net; | ||
31 | 32 | ||
32 | namespace OpenSim.Framework | 33 | namespace 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 | { |