auto merge of #10403 : poiru/rust/issue-2675, r=alexcrichton

Closes #2675.
This commit is contained in:
bors 2013-11-11 12:06:25 -08:00
commit 23746ae990

View File

@ -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) {
@ -217,18 +217,20 @@ 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;
QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_s);
if (ticks_per_s == 0LL) {
ticks_per_s = 1LL;
LARGE_INTEGER ticks_per_s;
BOOL query_result = QueryPerformanceFrequency(&ticks_per_s);
assert(query_result);
if (ticks_per_s.QuadPart == 0LL) {
ticks_per_s.QuadPart = 1LL;
}
uint64_t ticks;
QueryPerformanceCounter((LARGE_INTEGER *)&ticks);
*ns = ((ticks * ns_per_s) / ticks_per_s);
LARGE_INTEGER ticks;
query_result = QueryPerformanceCounter(&ticks);
assert(query_result);
*ns = (uint64_t)((ticks.QuadPart * ns_per_s) / ticks_per_s.QuadPart);
#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
}