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