Module: wine Branch: stable Commit: ed8357ee890e359fb3660cd1b39a31ec353a1af0 URL: http://source.winehq.org/git/wine.git/?a=commit;h=ed8357ee890e359fb3660cd1b3... Author: Daniel Lehman <dlehman(a)esri.com> Date: Wed Jul 27 16:42:53 2011 -0700 msvcrt: Return wall-clock time from clock(). (cherry picked from commit 15b35f4d37e4bdd8d2b44b772e800a8ffade7ab6) --- dlls/msvcrt/time.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c index 4c21380..11a5df9 100644 --- a/dlls/msvcrt/time.c +++ b/dlls/msvcrt/time.c @@ -30,6 +30,7 @@ #include "mtdll.h" #include "winbase.h" #include "winnls.h" +#include "winternl.h" #include "wine/debug.h" #include "wine/unicode.h" @@ -709,19 +710,23 @@ 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; + LARGE_INTEGER systime; - 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; - - clock = (utime + ktime) / (TICKSPERSEC / MSVCRT_CLOCKS_PER_SEC); + /* 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; + } - return clock; + NtQuerySystemTime(&systime); + return (systime.QuadPart - start_time) * MSVCRT_CLOCKS_PER_SEC / TICKSPERSEC; } /*********************************************************************