Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: base/watchdog.cc

Issue 42266: Break up unit test to avoid internal timing interactions between parts.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/watchdog_unittest.cc » ('j') | base/watchdog_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/watchdog.h" 5 #include "base/watchdog.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/platform_thread.h" 8 #include "base/platform_thread.h"
9 9
10 using base::TimeDelta; 10 using base::TimeDelta;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 while (DISARMED == watchdog_->state_) 83 while (DISARMED == watchdog_->state_)
84 watchdog_->condition_variable_.Wait(); 84 watchdog_->condition_variable_.Wait();
85 if (SHUTDOWN == watchdog_->state_) 85 if (SHUTDOWN == watchdog_->state_)
86 return; 86 return;
87 DCHECK(ARMED == watchdog_->state_); 87 DCHECK(ARMED == watchdog_->state_);
88 remaining_duration = watchdog_->duration_ - 88 remaining_duration = watchdog_->duration_ -
89 (TimeTicks::Now() - watchdog_->start_time_); 89 (TimeTicks::Now() - watchdog_->start_time_);
90 if (remaining_duration.InMilliseconds() > 0) { 90 if (remaining_duration.InMilliseconds() > 0) {
91 // Spurios wake? Timer drifts? Go back to sleep for remaining time. 91 // Spurios wake? Timer drifts? Go back to sleep for remaining time.
92 watchdog_->condition_variable_.TimedWait(remaining_duration); 92 watchdog_->condition_variable_.TimedWait(remaining_duration);
93 } else { 93 continue;
94 // We overslept, so this seems like a real alarm. 94 }
95 // Watch out for a user that stopped the debugger on a different alarm! 95 // We overslept, so this seems like a real alarm.
96 { 96 // Watch out for a user that stopped the debugger on a different alarm!
97 AutoLock static_lock(static_lock_); 97 {
98 if (last_debugged_alarm_time_ > watchdog_->start_time_) { 98 AutoLock static_lock(static_lock_);
99 // False alarm: we started our clock before the debugger break (last 99 if (last_debugged_alarm_time_ > watchdog_->start_time_) {
100 // alarm time). 100 // False alarm: we started our clock before the debugger break (last
101 watchdog_->start_time_ += last_debugged_alarm_delay_; 101 // alarm time).
102 if (last_debugged_alarm_time_ > watchdog_->start_time_) 102 watchdog_->start_time_ += last_debugged_alarm_delay_;
103 // Too many alarms must have taken place. 103 if (last_debugged_alarm_time_ > watchdog_->start_time_)
104 watchdog_->state_ = DISARMED; 104 // Too many alarms must have taken place.
105 continue; 105 watchdog_->state_ = DISARMED;
106 } 106 continue;
107 }
108 watchdog_->state_ = DISARMED; // Only alarm at most once.
109 TimeTicks last_alarm_time = TimeTicks::Now();
110 watchdog_->Alarm(); // Set a break point here to debug on alarms.
111 TimeDelta last_alarm_delay = TimeTicks::Now() - last_alarm_time;
112 if (last_alarm_delay > TimeDelta::FromMilliseconds(2)) {
113 // Ignore race of two alarms/breaks going off at roughly the same time.
114 AutoLock static_lock(static_lock_);
115 // This was a real debugger break.
116 last_debugged_alarm_time_ = last_alarm_time;
117 last_debugged_alarm_delay_ = last_alarm_delay;
118 } 107 }
119 } 108 }
109 watchdog_->state_ = DISARMED; // Only alarm at most once.
110 TimeTicks last_alarm_time = TimeTicks::Now();
111 watchdog_->Alarm(); // Set a break point here to debug on alarms.
112 TimeDelta last_alarm_delay = TimeTicks::Now() - last_alarm_time;
113 if (last_alarm_delay <= TimeDelta::FromMilliseconds(2))
114 continue;
115 // Ignore race of two alarms/breaks going off at roughly the same time.
116 AutoLock static_lock(static_lock_);
117 // This was a real debugger break.
118 last_debugged_alarm_time_ = last_alarm_time;
119 last_debugged_alarm_delay_ = last_alarm_delay;
120 } 120 }
121 } 121 }
122 122
123 void Watchdog::ThreadDelegate::SetThreadName() const { 123 void Watchdog::ThreadDelegate::SetThreadName() const {
124 std::string name = watchdog_->thread_watched_name_ + " Watchdog"; 124 std::string name = watchdog_->thread_watched_name_ + " Watchdog";
125 PlatformThread::SetName(name.c_str()); 125 PlatformThread::SetName(name.c_str());
126 DLOG(INFO) << "Watchdog active: " << name; 126 DLOG(INFO) << "Watchdog active: " << name;
127 } 127 }
128 128
129 // static 129 // static
130 Lock Watchdog::static_lock_; // Lock for access of static data... 130 Lock Watchdog::static_lock_; // Lock for access of static data...
131 // static 131 // static
132 TimeTicks Watchdog::last_debugged_alarm_time_ = TimeTicks(); 132 TimeTicks Watchdog::last_debugged_alarm_time_ = TimeTicks();
133 // static 133 // static
134 TimeDelta Watchdog::last_debugged_alarm_delay_; 134 TimeDelta Watchdog::last_debugged_alarm_delay_;
OLDNEW
« no previous file with comments | « no previous file | base/watchdog_unittest.cc » ('j') | base/watchdog_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698