[prev in list] [next in list] [prev in thread] [next in thread]
List: wine-devel
Subject: Re: msvcrt: return wall-clock time from clock()
From: Alexandre Julliard <julliard () winehq ! org>
Date: 2013-11-22 13:15:12
Message-ID: 87k3g037dr.fsf () wine ! dyndns ! org
[Download RAW message or body]
Daniel Lehman <dlehman@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@winehq.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic