PageRenderTime 611ms CodeModel.GetById 597ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LL_LLTHREADWATCHDOG_H
  27. #define LL_LLTHREADWATCHDOG_H
  28. #include <boost/function.hpp>
  29. #ifndef LL_TIMER_H
  30. #include "lltimer.h"
  31. #endif
  32. // LLWatchdogEntry is the interface used by the tasks that
  33. // need to be watched.
  34. class LLWatchdogEntry
  35. {
  36. public:
  37. LLWatchdogEntry();
  38. virtual ~LLWatchdogEntry();
  39. // isAlive is accessed by the watchdog thread.
  40. // This may mean that resources used by
  41. // isAlive and other method may need synchronization.
  42. virtual bool isAlive() const = 0;
  43. virtual void reset() = 0;
  44. virtual void start();
  45. virtual void stop();
  46. };
  47. class LLWatchdogTimeout : public LLWatchdogEntry
  48. {
  49. public:
  50. LLWatchdogTimeout();
  51. virtual ~LLWatchdogTimeout();
  52. /* virtual */ bool isAlive() const;
  53. /* virtual */ void reset();
  54. /* virtual */ void start() { start(""); }
  55. /* virtual */ void stop();
  56. void start(const std::string& state);
  57. void setTimeout(F32 d);
  58. void ping(const std::string& state);
  59. const std::string& getState() {return mPingState; }
  60. private:
  61. LLTimer mTimer;
  62. F32 mTimeout;
  63. std::string mPingState;
  64. };
  65. class LLWatchdogTimerThread; // Defined in the cpp
  66. class LLWatchdog : public LLSingleton<LLWatchdog>
  67. {
  68. public:
  69. LLWatchdog();
  70. ~LLWatchdog();
  71. // Add an entry to the watchdog.
  72. void add(LLWatchdogEntry* e);
  73. void remove(LLWatchdogEntry* e);
  74. typedef boost::function<void (void)> killer_event_callback;
  75. void init(killer_event_callback func = NULL);
  76. void run();
  77. void cleanup();
  78. private:
  79. void lockThread();
  80. void unlockThread();
  81. typedef std::set<LLWatchdogEntry*> SuspectsRegistry;
  82. SuspectsRegistry mSuspects;
  83. LLMutex* mSuspectsAccessMutex;
  84. LLWatchdogTimerThread* mTimer;
  85. U64 mLastClockCount;
  86. killer_event_callback mKillerCallback;
  87. };
  88. #endif // LL_LLTHREADWATCHDOG_H