[PATCH] D42579: [sanitizer] Implement NanoTime & MonotonicNanoTime for Windows

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 26 09:14:52 PST 2018


cryptoad updated this revision to Diff 131603.
cryptoad added a comment.

Implement `NanoTime` using `QueryPerformanceCounter`. `MonotonicNanoTime` will
just call `NanoTime`.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D42579

Files:
  lib/sanitizer_common/sanitizer_win.cc


Index: lib/sanitizer_common/sanitizer_win.cc
===================================================================
--- lib/sanitizer_common/sanitizer_win.cc
+++ lib/sanitizer_common/sanitizer_win.cc
@@ -502,12 +502,19 @@
 }
 
 u64 NanoTime() {
-  return 0;
+  static LARGE_INTEGER frequency = {0};
+  LARGE_INTEGER counter;
+  if (UNLIKELY(frequency.QuadPart == 0)) {
+    QueryPerformanceFrequency(&frequency);
+    CHECK_NE(frequency.QuadPart, 0);
+  }
+  QueryPerformanceCounter(&counter);
+  counter.QuadPart *= 1000U * 1000000U;
+  counter.QuadPart /= frequency.QuadPart;
+  return counter.QuadPart;
 }
 
-u64 MonotonicNanoTime() {
-  return 0;
-}
+u64 MonotonicNanoTime() { return NanoTime(); }
 
 void Abort() {
   internal__exit(3);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42579.131603.patch
Type: text/x-patch
Size: 739 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180126/3716e947/attachment.bin>


More information about the llvm-commits mailing list