OSDN Git Service

* approved by rth
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-reatim.ads
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 --                                                                          --
10 --          Copyright (C) 1992-2001 Free Software Foundation, Inc.          --
11 --                                                                          --
12 -- This specification is derived from the Ada Reference Manual for use with --
13 -- GNAT. The copyright notice above, and the license provisions that follow --
14 -- apply solely to the  contents of the part following the private keyword. --
15 --                                                                          --
16 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
17 -- terms of the  GNU General Public License as published  by the Free Soft- --
18 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
19 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
20 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
21 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
22 -- for  more details.  You should have  received  a copy of the GNU General --
23 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
24 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
25 -- MA 02111-1307, USA.                                                      --
26 --                                                                          --
27 -- As a special exception,  if other files  instantiate  generics from this --
28 -- unit, or you link  this unit with other files  to produce an executable, --
29 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
30 -- covered  by the  GNU  General  Public  License.  This exception does not --
31 -- however invalidate  any other reasons why  the executable file  might be --
32 -- covered by the  GNU Public License.                                      --
33 --                                                                          --
34 -- GNAT was originally developed  by the GNAT team at  New York University. --
35 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
36 --                                                                          --
37 ------------------------------------------------------------------------------
38
39 with System.Task_Primitives.Operations;
40 pragma Elaborate_All (System.Task_Primitives.Operations);
41
42 package Ada.Real_Time is
43
44    type Time is private;
45    Time_First : constant Time;
46    Time_Last  : constant Time;
47    Time_Unit  : constant := 10#1.0#E-9;
48
49    type Time_Span is private;
50    Time_Span_First : constant Time_Span;
51    Time_Span_Last  :  constant Time_Span;
52    Time_Span_Zero  :  constant Time_Span;
53    Time_Span_Unit  :  constant Time_Span;
54
55    Tick : constant Time_Span;
56    function Clock return Time;
57
58    function "+"  (Left : Time;      Right : Time_Span) return Time;
59    function "+"  (Left : Time_Span; Right : Time)      return Time;
60    function "-"  (Left : Time;      Right : Time_Span) return Time;
61    function "-"  (Left : Time;      Right : Time)      return Time_Span;
62
63    function "<"  (Left, Right : Time) return Boolean;
64    function "<=" (Left, Right : Time) return Boolean;
65    function ">"  (Left, Right : Time) return Boolean;
66    function ">=" (Left, Right : Time) return Boolean;
67
68    function "+"  (Left, Right : Time_Span)             return Time_Span;
69    function "-"  (Left, Right : Time_Span)             return Time_Span;
70    function "-"  (Right : Time_Span)                   return Time_Span;
71    function "*"  (Left : Time_Span; Right : Integer)   return Time_Span;
72    function "*"  (Left : Integer;   Right : Time_Span) return Time_Span;
73    function "/"  (Left, Right : Time_Span)             return Integer;
74    function "/"  (Left : Time_Span; Right : Integer)   return Time_Span;
75
76    function "abs" (Right : Time_Span) return Time_Span;
77
78    function "<"  (Left, Right : Time_Span) return Boolean;
79    function "<=" (Left, Right : Time_Span) return Boolean;
80    function ">"  (Left, Right : Time_Span) return Boolean;
81    function ">=" (Left, Right : Time_Span) return Boolean;
82
83    function To_Duration  (TS : Time_Span) return Duration;
84    function To_Time_Span (D : Duration)   return Time_Span;
85
86    function Nanoseconds  (NS : Integer) return Time_Span;
87    function Microseconds (US : Integer) return Time_Span;
88    function Milliseconds (MS : Integer) return Time_Span;
89
90    --  Seconds_Count needs 64 bits, since Time has the full range of
91    --  Duration. The delta of Duration is 10 ** (-9), so the maximum
92    --  number of seconds is 2**63/10**9 = 8*10**9 which does not quite
93    --  fit in 32 bits.
94
95    type Seconds_Count is range -2 ** 63 .. 2 ** 63 - 1;
96
97    procedure Split (T : Time; SC : out Seconds_Count; TS : out Time_Span);
98    function Time_Of (SC : Seconds_Count; TS : Time_Span) return Time;
99
100 private
101    type Time is new Duration;
102
103    Time_First : constant Time := Time'First;
104
105    Time_Last  : constant Time := Time'Last;
106
107    type Time_Span is new Duration;
108
109    Time_Span_First : constant Time_Span := Time_Span'First;
110
111    Time_Span_Last  : constant Time_Span := Time_Span'Last;
112
113    Time_Span_Zero  : constant Time_Span := 0.0;
114
115    Time_Span_Unit  : constant Time_Span := 10#1.0#E-9;
116
117    Tick : constant Time_Span :=
118             Time_Span (System.Task_Primitives.Operations.RT_Resolution);
119
120    --  Time and Time_Span are represented in 64-bit Duration value in
121    --  in nanoseconds. For example, 1 second and 1 nanosecond is
122    --  represented as the stored integer 1_000_000_001.
123
124    pragma Import (Intrinsic, "<");
125    pragma Import (Intrinsic, "<=");
126    pragma Import (Intrinsic, ">");
127    pragma Import (Intrinsic, ">=");
128    pragma Import (Intrinsic, "abs");
129
130 end Ada.Real_Time;