aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llwatchdog.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:54 -0500
committerJacek Antonelli2008-08-15 23:45:54 -0500
commitd0b03a62fd799317d5da0bd56615739ce3b5b052 (patch)
tree8bc79bbbb52e18294f62810d9fa66ce136f90e2d /linden/indra/newview/llwatchdog.cpp
parentSecond Life viewer sources 1.20.8 (diff)
downloadmeta-impy-d0b03a62fd799317d5da0bd56615739ce3b5b052.zip
meta-impy-d0b03a62fd799317d5da0bd56615739ce3b5b052.tar.gz
meta-impy-d0b03a62fd799317d5da0bd56615739ce3b5b052.tar.bz2
meta-impy-d0b03a62fd799317d5da0bd56615739ce3b5b052.tar.xz
Second Life viewer sources 1.20.9
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/llwatchdog.cpp68
1 files changed, 52 insertions, 16 deletions
diff --git a/linden/indra/newview/llwatchdog.cpp b/linden/indra/newview/llwatchdog.cpp
index d92d381..55975ee 100644
--- a/linden/indra/newview/llwatchdog.cpp
+++ b/linden/indra/newview/llwatchdog.cpp
@@ -33,6 +33,8 @@
33#include "llviewerprecompiledheaders.h" 33#include "llviewerprecompiledheaders.h"
34#include "llwatchdog.h" 34#include "llwatchdog.h"
35 35
36const U32 WATCHDOG_SLEEP_TIME_USEC = 1000000;
37
36// This class runs the watchdog timing thread. 38// This class runs the watchdog timing thread.
37class LLWatchdogTimerThread : public LLThread 39class LLWatchdogTimerThread : public LLThread
38{ 40{
@@ -105,6 +107,11 @@ bool LLWatchdogTimeout::isAlive() const
105 return (mTimer.getStarted() && !mTimer.hasExpired()); 107 return (mTimer.getStarted() && !mTimer.hasExpired());
106} 108}
107 109
110void LLWatchdogTimeout::reset()
111{
112 mTimer.setTimerExpirySec(mTimeout);
113}
114
108void LLWatchdogTimeout::setTimeout(F32 d) 115void LLWatchdogTimeout::setTimeout(F32 d)
109{ 116{
110 mTimeout = d; 117 mTimeout = d;
@@ -132,13 +139,14 @@ void LLWatchdogTimeout::ping(const std::string& state)
132 { 139 {
133 mPingState = state; 140 mPingState = state;
134 } 141 }
135 mTimer.setTimerExpirySec(mTimeout); 142 reset();
136} 143}
137 144
138// LlWatchdog 145// LLWatchdog
139LLWatchdog::LLWatchdog() : 146LLWatchdog::LLWatchdog() :
140 mSuspectsAccessMutex(NULL), 147 mSuspectsAccessMutex(NULL),
141 mTimer(NULL) 148 mTimer(NULL),
149 mLastClockCount(0)
142{ 150{
143} 151}
144 152
@@ -166,7 +174,11 @@ void LLWatchdog::init()
166 { 174 {
167 mSuspectsAccessMutex = new LLMutex(NULL); 175 mSuspectsAccessMutex = new LLMutex(NULL);
168 mTimer = new LLWatchdogTimerThread(); 176 mTimer = new LLWatchdogTimerThread();
169 mTimer->setSleepTime(1000); 177 mTimer->setSleepTime(WATCHDOG_SLEEP_TIME_USEC / 1000);
178 mLastClockCount = LLTimer::getTotalTime();
179
180 // mTimer->start() kicks off the thread, any code after
181 // start needs to use the mSuspectsAccessMutex
170 mTimer->start(); 182 mTimer->start();
171 } 183 }
172} 184}
@@ -177,40 +189,64 @@ void LLWatchdog::cleanup()
177 { 189 {
178 mTimer->stop(); 190 mTimer->stop();
179 delete mTimer; 191 delete mTimer;
192 mTimer = NULL;
180 } 193 }
181 194
182 if(mSuspectsAccessMutex) 195 if(mSuspectsAccessMutex)
183 { 196 {
184 delete mSuspectsAccessMutex; 197 delete mSuspectsAccessMutex;
198 mSuspectsAccessMutex = NULL;
185 } 199 }
200
201 mLastClockCount = 0;
186} 202}
187 203
188void LLWatchdog::run() 204void LLWatchdog::run()
189{ 205{
190 lockThread(); 206 lockThread();
207
208 // Check the time since the last call to run...
209 // If the time elapsed is two times greater than the regualr sleep time
210 // reset the active timeouts.
211 const U32 TIME_ELAPSED_MULTIPLIER = 2;
212 U64 current_time = LLTimer::getTotalTime();
213 U64 current_run_delta = current_time - mLastClockCount;
214 mLastClockCount = current_time;
191 215
192 SuspectsRegistry::iterator result = 216 if(current_run_delta > (WATCHDOG_SLEEP_TIME_USEC * TIME_ELAPSED_MULTIPLIER))
193 std::find_if(mSuspects.begin(), 217 {
218 llinfos << "Watchdog thread delayed: resetting entries." << llendl;
219 std::for_each(mSuspects.begin(),
194 mSuspects.end(), 220 mSuspects.end(),
195 std::not1(std::mem_fun(&LLWatchdogEntry::isAlive)) 221 std::mem_fun(&LLWatchdogEntry::reset)
196 ); 222 );
197 223 }
198 if(result != mSuspects.end()) 224 else
199 { 225 {
200 // error!!! 226 SuspectsRegistry::iterator result =
201 if(mTimer) 227 std::find_if(mSuspects.begin(),
228 mSuspects.end(),
229 std::not1(std::mem_fun(&LLWatchdogEntry::isAlive))
230 );
231
232 if(result != mSuspects.end())
202 { 233 {
203 mTimer->stop(); 234 // error!!!
204 } 235 if(mTimer)
236 {
237 mTimer->stop();
238 }
205 239
206 llinfos << "Watchdog detected error:" << llendl; 240 llinfos << "Watchdog detected error:" << llendl;
207#ifdef LL_WINDOWS 241#ifdef LL_WINDOWS
208 RaiseException(0,0,0,0); 242 RaiseException(0,0,0,0);
209#else 243#else
210 raise(SIGQUIT); 244 raise(SIGQUIT);
211#endif 245#endif
246 }
212 } 247 }
213 248
249
214 unlockThread(); 250 unlockThread();
215} 251}
216 252