Repository: dotnet/runtime
File: src/native/minipal/time.c (C)

Code before:
    int result = clock_gettime(CLOCK_MONOTONIC, &ts);
    assert(result == 0 && "clock_gettime(CLOCK_MONOTONIC) failed");

    return ((int64_t)(ts.tv_sec) * (int64_t)(tccSecondsToNanoSeconds)) + (int64_t)(ts.tv_nsec);
#endif
}

int64_t minipal_lowres_ticks(void)
{
#if HAVE_CLOCK_GETTIME_NSEC_NP
    return  (int64_t)clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / (int64_t)(tccMilliSecondsToNanoSeconds);
#else
    struct timespec ts;

    // emscripten exposes CLOCK_MONOTONIC_COARSE but doesn't implement it
#if HAVE_CLOCK_MONOTONIC_COARSE && !defined(__EMSCRIPTEN__)
    // CLOCK_MONOTONIC_COARSE has enough precision for GetTickCount but
    // doesn't have the same overhead as CLOCK_MONOTONIC. This allows
    // overall higher throughput. See dotnet/coreclr#2257 for more details.

    const clockid_t clockType = CLOCK_MONOTONIC_COARSE;
#else
    const clockid_t clockType = CLOCK_MONOTONIC;
#endif

    int result = clock_gettime(clockType, &ts);
#if HAVE_CLOCK_MONOTONIC_COARSE && !defined(__EMSCRIPTEN__)
    assert(result == 0 && "clock_gettime(CLOCK_MONOTONIC_COARSE) failed");
#else
    assert(result == 0 && "clock_gettime(CLOCK_MONOTONIC) failed");
#endif

    return ((int64_t)(ts.tv_sec) * (int64_t)(tccSecondsToMilliSeconds)) + ((int64_t)(ts.tv_nsec) / (int64_t)(tccMilliSecondsToNanoSeconds));
#endif
}

uint64_t minipal_get_system_time(void)
{
    struct timespec ts;
    if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
    {
        assert(!"clock_gettime(CLOCK_REALTIME) failed");
    }

    const uint64_t SECS_BETWEEN_1601_AND_1970_EPOCHS = 11644473600LL;
    return ((uint64_t)(ts.tv_sec) + SECS_BETWEEN_1601_AND_1970_EPOCHS) * tccSecondsTo100NS + (ts.tv_nsec / 100);
}

#endif // HOST_WINDOWS

void minipal_microdelay(uint32_t usecs, uint32_t* usecsSinceYield)

Review comment (suggestion):
```suggestion
    int result;
    result = clock_gettime(clockType, &ts);
```

Code after:
    int result;
    result = clock_gettime(CLOCK_MONOTONIC, &ts);
    assert(result == 0 && "clock_gettime(CLOCK_MONOTONIC) failed");

    return ((int64_t)(ts.tv_sec) * (int64_t)(tccSecondsToNanoSeconds)) + (int64_t)(ts.tv_nsec);
#endif
}

int64_t minipal_lowres_ticks(void)
{
#if HAVE_CLOCK_GETTIME_NSEC_NP
    return  (int64_t)clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / (int64_t)(tccMilliSecondsToNanoSeconds);
#else
    struct timespec ts;

    // emscripten exposes CLOCK_MONOTONIC_COARSE but doesn't implement it
#if HAVE_CLOCK_MONOTONIC_COARSE && !defined(__EMSCRIPTEN__)
    // CLOCK_MONOTONIC_COARSE has enough precision for GetTickCount but
    // doesn't have the same overhead as CLOCK_MONOTONIC. This allows
    // overall higher throughput. See dotnet/coreclr#2257 for more details.

    const clockid_t clockType = CLOCK_MONOTONIC_COARSE;
#else
    const clockid_t clockType = CLOCK_MONOTONIC;
#endif

    int result;
    result = clock_gettime(clockType, &ts);
#if HAVE_CLOCK_MONOTONIC_COARSE && !defined(__EMSCRIPTEN__)
    assert(result == 0 && "clock_gettime(CLOCK_MONOTONIC_COARSE) failed");
#else
    assert(result == 0 && "clock_gettime(CLOCK_MONOTONIC) failed");
#endif

    return ((int64_t)(ts.tv_sec) * (int64_t)(tccSecondsToMilliSeconds)) + ((int64_t)(ts.tv_nsec) / (int64_t)(tccMilliSecondsToNanoSeconds));
#endif
}

uint64_t minipal_get_system_time(void)
{
    struct timespec ts;
    if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
    {
        assert(!"clock_gettime(CLOCK_REALTIME) failed");
    }

    const uint64_t SECS_BETWEEN_1601_AND_1970_EPOCHS = 11644473600LL;
    return ((uint64_t)(ts.tv_sec) + SECS_BETWEEN_1601_AND_1970_EPOCHS) * tccSecondsTo100NS + (ts.tv_nsec / 100);
}

#endif // HOST_WINDOWS