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

Side by Side Diff: base/time_win.cc

Issue 4288: Make the SystemMonitor observer list thread safe.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month 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 | « base/system_monitor_win.cc ('k') | no next file » | no next file with comments »
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 5
6 // Windows Timer Primer 6 // Windows Timer Primer
7 // 7 //
8 // A good article: http://www.ddj.com/windows/184416651 8 // A good article: http://www.ddj.com/windows/184416651
9 // A good mozilla bug: http://bugzilla.mozilla.org/show_bug.cgi?id=363258 9 // A good mozilla bug: http://bugzilla.mozilla.org/show_bug.cgi?id=363258
10 // 10 //
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 : rollover_(TimeDelta::FromMilliseconds(0)), 226 : rollover_(TimeDelta::FromMilliseconds(0)),
227 last_seen_(0), 227 last_seen_(0),
228 hi_res_clock_enabled_(false) { 228 hi_res_clock_enabled_(false) {
229 base::SystemMonitor* system = base::SystemMonitor::Get(); 229 base::SystemMonitor* system = base::SystemMonitor::Get();
230 system->AddObserver(this); 230 system->AddObserver(this);
231 UseHiResClock(!system->BatteryPower()); 231 UseHiResClock(!system->BatteryPower());
232 } 232 }
233 233
234 ~NowSingleton() { 234 ~NowSingleton() {
235 UseHiResClock(false); 235 UseHiResClock(false);
236 base::SystemMonitor::Get()->RemoveObserver(this); 236 base::SystemMonitor* monitor = base::SystemMonitor::Get();
237 if (monitor)
238 monitor->RemoveObserver(this);
237 } 239 }
238 240
239 TimeDelta Now() { 241 TimeDelta Now() {
240 AutoLock locked(lock_); 242 AutoLock locked(lock_);
241 // We should hold the lock while calling tick_function to make sure that 243 // We should hold the lock while calling tick_function to make sure that
242 // we keep our last_seen_ stay correctly in sync. 244 // we keep our last_seen_ stay correctly in sync.
243 DWORD now = tick_function(); 245 DWORD now = tick_function();
244 if (now < last_seen_) 246 if (now < last_seen_)
245 rollover_ += TimeDelta::FromMilliseconds(0x100000000I64); // ~49.7 days. 247 rollover_ += TimeDelta::FromMilliseconds(0x100000000I64); // ~49.7 days.
246 last_seen_ = now; 248 last_seen_ = now;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 388
387 // static 389 // static
388 TimeTicks TimeTicks::Now() { 390 TimeTicks TimeTicks::Now() {
389 return TimeTicks() + Singleton<NowSingleton>::get()->Now(); 391 return TimeTicks() + Singleton<NowSingleton>::get()->Now();
390 } 392 }
391 393
392 // static 394 // static
393 TimeTicks TimeTicks::HighResNow() { 395 TimeTicks TimeTicks::HighResNow() {
394 return TimeTicks() + Singleton<HighResNowSingleton>::get()->Now(); 396 return TimeTicks() + Singleton<HighResNowSingleton>::get()->Now();
395 } 397 }
OLDNEW
« no previous file with comments | « base/system_monitor_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698