msvcrt: return wall-clock time from clock()

Alexandre Julliard julliard at winehq.org
Fri Nov 22 07:15:12 CST 2013


Daniel Lehman <dlehman at esri.com> writes:

> @@ -709,19 +711,26 @@ int CDECL _wstrtime_s(MSVCRT_wchar_t* time, MSVCRT_size_t size)
>   */
>  MSVCRT_clock_t CDECL MSVCRT_clock(void)
>  {
> -  FILETIME ftc, fte, ftk, ftu;
> -  ULONGLONG utime, ktime;
> - 
> -  MSVCRT_clock_t clock;
> +    static LONGLONG start_time;
> +    LONGLONG current_time;
> +    struct timeval now;
>  
> -  GetProcessTimes(GetCurrentProcess(), &ftc, &fte, &ftk, &ftu);
> +    if(!start_time) {
> +        KERNEL_USER_TIMES pti;
>  
> -  ktime = ((ULONGLONG)ftk.dwHighDateTime << 32) | ftk.dwLowDateTime;
> -  utime = ((ULONGLONG)ftu.dwHighDateTime << 32) | ftu.dwLowDateTime;
> +        /* while Linux's clock returns user time, Windows' clock
> +         * returns wall-clock time from process start.  cache the
> +         * process start time since it won't change and to avoid
> +         * wineserver round-trip overhead */
> +        if(NtQueryInformationProcess(GetCurrentProcess(), ProcessTimes, &pti, sizeof(pti), NULL))
> +            return -1;
> +        start_time = pti.CreateTime.QuadPart;
> +    }
>  
> -  clock = (utime + ktime) / (TICKSPERSEC / MSVCRT_CLOCKS_PER_SEC);
> +    gettimeofday(&now, NULL);
> +    current_time = (LONGLONG)now.tv_sec * TICKSPERSEC + now.tv_usec * 10 + TICKS_1601_TO_1970;

You should be using Windows APIs for this, not gettimeofday.

-- 
Alexandre Julliard
julliard at winehq.org



More information about the wine-devel mailing list