Skip to content

Commit

Permalink
IH-628: remove deadlines from timers
Browse files Browse the repository at this point in the history
These could help with the porting of the redo_log code, but Edwin's has working
code that changes the API of the timed calls to use durations instead of
deadlines.

Signed-off-by: Pau Ruiz Safont <[email protected]>
  • Loading branch information
psafont committed Jun 26, 2024
1 parent 2c5b022 commit ad40fd9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
13 changes: 2 additions & 11 deletions ocaml/libs/clock/timer.ml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
type t = {start: Ptime.t; elapsed: Mtime_clock.counter; duration: Mtime.Span.t}
type t = {elapsed: Mtime_clock.counter; duration: Mtime.Span.t}

type countdown = Remaining of Mtime.Span.t | Expired of Mtime.Span.t

let span_is_shorter a ~than:b = Mtime.Span.compare a b < 0

let span_is_longer a ~than:b = Mtime.Span.compare a b > 0

let start ~duration =
{start= Ptime_clock.now (); elapsed= Mtime_clock.counter (); duration}
let start ~duration = {elapsed= Mtime_clock.counter (); duration}

let duration {duration; _} = duration

Expand All @@ -25,14 +24,6 @@ let has_expired t =
let elapsed = Mtime_clock.count t.elapsed in
not (span_is_shorter elapsed ~than:t.duration)

let deadline_of t =
Mtime.Span.to_uint64_ns t.duration
|> Int64.to_float
|> Ptime.Span.of_float_s
|> Option.get
|> Ptime.(Span.add Ptime.(to_span t.start))
|> Ptime.Span.to_float_s

let shorten_by dur t =
let duration =
if span_is_longer dur ~than:t.duration then
Expand Down
6 changes: 0 additions & 6 deletions ocaml/libs/clock/timer.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ val remaining : t -> countdown
(** [remaining timer] returns the amount of time left until [timer] expires or
the amount of time since it expired. *)

val deadline_of : t -> float
(** [deadline_of timer] returns the posix timestamp when the timer expires.
This is an approximation as the timer doesn't take leap seconds into
account when waiting. The use of this function is discouraged and it's
only provided for backwards-compatible reasons. *)

val shorten_by : Mtime.Span.t -> t -> t
(** [shorten_by amount timer] creates a new timer with the duration of [timer]
shortened by [amount]. The starting time doesn't change. The duration of a
Expand Down

0 comments on commit ad40fd9

Please sign in to comment.