Debian Codegraph @

gcc/ada/libgnarl/a-reatim.ads

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . R E A L _ T I M E --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2025, Free Software Foundation, Inc. --
10 -- --
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. --
14 -- --
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. --
21 -- --
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. --
25 -- --
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/>. --
30 -- --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 -- --
34 ------------------------------------------------------------------------------
35
36 -- Package ``Ada.Real_Time`` provides basic definitions and operations related
37 -- to the types defined ``Time`` and ``Time_Span`` as defined by ARM D.8. The
38 -- types ``Time`` and ``Time_Span`` are implemented by the ``Duration`` type.
39 --
40 -- This software layer provides the Ada abstraction for time handling and
41 -- delays, using the services provided by lower layers.
42
43 with System.Task_Primitives.Operations;
44 pragma Elaborate_All (System.Task_Primitives.Operations);
45
46 package Ada.Real_Time with
47 SPARK_Mode,
48 Abstract_State => (Clock_Time with Synchronous),
49 Initializes => Clock_Time,
50 Always_Terminates
51 is
52
53 pragma Compile_Time_Error
54 (Duration'Size /= 64,
55 "this version of Ada.Real_Time requires 64-bit Duration");
56
57 type Time is private;
58 Time_First : constant Time;
59 Time_Last : constant Time;
60 Time_Unit : constant := 10#1.0#E-9;
61
62 type Time_Span is private;
63 Time_Span_First : constant Time_Span;
64 Time_Span_Last : constant Time_Span;
65 Time_Span_Zero : constant Time_Span;
66 Time_Span_Unit : constant Time_Span;
67
68 Tick : constant Time_Span;
69 function Clock return Time with
70 Volatile_Function,
71 Global => Clock_Time;
72
73 function "+" (Left : Time; Right : Time_Span) return Time with
74 Global => null;
75 function "+" (Left : Time_Span; Right : Time) return Time with
76 Global => null;
77 function "-" (Left : Time; Right : Time_Span) return Time with
78 Global => null;
79 function "-" (Left : Time; Right : Time) return Time_Span with
80 Global => null;
81
82 function "<" (Left, Right : Time) return Boolean with
83 Global => null;
84 function "<=" (Left, Right : Time) return Boolean with
85 Global => null;
86 function ">" (Left, Right : Time) return Boolean with
87 Global => null;
88 function ">=" (Left, Right : Time) return Boolean with
89 Global => null;
90
91 function "+" (Left, Right : Time_Span) return Time_Span with
92 Global => null;
93 function "-" (Left, Right : Time_Span) return Time_Span with
94 Global => null;
95 function "-" (Right : Time_Span) return Time_Span with
96 Global => null;
97 function "*" (Left : Time_Span; Right : Integer) return Time_Span with
98 Global => null;
99 function "*" (Left : Integer; Right : Time_Span) return Time_Span with
100 Global => null;
101 function "/" (Left, Right : Time_Span) return Integer with
102 Global => null;
103 function "/" (Left : Time_Span; Right : Integer) return Time_Span with
104 Global => null;
105
106 function "abs" (Right : Time_Span) return Time_Span with
107 Global => null;
108
109 function "<" (Left, Right : Time_Span) return Boolean with
110 Global => null;
111 function "<=" (Left, Right : Time_Span) return Boolean with
112 Global => null;
113 function ">" (Left, Right : Time_Span) return Boolean with
114 Global => null;
115 function ">=" (Left, Right : Time_Span) return Boolean with
116 Global => null;
117
118 function To_Duration (TS : Time_Span) return Duration with
119 Global => null;
120 function To_Time_Span (D : Duration) return Time_Span with
121 Global => null;
122
123 function Nanoseconds (NS : Integer) return Time_Span with
124 Global => null;
125 function Microseconds (US : Integer) return Time_Span with
126 Global => null;
127 function Milliseconds (MS : Integer) return Time_Span with
128 Global => null;
129
130 function Seconds (S : Integer) return Time_Span with
131 Global => null;
132 pragma Ada_05 (Seconds);
133
134 function Minutes (M : Integer) return Time_Span with
135 Global => null;
136 pragma Ada_05 (Minutes);
137
138 type Seconds_Count is new Long_Long_Integer;
139 -- Seconds_Count needs 64 bits, since the type Time has the full range of
140 -- Duration. The delta of Duration is 10 ** (-9), so the maximum number of
141 -- seconds is 2**63/10**9 = 8*10**9 which does not quite fit in 32 bits.
142 -- However, rather than make this explicitly 64-bits we derive from
143 -- Long_Long_Integer. In normal usage this will have the same effect. But
144 -- in the case of CodePeer with a target configuration file with a maximum
145 -- integer size of 32, it allows analysis of this unit.
146
147 procedure Split (T : Time; SC : out Seconds_Count; TS : out Time_Span)
148 with
149 Global => null;
150 function Time_Of (SC : Seconds_Count; TS : Time_Span) return Time
151 with
152 Global => null;
153
154 private
155 pragma SPARK_Mode (Off);
156
157 -- Time and Time_Span are represented in 64-bit Duration value in
158 -- nanoseconds. For example, 1 second and 1 nanosecond is represented
159 -- as the stored integer 1_000_000_001. This is for the 64-bit Duration
160 -- case, not clear if this also is used for 32-bit Duration values.
161
162 type Time is new Duration;
163
164 Time_First : constant Time := Time'First;
165
166 Time_Last : constant Time := Time'Last;
167
168 type Time_Span is new Duration;
169
170 Time_Span_First : constant Time_Span := Time_Span'First;
171
172 Time_Span_Last : constant Time_Span := Time_Span'Last;
173
174 Time_Span_Zero : constant Time_Span := 0.0;
175
176 Time_Span_Unit : constant Time_Span := 10#1.0#E-9;
177
178 Tick : constant Time_Span :=
179 Time_Span (System.Task_Primitives.Operations.RT_Resolution);
180
181 pragma Import (Intrinsic, "<");
182 pragma Import (Intrinsic, "<=");
183 pragma Import (Intrinsic, ">");
184 pragma Import (Intrinsic, ">=");
185 pragma Import (Intrinsic, "abs");
186
187 pragma Inline (Microseconds);
188 pragma Inline (Milliseconds);
189 pragma Inline (Nanoseconds);
190 pragma Inline (Seconds);
191 pragma Inline (Minutes);
192
193 end Ada.Real_Time;