On this page
Package Ada.Real_Time
Ada.Real_Time (RM D.8) for tasks: a monotonic clock in nanoseconds. Clock is read through the run-time; the prover treats each reading as an unknown value of Time. A Time and a Time_Span are counts of nanoseconds, about 292 years either way. Adding a span to a time stops at Time_First and Time_Last, so a task that adds its period forever, as the periodic-task idiom does, is proved: a time that far away is never reached (the clock starts from about when the machine started). The other operations on spans have preconditions that keep them in range.
Time
type Time is private;Time_Span
type Time_Span is private;Time_First
Time_First : constant Time;Time_Last
Time_Last : constant Time;Time_Span_First
Time_Span_First : constant Time_Span;Time_Span_Last
Time_Span_Last : constant Time_Span;Time_Span_Zero
Time_Span_Zero : constant Time_Span;Time_Span_Unit
Time_Span_Unit : constant Time_Span;Tick
Tick : constant Time_Span;the clock's step: a nanosecond, the unit of Time
Time_Unit
Time_Unit : constant := 0.000_000_001;Nanoseconds_Of
function Nanoseconds_Of (T : Time) return Long_Long_Integer
with Global => null;(Verada) a time and a span as their nanoseconds
Span_Nanoseconds
function Span_Nanoseconds (TS : Time_Span) return Long_Long_Integer
with Global => null;Clock
function Clock return Time
with Global => null,
Post => Nanoseconds_Of (Clock'Result) in 0 .. 4_000_000_000_000_000_000;(the monotonic clock counts from about when the machine started: far below Time's last value, about 292 years)
function "+" (Left : Time; Right : Time_Span) return Time
with Global => null,
Post => (if Span_Nanoseconds (Right) >= 0
then (if Nanoseconds_Of (Left) <= Long_Long_Integer'Last - Span_Nanoseconds (Right)
then Nanoseconds_Of ("+"'Result) = Nanoseconds_Of (Left) + Span_Nanoseconds (Right)
else Nanoseconds_Of ("+"'Result) = Long_Long_Integer'Last)
else (if Nanoseconds_Of (Left) >= Long_Long_Integer'First - Span_Nanoseconds (Right)
then Nanoseconds_Of ("+"'Result) = Nanoseconds_Of (Left) + Span_Nanoseconds (Right)
else Nanoseconds_Of ("+"'Result) = Long_Long_Integer'First));a time a span later: exact, or Time_Last (Time_First) when it would be beyond it
function "+" (Left : Time_Span; Right : Time) return Time
with Global => null,
Post => Nanoseconds_Of ("+"'Result) = Nanoseconds_Of (Right + Left);function "-" (Left : Time; Right : Time_Span) return Time
with Global => null,
Post => (if Span_Nanoseconds (Right) <= 0
then (if Nanoseconds_Of (Left) <= Long_Long_Integer'Last + Span_Nanoseconds (Right)
then Nanoseconds_Of ("-"'Result) = Nanoseconds_Of (Left) - Span_Nanoseconds (Right)
else Nanoseconds_Of ("-"'Result) = Long_Long_Integer'Last)
else (if Nanoseconds_Of (Left) >= Long_Long_Integer'First + Span_Nanoseconds (Right)
then Nanoseconds_Of ("-"'Result) = Nanoseconds_Of (Left) - Span_Nanoseconds (Right)
else Nanoseconds_Of ("-"'Result) = Long_Long_Integer'First));a time a span earlier, likewise
function "-" (Left : Time; Right : Time) return Time_Span
with Global => null,
Pre => (if Nanoseconds_Of (Right) >= 0
then Nanoseconds_Of (Left) >= Long_Long_Integer'First + Nanoseconds_Of (Right)
else Nanoseconds_Of (Left) <= Long_Long_Integer'Last + Nanoseconds_Of (Right)),
Post => Span_Nanoseconds ("-"'Result) = Nanoseconds_Of (Left) - Nanoseconds_Of (Right);function "<" (Left, Right : Time) return Boolean
with Global => null,
Post => "<"'Result = (Nanoseconds_Of (Left) < Nanoseconds_Of (Right));function "<=" (Left, Right : Time) return Boolean
with Global => null,
Post => "<="'Result = (Nanoseconds_Of (Left) <= Nanoseconds_Of (Right));function ">" (Left, Right : Time) return Boolean
with Global => null,
Post => ">"'Result = (Nanoseconds_Of (Left) > Nanoseconds_Of (Right));function ">=" (Left, Right : Time) return Boolean
with Global => null,
Post => ">="'Result = (Nanoseconds_Of (Left) >= Nanoseconds_Of (Right));function "+" (Left, Right : Time_Span) return Time_Span
with Global => null,
Pre => (if Span_Nanoseconds (Right) >= 0
then Span_Nanoseconds (Left) <= Long_Long_Integer'Last - Span_Nanoseconds (Right)
else Span_Nanoseconds (Left) >= Long_Long_Integer'First - Span_Nanoseconds (Right)),
Post => Span_Nanoseconds ("+"'Result) = Span_Nanoseconds (Left) + Span_Nanoseconds (Right);spans: sums, differences, multiples and quotients, kept in range by their preconditions
function "-" (Left, Right : Time_Span) return Time_Span
with Global => null,
Pre => (if Span_Nanoseconds (Right) >= 0
then Span_Nanoseconds (Left) >= Long_Long_Integer'First + Span_Nanoseconds (Right)
else Span_Nanoseconds (Left) <= Long_Long_Integer'Last + Span_Nanoseconds (Right)),
Post => Span_Nanoseconds ("-"'Result) = Span_Nanoseconds (Left) - Span_Nanoseconds (Right);function "-" (Right : Time_Span) return Time_Span
with Global => null,
Pre => Span_Nanoseconds (Right) /= Long_Long_Integer'First,
Post => Span_Nanoseconds ("-"'Result) = -Span_Nanoseconds (Right);function "abs" (Right : Time_Span) return Time_Span
with Global => null,
Pre => Span_Nanoseconds (Right) /= Long_Long_Integer'First,
Post => Span_Nanoseconds ("abs"'Result) = abs Span_Nanoseconds (Right);function "*" (Left : Time_Span; Right : Integer) return Time_Span
with Global => null,
Pre => Long_Long_Long_Integer (Span_Nanoseconds (Left)) * Long_Long_Long_Integer (Right)
in Long_Long_Long_Integer (Long_Long_Integer'First) .. Long_Long_Long_Integer (Long_Long_Integer'Last),
Post => Long_Long_Long_Integer (Span_Nanoseconds ("*"'Result))
= Long_Long_Long_Integer (Span_Nanoseconds (Left)) * Long_Long_Long_Integer (Right);function "*" (Left : Integer; Right : Time_Span) return Time_Span
with Global => null,
Pre => Long_Long_Long_Integer (Left) * Long_Long_Long_Integer (Span_Nanoseconds (Right))
in Long_Long_Long_Integer (Long_Long_Integer'First) .. Long_Long_Long_Integer (Long_Long_Integer'Last),
Post => Long_Long_Long_Integer (Span_Nanoseconds ("*"'Result))
= Long_Long_Long_Integer (Left) * Long_Long_Long_Integer (Span_Nanoseconds (Right));function "/" (Left, Right : Time_Span) return Integer
with Global => null,
Pre => Span_Nanoseconds (Right) /= 0
and then not (Span_Nanoseconds (Left) = Long_Long_Integer'First and then Span_Nanoseconds (Right) = -1),
Post => Long_Long_Integer ("/"'Result) = Span_Nanoseconds (Left) / Span_Nanoseconds (Right);(truncated toward zero, as Integer division is)
function "/" (Left : Time_Span; Right : Integer) return Time_Span
with Global => null,
Pre => Right /= 0 and then not (Span_Nanoseconds (Left) = Long_Long_Integer'First and then Right = -1),
Post => Span_Nanoseconds ("/"'Result) = Span_Nanoseconds (Left) / Long_Long_Integer (Right);function "<" (Left, Right : Time_Span) return Boolean
with Global => null,
Post => "<"'Result = (Span_Nanoseconds (Left) < Span_Nanoseconds (Right));function "<=" (Left, Right : Time_Span) return Boolean
with Global => null,
Post => "<="'Result = (Span_Nanoseconds (Left) <= Span_Nanoseconds (Right));function ">" (Left, Right : Time_Span) return Boolean
with Global => null,
Post => ">"'Result = (Span_Nanoseconds (Left) > Span_Nanoseconds (Right));function ">=" (Left, Right : Time_Span) return Boolean
with Global => null,
Post => ">="'Result = (Span_Nanoseconds (Left) >= Span_Nanoseconds (Right));To_Duration
function To_Duration (TS : Time_Span) return Duration
with Global => null,
Pre => Span_Nanoseconds (TS) / 1_000_000_000 in -4_294_967_295 .. 4_294_967_295;a span as a Duration (which holds about 136 years either way), to the nanosecond as near as Duration's small allows, and a Duration as a span
To_Time_Span
function To_Time_Span (D : Duration) return Time_Span
with Global => null,
Post => abs (Span_Nanoseconds (To_Time_Span'Result) - Long_Long_Integer (D) * 1_000_000_000) <= 500_000_000;Nanoseconds
function Nanoseconds (NS : Integer) return Time_Span
with Global => null,
Post => Span_Nanoseconds (Nanoseconds'Result) = Long_Long_Integer (NS);Microseconds
function Microseconds (US : Integer) return Time_Span
with Global => null,
Pre => US in -9_223_372_036_854_775 .. 9_223_372_036_854_775,
Post => Span_Nanoseconds (Microseconds'Result) = Long_Long_Integer (US) * 1_000;(a span is a Long_Long_Integer of nanoseconds: about 292 years either way)
Milliseconds
function Milliseconds (MS : Integer) return Time_Span
with Global => null,
Pre => MS in -9_223_372_036_854 .. 9_223_372_036_854,
Post => Span_Nanoseconds (Milliseconds'Result) = Long_Long_Integer (MS) * 1_000_000;Seconds
function Seconds (S : Integer) return Time_Span
with Global => null,
Pre => S in -9_223_372_036 .. 9_223_372_036,
Post => Span_Nanoseconds (Seconds'Result) = Long_Long_Integer (S) * 1_000_000_000;Minutes
function Minutes (M : Integer) return Time_Span
with Global => null,
Pre => M in -153_722_867 .. 153_722_867,
Post => Span_Nanoseconds (Minutes'Result) = Long_Long_Integer (M) * 60_000_000_000;Seconds_Count
type Seconds_Count is range -9_223_372_037 .. 9_223_372_037;whole seconds (RM D.8(29)): those of any Time
Split
procedure Split (T : Time; SC : out Seconds_Count; TS : out Time_Span)
with Global => null,
Post => Span_Nanoseconds (TS) in 0 .. 999_999_999
and then Long_Long_Long_Integer (SC) * 1_000_000_000 + Long_Long_Long_Integer (Span_Nanoseconds (TS))
= Long_Long_Long_Integer (Nanoseconds_Of (T));a time as whole seconds and the nanoseconds after them, 0 .. 999_999_999
Time_Of
function Time_Of (SC : Seconds_Count; TS : Time_Span) return Time
with Global => null,
Pre => Long_Long_Long_Integer (SC) * 1_000_000_000 + Long_Long_Long_Integer (Span_Nanoseconds (TS))
in Long_Long_Long_Integer (Long_Long_Integer'First) .. Long_Long_Long_Integer (Long_Long_Integer'Last),
Post => Long_Long_Long_Integer (Nanoseconds_Of (Time_Of'Result))
= Long_Long_Long_Integer (SC) * 1_000_000_000 + Long_Long_Long_Integer (Span_Nanoseconds (TS));the time Split gives these of