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

Side by Side Diff: chrome/browser/sync/util/highres_timer-win32.cc

Issue 193103: Build sync engine as part of the browser build (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // High resolution timer functions for use in Windows.
6
7 #include "chrome/browser/sync/util/highres_timer.h"
8
9 bool HighresTimer::perf_freq_collected_ = false;
10 ULONGLONG HighresTimer::perf_freq_ = 0;
11
12 ULONGLONG HighresTimer::GetElapsedMs() const {
13 ULONGLONG end_time = GetCurrentTicks();
14
15 // Scale to ms and round to nearest ms - rounding is important because
16 // otherwise the truncation error may accumulate e.g. in sums.
17 //
18 // Given infinite resolution, this expression could be written as:
19 // trunc((end - start (units:freq*sec))/freq (units:sec) *
20 // 1000 (unit:ms) + 1/2 (unit:ms))
21 ULONGLONG freq = GetTimerFrequency();
22 return ((end_time - start_ticks_) * 1000L + freq / 2) / freq;
23 }
24
25 ULONGLONG HighresTimer::GetElapsedSec() const {
26 ULONGLONG end_time = GetCurrentTicks();
27
28 // Round to nearest ms - rounding is important because otherwise the
29 // truncation error may accumulate e.g. in sums.
30 //
31 // Given infinite resolution, this expression could be written as:
32 // trunc((end - start (units:freq*sec))/freq (unit:sec) + 1/2 (unit:sec))
33 ULONGLONG freq = GetTimerFrequency();
34 return ((end_time - start_ticks_) + freq / 2) / freq;
35 }
36
37 void HighresTimer::CollectPerfFreq() {
38 LARGE_INTEGER freq;
39
40 // Note that this is racy. It's OK, however, because even concurrent
41 // executions of this are idempotent.
42 if (::QueryPerformanceFrequency(&freq)) {
43 perf_freq_ = freq.QuadPart;
44 perf_freq_collected_ = true;
45 }
46 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/util/highres_timer-win32.h ('k') | chrome/browser/sync/util/highres_timer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698