diff options
author | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-25 22:46:59 +0000 |
---|---|---|
committer | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-25 22:46:59 +0000 |
commit | 95ab1553ce02175cf23278d80b8440b27740159c (patch) | |
tree | 56fc9eb4c803368b24b191c108f143c8009eb03c /base/watchdog.h | |
parent | d8375fdbe8d32ad3562152ecd53378383e393971 (diff) | |
download | chromium_src-95ab1553ce02175cf23278d80b8440b27740159c.zip chromium_src-95ab1553ce02175cf23278d80b8440b27740159c.tar.gz chromium_src-95ab1553ce02175cf23278d80b8440b27740159c.tar.bz2 |
Port base/watchdog to Linux.
BUG=4632
Review URL: http://codereview.chromium.org/11326
Patch from Pawel Hajdan Jr.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6004 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/watchdog.h')
-rw-r--r-- | base/watchdog.h | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/base/watchdog.h b/base/watchdog.h index c7e967f..63c0612 100644 --- a/base/watchdog.h +++ b/base/watchdog.h @@ -22,15 +22,15 @@ #include "base/condition_variable.h" #include "base/lock.h" +#include "base/platform_thread.h" #include "base/time.h" class Watchdog { public: - // TODO(JAR)change default arg to required arg after all users have migrated. // Constructor specifies how long the Watchdog will wait before alarming. Watchdog(const base::TimeDelta& duration, - const std::wstring& thread_watched_name, - bool enabled = true); + const std::string& thread_watched_name, + bool enabled); virtual ~Watchdog(); // Start timing, and alarm when time expires (unless we're disarm()ed.) @@ -48,22 +48,29 @@ class Watchdog { } private: - enum State {ARMED, DISARMED, SHUTDOWN }; + class ThreadDelegate : public PlatformThread::Delegate { + public: + explicit ThreadDelegate(Watchdog* watchdog, const base::TimeDelta& duration) + : watchdog_(watchdog), duration_(duration) { + } + virtual void ThreadMain(); + private: + Watchdog* watchdog_; + const base::TimeDelta duration_; // How long after start_time_ do we alarm? + + void SetThreadName() const; + }; - // Windows thread start callback - static DWORD WINAPI ThreadStart(void* pThis); + enum State {ARMED, DISARMED, SHUTDOWN }; - // Loop and test function for our watchdog thread. - unsigned Run(); - void Watchdog::SetThreadName() const; + bool init_successful_; Lock lock_; // Mutex for state_. ConditionVariable condition_variable_; State state_; - const base::TimeDelta duration_; // How long after start_time_ do we alarm? - const std::wstring thread_watched_name_; - HANDLE handle_; // Handle for watchdog thread. - DWORD thread_id_; // Also for watchdog thread. + const std::string thread_watched_name_; + PlatformThreadHandle handle_; + ThreadDelegate delegate_; // Store it, because it must outlive the thread. base::TimeTicks start_time_; // Start of epoch, and alarm after duration_. @@ -79,8 +86,7 @@ class Watchdog { // How long did we sit on a break in the debugger? static base::TimeDelta last_debugged_alarm_delay_; - - DISALLOW_EVIL_CONSTRUCTORS(Watchdog); + DISALLOW_COPY_AND_ASSIGN(Watchdog); }; #endif // BASE_WATCHDOG_H__ |