PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llwatchdog.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 105 lines | 57 code | 17 blank | 31 comment | 0 complexity | d76b200e0c709ef4014d1233da17265f MD5 | raw file
  1/** 
  2 * @file llthreadwatchdog.h
  3 * @brief The LLThreadWatchdog class declaration
  4 *
  5 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLTHREADWATCHDOG_H
 28#define LL_LLTHREADWATCHDOG_H
 29
 30#include <boost/function.hpp>
 31
 32#ifndef LL_TIMER_H					
 33	#include "lltimer.h"
 34#endif
 35
 36// LLWatchdogEntry is the interface used by the tasks that 
 37// need to be watched.
 38class LLWatchdogEntry
 39{
 40public:
 41	LLWatchdogEntry();
 42	virtual ~LLWatchdogEntry();
 43
 44	// isAlive is accessed by the watchdog thread.
 45	// This may mean that resources used by 
 46	// isAlive and other method may need synchronization.
 47	virtual bool isAlive() const = 0;
 48	virtual void reset() = 0;
 49	virtual void start();
 50	virtual void stop();
 51};
 52
 53class LLWatchdogTimeout : public LLWatchdogEntry
 54{
 55public:
 56	LLWatchdogTimeout();
 57	virtual ~LLWatchdogTimeout();
 58
 59	/* virtual */ bool isAlive() const;
 60	/* virtual */ void reset();
 61	/* virtual */ void start() { start(""); }
 62	/* virtual */ void stop();
 63
 64	void start(const std::string& state); 
 65	void setTimeout(F32 d);
 66	void ping(const std::string& state);
 67	const std::string& getState() {return mPingState; }
 68
 69private:
 70	LLTimer mTimer;
 71	F32 mTimeout;
 72	std::string mPingState;
 73};
 74
 75class LLWatchdogTimerThread; // Defined in the cpp
 76class LLWatchdog : public LLSingleton<LLWatchdog>
 77{
 78public:
 79	LLWatchdog();
 80	~LLWatchdog();
 81
 82	// Add an entry to the watchdog.
 83	void add(LLWatchdogEntry* e);
 84	void remove(LLWatchdogEntry* e);
 85
 86	typedef boost::function<void (void)> killer_event_callback;
 87
 88	void init(killer_event_callback func = NULL);
 89	void run();
 90	void cleanup();
 91    
 92private:
 93	void lockThread();
 94	void unlockThread();
 95
 96	typedef std::set<LLWatchdogEntry*> SuspectsRegistry;
 97	SuspectsRegistry mSuspects;
 98	LLMutex* mSuspectsAccessMutex;
 99	LLWatchdogTimerThread* mTimer;
100	U64 mLastClockCount;
101
102	killer_event_callback mKillerCallback;
103};
104
105#endif // LL_LLTHREADWATCHDOG_H