From 95ab1553ce02175cf23278d80b8440b27740159c Mon Sep 17 00:00:00 2001 From: "deanm@chromium.org" Date: Tue, 25 Nov 2008 22:46:59 +0000 Subject: 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 --- base/watchdog.h | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'base/watchdog.h') 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__ -- cgit v1.1