Skip to content

Commit

Permalink
Change use of unsigned integers to signed integers for clarity in
Browse files Browse the repository at this point in the history
precise_time_ns

The QueryPerformance* functions take a LARGE_INTEGER, which is a signed
64-bit integer rather than an unsigned 64-bit integer. `ts.tv_sec`, too,
is a signed integer so `ns_per_s` has been changed to a int64_t.
  • Loading branch information
poiru committed Nov 11, 2013
1 parent 3851f90 commit 61f76a5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/rt/rust_builtin.cpp
Expand Up @@ -203,7 +203,7 @@ get_time(int64_t *sec, int32_t *nsec) {
}
#endif

const uint64_t ns_per_s = 1000000000LL;
const int64_t ns_per_s = 1000000000LL;

extern "C" CDECL void
precise_time_ns(uint64_t *ns) {
Expand All @@ -217,18 +217,18 @@ precise_time_ns(uint64_t *ns) {
uint64_t time_nano = time * (info.numer / info.denom);
*ns = time_nano;
#elif __WIN32__
uint64_t ticks_per_s;
int64_t ticks_per_s;
QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_s);
if (ticks_per_s == 0LL) {
ticks_per_s = 1LL;
}
uint64_t ticks;
int64_t ticks;
QueryPerformanceCounter((LARGE_INTEGER *)&ticks);
*ns = ((ticks * ns_per_s) / ticks_per_s);
*ns = (uint64_t)((ticks * ns_per_s) / ticks_per_s);
#else
timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
*ns = (ts.tv_sec * ns_per_s + ts.tv_nsec);
*ns = (uint64_t)(ts.tv_sec * ns_per_s + ts.tv_nsec);
#endif
}

Expand Down

0 comments on commit 61f76a5

Please sign in to comment.