Module Core_kernel__.Timing_wheel_ns
module Time : Core_kernel.Timing_wheel_ns_intf.Timing_wheel_time with type t = Core_kernel.Time_ns.t and type Span.t = Core_kernel.Time_ns.Span.t
module Alarm_precision : Core_kernel.Timing_wheel_ns_intf.Alarm_precision with module Time := Time
val sexp_of_t : ('a -> Ppx_sexp_conv_lib.Sexp.t) -> 'a t -> Ppx_sexp_conv_lib.Sexp.t
type 'a timing_wheel
= 'a t
type 'a t_now
= 'a t
<:sexp_of< _ t_now >>
displays onlynow t
, not all the alarms.
val sexp_of_t_now : ('a -> Ppx_sexp_conv_lib.Sexp.t) -> 'a t_now -> Ppx_sexp_conv_lib.Sexp.t
module Alarm : sig ... end
include Core_kernel__.Import.Invariant.S1 with type 'a t := 'a t
val invariant : 'a Base__.Invariant_intf.inv -> 'a t Base__.Invariant_intf.inv
module Level_bits : sig ... end
module Config : sig ... end
val create : config:Config.t -> start:Time.t -> 'a t
create ~config ~start
creates a new timing wheel with current timestart
.create
raises ifstart < Time.epoch
. For a fixedlevel_bits
, a smaller (i.e. more precise)alarm_precision
decreases the representable range of times/keys and increases the constant factor foradvance_clock
.
val alarm_precision : _ t -> Time.Span.t
Accessors
val is_empty : _ t -> Core_kernel__.Import.bool
val length : _ t -> Core_kernel__.Import.int
val iter : 'a t -> f:('a Alarm.t -> Core_kernel__.Import.unit) -> Core_kernel__.Import.unit
val interval_num : _ t -> Time.t -> Interval_num.t
interval_num t time
returns the number of the interval thattime
is in, where0
is the interval that starts atTime.epoch
.interval_num
raises ifTime.( < ) time Time.epoch
.now_interval_num t
equalsinterval_num t (now t)
.
val now_interval_num : _ t -> Interval_num.t
val interval_num_start : _ t -> Interval_num.t -> Time.t
interval_num_start t n
is the start of then
'th interval int
, i.e.n * alarm_precision t
after the epoch.interval_start t time
is the start of the half-open interval containingtime
, i.e.:interval_num_start t (interval_num t time)
interval_start
raises in the same cases thatinterval_num
does.
val interval_start : _ t -> Time.t -> Time.t
val advance_clock : 'a t -> to_:Time.t -> handle_fired:('a Alarm.t -> Core_kernel__.Import.unit) -> Core_kernel__.Import.unit
advance_clock t ~to_ ~handle_fired
advancest
's clock toto_
. It fires and removes all alarmsa
int
withTime.(<) (Alarm.at t a) (interval_start t to_)
, applyinghandle_fired
to each sucha
.If
to_ <= now t
, thenadvance_clock
does nothing.advance_clock
fails ifto_
is too far in the future to represent.Behavior is unspecified if
handle_fired
accessest
in any way other thanAlarm
functions.
val fire_past_alarms : 'a t -> handle_fired:('a Alarm.t -> Core_kernel__.Import.unit) -> Core_kernel__.Import.unit
fire_past_alarms t ~handle_fired
fires and removes all alarmsa
int
withTime.( <= ) (Alarm.at t a) (now t)
, applyinghandle_fired
to each sucha
.fire_past_alarms
visits all alarms in intervalnow_interval_num
, to check theirAlarm.at
.Behavior is unspecified if
handle_fired
accessest
in any way other thanAlarm
functions.
val alarm_upper_bound : _ t -> Time.t
alarm_upper_bound t
returns the upper bound on anat
that can be supplied toadd
.alarm_upper_bound t
is not constant; its value increases asnow t
increases.
val max_allowed_alarm_time : _ t -> Time.t
max_allowed_alarm_time t
returns the greatestat
that can be supplied toadd
.max_allowed_alarm_time
is not constant; its value increases asnow t
increases.
val min_allowed_alarm_interval_num : _ t -> Interval_num.t
min_allowed_alarm_interval_num t = now_interval_num t
val max_allowed_alarm_interval_num : _ t -> Interval_num.t
max_allowed_alarm_interval_num t = interval_num t (max_allowed_alarm_time t)
val add : 'a t -> at:Time.t -> 'a -> 'a Alarm.t
add t ~at a
adds a new valuea
tot
and returns an alarm that can later be supplied toremove
the alarm fromt
.add
raises ifinterval_num t at < now_interval_num t || at > max_allowed_alarm_time t
.add_at_interval_num t ~at a
is equivalent toadd t ~at:(interval_num_start t at) a
.
val add_at_interval_num : 'a t -> at:Interval_num.t -> 'a -> 'a Alarm.t
val mem : 'a t -> 'a Alarm.t -> Core_kernel__.Import.bool
val remove : 'a t -> 'a Alarm.t -> Core_kernel__.Import.unit
remove t alarm
removesalarm
fromt
.remove
raises ifnot (mem t alarm)
.
val reschedule : 'a t -> 'a Alarm.t -> at:Time.t -> Core_kernel__.Import.unit
reschedule t alarm ~at
mutatesalarm
so that it will fire atat
, i.e. so thatAlarm.at t alarm = at
.reschedule
raises ifnot (mem t alarm)
or ifat
is an invalid time fort
, in the same situations thatadd
raises.reschedule_at_interval_num t alarm ~at
is equivalent to:reschedule t alarm ~at:(interval_num_start t at)
val reschedule_at_interval_num : 'a t -> 'a Alarm.t -> at:Interval_num.t -> Core_kernel__.Import.unit
val clear : _ t -> Core_kernel__.Import.unit
clear t
removes all alarms fromt
.
val min_alarm_interval_num : _ t -> Interval_num.t Core_kernel__.Import.option
min_alarm_interval_num t
is the minimumAlarm.interval_num
of all alarms int
.min_alarm_interval_num_exn t
is the same, except it raises ifis_empty t
.
val min_alarm_interval_num_exn : _ t -> Interval_num.t
val max_alarm_time_in_min_interval : 'a t -> Time.t Core_kernel__.Import.option
max_alarm_time_in_min_interval t
returns the maximumAlarm.at
over all alarms int
whoseAlarm.interval_num
ismin_alarm_interval_num t
.max_alarm_time_in_min_interval_exn t
is the same asmax_alarm_time_in_min_interval
, except that it raises ifis_empty t
.This function is useful for advancing to the
min_alarm_interval_num
of a timing wheel and then callingfire_past_alarms
to fire the alarms in that interval. That is useful when simulating time, to ensure that alarms are processed in order.
val max_alarm_time_in_min_interval_exn : 'a t -> Time.t
val next_alarm_fires_at : _ t -> Time.t Core_kernel__.Import.option
next_alarm_fires_at t
returns the minimum time to which the clock can be advanced such that an alarm will fire, orNone
ift
has no alarms. Ifnext_alarm_fires_at t = Some next
, then for the minimum alarm timemin
that occurs int
, it is guaranteed that:next - alarm_precision t <= min < next
.next_alarm_fires_at_exn
is the same asnext_alarm_fires_at
, except that it raises ifis_empty t
.
module Private : sig ... end