1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . R E A L _ T I M E --
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the contents of the part following the private keyword. --
15 -- GNAT is free software; you can redistribute it and/or modify it under --
16 -- terms of the GNU General Public License as published by the Free Soft- --
17 -- ware Foundation; either version 3, or (at your option) any later ver- --
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE. --
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
23 -- additional permissions described in the GCC Runtime Library Exception, --
24 -- version 3.1, as published by the Free Software Foundation. --
26 -- You should have received a copy of the GNU General Public License and --
27 -- a copy of the GCC Runtime Library Exception along with this program; --
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
29 -- <http://www.gnu.org/licenses/>. --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
34 ------------------------------------------------------------------------------
36 with System
.Task_Primitives
.Operations
;
37 pragma Elaborate_All
(System
.Task_Primitives
.Operations
);
39 package Ada
.Real_Time
with
41 Abstract_State
=> (Clock_Time
with Synchronous
),
42 Initializes
=> Clock_Time
45 pragma Compile_Time_Error
47 "this version of Ada.Real_Time requires 64-bit Duration");
50 Time_First
: constant Time
;
51 Time_Last
: constant Time
;
52 Time_Unit
: constant := 10#
1.0#E
-9;
54 type Time_Span
is private;
55 Time_Span_First
: constant Time_Span
;
56 Time_Span_Last
: constant Time_Span
;
57 Time_Span_Zero
: constant Time_Span
;
58 Time_Span_Unit
: constant Time_Span
;
60 Tick
: constant Time_Span
;
61 function Clock
return Time
with
65 function "+" (Left
: Time
; Right
: Time_Span
) return Time
with
67 function "+" (Left
: Time_Span
; Right
: Time
) return Time
with
69 function "-" (Left
: Time
; Right
: Time_Span
) return Time
with
71 function "-" (Left
: Time
; Right
: Time
) return Time_Span
with
74 function "<" (Left
, Right
: Time
) return Boolean with
76 function "<=" (Left
, Right
: Time
) return Boolean with
78 function ">" (Left
, Right
: Time
) return Boolean with
80 function ">=" (Left
, Right
: Time
) return Boolean with
83 function "+" (Left
, Right
: Time_Span
) return Time_Span
with
85 function "-" (Left
, Right
: Time_Span
) return Time_Span
with
87 function "-" (Right
: Time_Span
) return Time_Span
with
89 function "*" (Left
: Time_Span
; Right
: Integer) return Time_Span
with
91 function "*" (Left
: Integer; Right
: Time_Span
) return Time_Span
with
93 function "/" (Left
, Right
: Time_Span
) return Integer with
95 function "/" (Left
: Time_Span
; Right
: Integer) return Time_Span
with
98 function "abs" (Right
: Time_Span
) return Time_Span
with
101 function "<" (Left
, Right
: Time_Span
) return Boolean with
103 function "<=" (Left
, Right
: Time_Span
) return Boolean with
105 function ">" (Left
, Right
: Time_Span
) return Boolean with
107 function ">=" (Left
, Right
: Time_Span
) return Boolean with
110 function To_Duration
(TS
: Time_Span
) return Duration with
112 function To_Time_Span
(D
: Duration) return Time_Span
with
115 function Nanoseconds
(NS
: Integer) return Time_Span
with
117 function Microseconds
(US
: Integer) return Time_Span
with
119 function Milliseconds
(MS
: Integer) return Time_Span
with
122 function Seconds
(S
: Integer) return Time_Span
with
124 pragma Ada_05
(Seconds
);
126 function Minutes
(M
: Integer) return Time_Span
with
128 pragma Ada_05
(Minutes
);
130 type Seconds_Count
is new Long_Long_Integer;
131 -- Seconds_Count needs 64 bits, since the type Time has the full range of
132 -- Duration. The delta of Duration is 10 ** (-9), so the maximum number of
133 -- seconds is 2**63/10**9 = 8*10**9 which does not quite fit in 32 bits.
134 -- However, rather than make this explicitly 64-bits we derive from
135 -- Long_Long_Integer. In normal usage this will have the same effect. But
136 -- in the case of CodePeer with a target configuration file with a maximum
137 -- integer size of 32, it allows analysis of this unit.
139 procedure Split
(T
: Time
; SC
: out Seconds_Count
; TS
: out Time_Span
)
142 function Time_Of
(SC
: Seconds_Count
; TS
: Time_Span
) return Time
147 pragma SPARK_Mode
(Off
);
149 -- Time and Time_Span are represented in 64-bit Duration value in
150 -- nanoseconds. For example, 1 second and 1 nanosecond is represented
151 -- as the stored integer 1_000_000_001. This is for the 64-bit Duration
152 -- case, not clear if this also is used for 32-bit Duration values.
154 type Time
is new Duration;
156 Time_First
: constant Time
:= Time
'First;
158 Time_Last
: constant Time
:= Time
'Last;
160 type Time_Span
is new Duration;
162 Time_Span_First
: constant Time_Span
:= Time_Span
'First;
164 Time_Span_Last
: constant Time_Span
:= Time_Span
'Last;
166 Time_Span_Zero
: constant Time_Span
:= 0.0;
168 Time_Span_Unit
: constant Time_Span
:= 10#
1.0#E
-9;
170 Tick
: constant Time_Span
:=
171 Time_Span
(System
.Task_Primitives
.Operations
.RT_Resolution
);
173 pragma Import
(Intrinsic
, "<");
174 pragma Import
(Intrinsic
, "<=");
175 pragma Import
(Intrinsic
, ">");
176 pragma Import
(Intrinsic
, ">=");
177 pragma Import
(Intrinsic
, "abs");
179 pragma Inline
(Microseconds
);
180 pragma Inline
(Milliseconds
);
181 pragma Inline
(Nanoseconds
);
182 pragma Inline
(Seconds
);
183 pragma Inline
(Minutes
);