with System.Task_Primitives.Operations;
package body Ada.Real_Time is
function "*" (Left : Time_Span; Right : Integer) return Time_Span is
pragma Unsuppress (Overflow_Check);
begin
return Time_Span (Duration (Left) * Right);
end "*";
function "*" (Left : Integer; Right : Time_Span) return Time_Span is
pragma Unsuppress (Overflow_Check);
begin
return Time_Span (Left * Duration (Right));
end "*";
function "+" (Left : Time; Right : Time_Span) return Time is
pragma Unsuppress (Overflow_Check);
begin
return Time (Duration (Left) + Duration (Right));
end "+";
function "+" (Left : Time_Span; Right : Time) return Time is
pragma Unsuppress (Overflow_Check);
begin
return Time (Duration (Left) + Duration (Right));
end "+";
function "+" (Left, Right : Time_Span) return Time_Span is
pragma Unsuppress (Overflow_Check);
begin
return Time_Span (Duration (Left) + Duration (Right));
end "+";
function "-" (Left : Time; Right : Time_Span) return Time is
pragma Unsuppress (Overflow_Check);
begin
return Time (Duration (Left) - Duration (Right));
end "-";
function "-" (Left, Right : Time) return Time_Span is
pragma Unsuppress (Overflow_Check);
begin
return Time_Span (Duration (Left) - Duration (Right));
end "-";
function "-" (Left, Right : Time_Span) return Time_Span is
pragma Unsuppress (Overflow_Check);
begin
return Time_Span (Duration (Left) - Duration (Right));
end "-";
function "-" (Right : Time_Span) return Time_Span is
pragma Unsuppress (Overflow_Check);
begin
return Time_Span_Zero - Right;
end "-";
function "/" (Left, Right : Time_Span) return Integer is
pragma Unsuppress (Overflow_Check);
begin
return Integer (Duration (Left) / Duration (Right));
end "/";
function "/" (Left : Time_Span; Right : Integer) return Time_Span is
pragma Unsuppress (Overflow_Check);
begin
return Time_Span (Duration (Left) / Right);
end "/";
function Clock return Time is
begin
return Time (System.Task_Primitives.Operations.Monotonic_Clock);
end Clock;
function Microseconds (US : Integer) return Time_Span is
begin
return Time_Span_Unit * US * 1_000;
end Microseconds;
function Milliseconds (MS : Integer) return Time_Span is
begin
return Time_Span_Unit * MS * 1_000_000;
end Milliseconds;
function Nanoseconds (NS : Integer) return Time_Span is
begin
return Time_Span_Unit * NS;
end Nanoseconds;
procedure Split (T : Time; SC : out Seconds_Count; TS : out Time_Span) is
T_Val : Time;
begin
if T = Time_First then
T_Val := abs (Time_Last);
else
T_Val := abs (T);
end if;
if T_Val < 0.5 then
SC := 0;
else
SC := Seconds_Count (Time_Span'(T_Val - 0.5));
end if;
if T < 0.0 then
SC := -SC;
end if;
if Time (SC) > T then
SC := SC - 1;
end if;
TS := Time_Span (Duration (T) - Duration (SC));
end Split;
function Time_Of (SC : Seconds_Count; TS : Time_Span) return Time is
begin
return Time (SC) + TS;
end Time_Of;
function To_Duration (TS : Time_Span) return Duration is
begin
return Duration (TS);
end To_Duration;
function To_Time_Span (D : Duration) return Time_Span is
begin
return Time_Span (D);
end To_Time_Span;
end Ada.Real_Time;