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 = { ...@@ -22,8 +22,8 @@ type clock = {
mutable now: float; mutable now: float;
(* The number of ticks that have taken place. *) (* The number of ticks that have taken place. *)
mutable ticks: int; mutable ticks: int;
(* The elapsed time, in integer seconds. *) (* The last time [tick] was called for this clock. *)
mutable second: int; mutable last: float;
(* A circular array of the times at which the most recent round ticks (* A circular array of the times at which the most recent round ticks
took place. *) took place. *)
window: float array; window: float array;
...@@ -39,7 +39,7 @@ let make granularity = ...@@ -39,7 +39,7 @@ let make granularity =
start; start;
now = start; now = start;
ticks = 0; ticks = 0;
second = 0; last = 0.;
window = Array.make n start; window = Array.make n start;
next = 0; next = 0;
} in } in
...@@ -55,11 +55,10 @@ let tick clock f = ...@@ -55,11 +55,10 @@ let tick clock f =
clock.window.(clock.next) <- clock.now; clock.window.(clock.next) <- clock.now;
let n = Array.length clock.window in let n = Array.length clock.window in
clock.next <- (clock.next + 1) mod n; 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 (* Check if roughly one new second has elapsed. If so, call the user
function [f]. *) function [f]. *)
if second' > clock.second then begin if clock.now > clock.last +. 1. then begin
clock.second <- second'; clock.last <- clock.now;
f() f()
end end
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