From 70e049261c2b49411fbc9cefc737bc18ee6c4365 Mon Sep 17 00:00:00 2001 From: beware Date: Mon, 3 Nov 2014 00:38:20 +0000 Subject: [PATCH] automatically use GetSystemTimePreciseAsFileTime if available (windows 8) git-svn-id: file:///svnroot/lcore/trunk@140 b1de8a11-f9be-4011-bde0-cc7ace90066a --- btime.pas | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/btime.pas b/btime.pas index 14b734e..54deae5 100644 --- a/btime.pas +++ b/btime.pas @@ -553,12 +553,51 @@ begin result := mmqpctimefloat; end; + + +var + GetSystemTimePreciseAsFileTime:procedure(var v:tfiletime); stdcall; + win8inited:boolean; + +procedure initwin8; +var + dllhandle:thandle; + +begin + win8inited := true; + dllhandle := loadlibrary('kernel32.dll'); + if (dllhandle <> 0) then begin + GetSystemTimePreciseAsFileTime := getprocaddress(dllhandle,'GetSystemTimePreciseAsFileTime'); + end; +end; + + +function unixtimefloat_win8:float; +var + ft:tfiletime; + i:int64 absolute ft; +begin + GetSystemTimePreciseAsFileTime(ft); + {change from windows 1601-01-01 to unix 1970-01-01. + use integer math for this, to preserve precision} + dec(i, 116444736000000000); + result := (i / 10000000); +end; + + + function unixtimefloat:float; const margin = 0.0012; var f,g,h:float; begin + if not win8inited then initwin8; + if assigned(@GetSystemTimePreciseAsFileTime) then begin + result := unixtimefloat_win8; + exit; + end; + result := monotimefloat+timefloatbias; f := result-unixtimefloat_systemtime; if ((f > ticks_freq2+margin) or (f < -margin)) or (timefloatbias = 0) then begin -- 2.30.2