Repository: dotnet/runtime
File: src/coreclr/pal/src/synchmgr/synchmanager.cpp (C++)

Code before:

    /*++
    Method:
      CPalSynchronizationManager::InterlockedAwaken

    Tries to change the target wait status to 'active' in an interlocked fashion
    --*/
    bool CPalSynchronizationManager::InterlockedAwaken(
        DWORD *pWaitState)
    {
        return InterlockedCompareExchange((LONG *)pWaitState, TWS_ACTIVE, TWS_WAITING) == TWS_WAITING;
    }

    /*++
    Method:
      CPalSynchronizationManager::GetAbsoluteTimeout

    Converts a relative timeout to an absolute one.
    --*/
    PAL_ERROR CPalSynchronizationManager::GetAbsoluteTimeout(DWORD dwTimeout, struct timespec * ptsAbsTmo, BOOL fPreferMonotonicClock)
    {
        PAL_ERROR palErr = NO_ERROR;
        int iRet;

#if HAVE_PTHREAD_CONDATTR_SETCLOCK
        if (fPreferMonotonicClock)
        {
            iRet = clock_gettime(CLOCK_MONOTONIC, ptsAbsTmo);
        }
        else
        {
#endif
#if HAVE_WORKING_CLOCK_GETTIME
            // Not every platform implements a (working) clock_gettime
            iRet = clock_gettime(CLOCK_REALTIME, ptsAbsTmo);
#elif HAVE_WORKING_GETTIMEOFDAY
            // Not every platform implements a (working) gettimeofday
            struct timeval tv;
            iRet = gettimeofday(&tv, NULL);
            if (0 == iRet)
            {
                ptsAbsTmo->tv_sec  = tv.tv_sec;
                ptsAbsTmo->tv_nsec = tv.tv_usec * tccMicroSecondsToNanoSeconds;
            }
#else
#ifdef DBI_COMPONENT_MONO
    return ERROR_INTERNAL_ERROR;
#else
    #error "Don't know how to get hi-res current time on this platform"
#endif
#endif // HAVE_WORKING_CLOCK_GETTIME, HAVE_WORKING_GETTIMEOFDAY

Review comment (refactor):
@copilot `fPreferMonotonicClock` argument is always true. Delete it and simplify the code

Code after:

    /*++
    Method:
      CPalSynchronizationManager::InterlockedAwaken

    Tries to change the target wait status to 'active' in an interlocked fashion
    --*/
    bool CPalSynchronizationManager::InterlockedAwaken(
        DWORD *pWaitState)
    {
        return InterlockedCompareExchange((LONG *)pWaitState, TWS_ACTIVE, TWS_WAITING) == TWS_WAITING;
    }

    /*++
    Method:
      CPalSynchronizationManager::GetAbsoluteTimeout

    Converts a relative timeout to an absolute one.
    --*/
    PAL_ERROR CPalSynchronizationManager::GetAbsoluteTimeout(DWORD dwTimeout, struct timespec * ptsAbsTmo)
    {
        PAL_ERROR palErr = NO_ERROR;
        int iRet;

#if HAVE_PTHREAD_CONDATTR_SETCLOCK
        iRet = clock_gettime(CLOCK_MONOTONIC, ptsAbsTmo);
#elif HAVE_WORKING_CLOCK_GETTIME
        // Not every platform implements a (working) clock_gettime
        iRet = clock_gettime(CLOCK_REALTIME, ptsAbsTmo);
#elif HAVE_WORKING_GETTIMEOFDAY
        // Not every platform implements a (working) gettimeofday
        struct timeval tv;
        iRet = gettimeofday(&tv, NULL);
        if (0 == iRet)
        {
            ptsAbsTmo->tv_sec  = tv.tv_sec;
            ptsAbsTmo->tv_nsec = tv.tv_usec * tccMicroSecondsToNanoSeconds;
        }
#else
#ifdef DBI_COMPONENT_MONO
    return ERROR_INTERNAL_ERROR;
#else
    #error "Don't know how to get hi-res current time on this platform"
#endif
#endif // HAVE_WORKING_CLOCK_GETTIME, HAVE_WORKING_GETTIMEOFDAY
        if (0 == iRet)
        {
            ptsAbsTmo->tv_sec  += dwTimeout / tccSecondsToMilliSeconds;
            ptsAbsTmo->tv_nsec += (dwTimeout % tccSecondsToMilliSeconds) * tccMilliSecondsToNanoSeconds;
            while (ptsAbsTmo->tv_nsec >= tccSecondsToNanoSeconds)
            {