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

Side by Side Diff: util/misc/clock_win.cc

Issue 807973002: win: clock implementation (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years 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
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "util/misc/clock.h" 15 #include "util/misc/clock.h"
16 16
17 #include <time.h> 17 #include <windows.h>
18
19 #include "base/logging.h"
20 #include "base/posix/eintr_wrapper.h"
21 #include "build/build_config.h"
22
23 namespace {
24
25 const uint64_t kNanosecondsPerSecond = 1E9;
26
27 } // namespace
28 18
29 namespace crashpad { 19 namespace crashpad {
30 20
31 #if !defined(OS_MACOSX) 21 uint64_t ClockMonotonicNanoseconds() {
22 LARGE_INTEGER frequency;
23 LARGE_INTEGER time;
32 24
33 uint64_t ClockMonotonicNanoseconds() { 25 QueryPerformanceFrequency(&frequency);
Mark Mentovai 2014/12/16 23:06:54 Cache this like we do in clock_mac.cc? (TimebaseIn
Mark Mentovai 2014/12/16 23:06:54 PCHECK() or DPCHECK() this and QueryPerformanceCou
scottmg 2014/12/17 01:01:28 Done.
scottmg 2014/12/17 01:01:28 They can't fail on XP or later, so I prefer not to
34 timespec now; 26 QueryPerformanceCounter(&time);
35 int rv = clock_gettime(CLOCK_MONOTONIC, &now);
36 DPCHECK(rv == 0) << "clock_gettime";
37 27
38 return now.tv_sec * kNanosecondsPerSecond + now.tv_nsec; 28 // |time| is the elapsed number of ticks, and we have the number of
29 // ticks-per-second. Use this to convert to the number of nanoseconds.
30 time.QuadPart *= 1000000000;
Mark Mentovai 2014/12/16 23:06:54 Fear of overflow: what kind of number is frequency
Mark Mentovai 2014/12/16 23:06:54 1E9 or kNanosecondsPerSecond = 1E9?
scottmg 2014/12/17 01:01:28 Done.
scottmg 2014/12/17 01:01:28 Done.
31 time.QuadPart /= frequency.QuadPart;
32
33 return time.QuadPart;
39 } 34 }
40 35
41 #endif
42
43 void SleepNanoseconds(uint64_t nanoseconds) { 36 void SleepNanoseconds(uint64_t nanoseconds) {
44 timespec sleep_time; 37 // This is both inaccurate (will be way too long for short sleeps) and
45 sleep_time.tv_sec = nanoseconds / kNanosecondsPerSecond; 38 // incorrect (can sleep for less than requested). But it's what's available
46 sleep_time.tv_nsec = nanoseconds % kNanosecondsPerSecond; 39 // without implementing a busy loop.
47 int rv = HANDLE_EINTR(nanosleep(&sleep_time, &sleep_time)); 40 const uint64_t kNanosecondsPerMillisecond = 1000000;
Mark Mentovai 2014/12/16 23:06:54 1E6? Counting more than four identical characters
scottmg 2014/12/17 01:01:28 Done.
48 DPCHECK(rv == 0) << "nanosleep"; 41 ::Sleep(static_cast<DWORD>(nanoseconds / kNanosecondsPerMillisecond));
Mark Mentovai 2014/12/16 23:06:54 The :: isn’t necessary, unless they’re so strongly
scottmg 2014/12/17 01:01:28 Done.
49 } 42 }
50 43
51 } // namespace crashpad 44 } // namespace crashpad
OLDNEW
« util/misc/clock.h ('K') | « util/misc/clock_posix.cc ('k') | util/util.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698