Protect (partially) against tick count wrapping around

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@7946 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Xavier Leroy 2007-03-01 13:51:24 +00:00
parent 25bb3c6f12
commit 6f2ec9b618
1 changed files with 5 additions and 4 deletions

View File

@ -24,12 +24,13 @@ static DWORD initial_tickcount;
CAMLprim value unix_gettimeofday(value unit) CAMLprim value unix_gettimeofday(value unit)
{ {
if (initial_time == 0) { DWORD tickcount = GetTickCount();
initial_tickcount = GetTickCount(); if (initial_time == 0 || tickcount < initial_tickcount) {
initial_tickcount = tickcount;
initial_time = time(NULL); initial_time = time(NULL);
return copy_double((double) initial_time); return copy_double((double) initial_time);
} else { } else {
return copy_double(initial_time + return copy_double((double) initial_time +
(GetTickCount() - initial_tickcount) * 1e-3); (double) (tickcount - initial_tickcount) * 1e-3);
} }
} }