Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Remove dependency on MonoTime.ticksPerSecond as it's not always ready.
Browse files Browse the repository at this point in the history
  • Loading branch information
schveiguy committed Apr 29, 2015
1 parent d0fd2c0 commit a880fe8
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/gc/gc.d
Expand Up @@ -61,7 +61,35 @@ else import core.stdc.stdio : sprintf, printf; // needed to ou

import core.time;
alias currTime = MonoTime.currTime;
long currTicks() { return MonoTime.ticksPerSecond ? MonoTime.currTime.ticks : 0; }
debug(PROFILE_API)
{
long currTicks() nothrow @nogc
{
// MonoTime.ticksPerSecond may not be ready yet. So just avoid it altogether
// this is copied from core.time.MonoTime.currTime
//return MonoTime.ticksPerSecond ? MonoTime.currTime.ticks : 0;
version(Windows)
{
long ticks;
if(QueryPerformanceCounter(&ticks) == 0)
{
// This probably cannot happen on Windows 95 or later
assert(0, "Call to QueryPerformanceCounter failed.");
}
return ticks;
}
else version(OSX)
return mach_absolute_time();
else version(Posix)
{
timespec ts;
if(clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
assert(0, "Call to clock_gettime failed.");

return ts.tv_sec * 1_000_000_000L + ts.tv_nsec;
}
}
}

debug(PRINTF_TO_FILE)
{
Expand Down

0 comments on commit a880fe8

Please sign in to comment.