Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

win: uv_hrtime() return non-incremental value #850

Closed
witchu opened this issue Jul 12, 2013 · 2 comments
Closed

win: uv_hrtime() return non-incremental value #850

witchu opened this issue Jul 12, 2013 · 2 comments
Labels

Comments

@witchu
Copy link

witchu commented Jul 12, 2013

on windows server (windows with high performance frequency) when call uv_hrtime() many times, return values will decrease sometimes.

to fix please apply:

1a39914af186f5db73ba8507d60da5d3bb3e39dc
 src/win/util.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/win/util.c b/src/win/util.c
index f19d30a..2deb39d 100644
--- a/src/win/util.c
+++ b/src/win/util.c
@@ -460,8 +460,8 @@ uint64_t uv_hrtime(void) {
   /* performance counter frequency, and there may not be much headroom to */
   /* multiply by NANOSEC without overflowing, we use 128-bit math instead. */
   return ((uint64_t) counter.LowPart * NANOSEC / hrtime_frequency_) +
-         (((uint64_t) counter.HighPart * NANOSEC / hrtime_frequency_)
-         << 32);
+         (((uint64_t) counter.HighPart * NANOSEC / hrtime_frequency_) << 32) +
+         (((uint64_t) counter.HighPart * NANOSEC % hrtime_frequency_) * 4294967296 / hrtime_frequency_);
 }

@bnoordhuis
Copy link
Contributor

/cc @piscisaureus - this has been open for a while now.

@Keno
Copy link
Contributor

Keno commented Oct 21, 2013

Can we get this applied?

vtjnash referenced this issue in JuliaAttic/libuv-archive Jan 1, 2014
Large performance counter frequency values would cause overflows, even
when 64-bit integers were used to do the multiplication with NANOSEC.
Fix this by using floating point math instead.

Fixes #850
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants