Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 9705e16c authored by POTTIER Francois's avatar POTTIER Francois
Browse files

Clock: internal change: replace [second] field with [last] field.

parent 97d9e98d
No related branches found
No related tags found
No related merge requests found
......@@ -22,8 +22,8 @@ type clock = {
mutable now: float;
(* The number of ticks that have taken place. *)
mutable ticks: int;
(* The elapsed time, in integer seconds. *)
mutable second: int;
(* The last time [tick] was called for this clock. *)
mutable last: float;
(* A circular array of the times at which the most recent round ticks
took place. *)
window: float array;
......@@ -39,7 +39,7 @@ let make granularity =
start;
now = start;
ticks = 0;
second = 0;
last = 0.;
window = Array.make n start;
next = 0;
} in
......@@ -55,11 +55,10 @@ let tick clock f =
clock.window.(clock.next) <- clock.now;
let n = Array.length clock.window in
clock.next <- (clock.next + 1) mod n;
let second' = truncate (clock.now -. clock.start) in
(* Check if roughly one new second has elapsed. If so, call the user
function [f]. *)
if second' > clock.second then begin
clock.second <- second';
if clock.now > clock.last +. 1. then begin
clock.last <- clock.now;
f()
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment