home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gnat-2.06-src.tgz / tar.out / fsf / gnat / ada / s-tasclo.adb < prev    next >
Text File  |  1996-09-28  |  5KB  |  175 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                 GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS               --
  4. --                                                                          --
  5. --                     S Y S T E M . T A S K _ C L O C K                    --
  6. --                                                                          --
  7. --                                  B o d y                                 --
  8. --                                                                          --
  9. --                             $Revision: 1.12 $                             --
  10. --                                                                          --
  11. --     Copyright (c) 1991,1992,1993,1994,1995 FSU, All Rights Reserved      --
  12. --                                                                          --
  13. -- GNARL is free software; you can redistribute it  and/or modify it  under --
  14. -- terms  of  the  GNU  Library General Public License  as published by the --
  15. -- Free Software  Foundation;  either version 2, or (at  your  option)  any --
  16. -- later  version.  GNARL is distributed  in the hope that  it will be use- --
  17. -- ful, but but WITHOUT ANY WARRANTY;  without even the implied warranty of --
  18. -- MERCHANTABILITY  or  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Gen- --
  19. -- eral Library Public License  for more details.  You should have received --
  20. -- a  copy of the GNU Library General Public License along with GNARL;  see --
  21. -- file COPYING.LIB.  If not,  write to the  Free Software Foundation,  675 --
  22. -- Mass Ave, Cambridge, MA 02139, USA.                                      --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with Interfaces; use Interfaces;
  27.  
  28. package body System.Task_Clock is
  29.  
  30.    -----------------------
  31.    -- Stimespec_Seconds --
  32.    -----------------------
  33.  
  34.    function Stimespec_Seconds (TV : Stimespec) return Integer is
  35.       Tmp : Stimespec := TV / Stimespec_Sec_Unit;
  36.    begin
  37.       return  Integer (Tmp);
  38.    end Stimespec_Seconds;
  39.  
  40.    ------------------------
  41.    -- Stimespec_Nseconds --
  42.    -------------------------
  43.  
  44.    function Stimespec_NSeconds (TV : Stimespec) return Integer is
  45.    begin
  46.       return
  47.         Integer (TV - Stimespec (Stimespec_Seconds (TV)) *
  48.           Stimespec_Sec_Unit);
  49.    end Stimespec_NSeconds;
  50.  
  51.    -------------
  52.    -- Time_Of --
  53.    -------------
  54.  
  55.    function Time_Of (S, NS : Integer) return Stimespec is
  56.    begin
  57.       return  Stimespec_Sec_Unit * Stimespec (S) + Stimespec (NS);
  58.    end Time_Of;
  59.  
  60.    ---------------------------
  61.    -- Stimespec_To_Duration --
  62.    ---------------------------
  63.  
  64.    function Stimespec_To_Duration (TV : Stimespec) return Duration is
  65.    begin
  66.       return
  67.         Duration (long_long_float (TV) / long_long_float (Stimespec_Sec_Unit));
  68.    end Stimespec_To_Duration;
  69.  
  70.    ---------------------------
  71.    -- Duration_To_Stimespec --
  72.    ---------------------------
  73.  
  74.    function Duration_To_Stimespec (Time : Duration) return Stimespec is
  75.    begin
  76.       return Stimespec
  77.         (long_long_float (Time) * long_long_float (Stimespec_Sec_Unit));
  78.    end Duration_To_Stimespec;
  79.  
  80.    ---------
  81.    -- "-" --
  82.    ---------
  83.  
  84.    --  Unary minus
  85.    function "-" (TV : Stimespec) return Stimespec is
  86.    begin
  87.       return Stimespec (-(Integer_64 (TV)));
  88.    end "-";
  89.  
  90.    ---------
  91.    -- "+" --
  92.    ---------
  93.  
  94.    function "+" (LTV, RTV : Stimespec) return Stimespec is
  95.    begin
  96.       return Stimespec (Integer_64 (LTV) + Integer_64 (RTV));
  97.    end "+";
  98.  
  99.    ---------
  100.    -- "-" --
  101.    ---------
  102.  
  103.    function "-" (LTV, RTV : Stimespec) return Stimespec is
  104.    begin
  105.       return Stimespec (Integer_64 (LTV) - Integer_64 (RTV));
  106.    end "-";
  107.  
  108.    ---------
  109.    -- "*" --
  110.    ---------
  111.  
  112.    function "*" (TV : Stimespec; N : Integer) return Stimespec is
  113.    begin
  114.       return TV * Stimespec (N);
  115.    end "*";
  116.  
  117.    ---------
  118.    -- "/" --
  119.    ---------
  120.  
  121.    --  Integer division of Stimespec
  122.  
  123.    function "/" (TV : Stimespec; N : Integer) return Stimespec is
  124.    begin
  125.       return TV / Stimespec (N);
  126.    end "/";
  127.  
  128.    ---------
  129.    -- "/" --
  130.    ---------
  131.  
  132.    function "/" (LTV, RTV : Stimespec) return Integer is
  133.       Tmp : Stimespec := LTV / RTV;
  134.    begin
  135.       return Integer (Tmp);
  136.    end "/";
  137.  
  138.    ---------
  139.    -- "<" --
  140.    ---------
  141.  
  142.    function "<" (LTV, RTV : Stimespec) return Boolean is
  143.    begin
  144.       return Integer_64 (LTV) < Integer_64 (RTV);
  145.    end "<";
  146.  
  147.    ----------
  148.    -- "<=" --
  149.    ----------
  150.  
  151.    function "<=" (LTV, RTV : Stimespec) return Boolean is
  152.    begin
  153.       return LTV < RTV or else RTV = LTV;
  154.    end "<=";
  155.  
  156.    ---------
  157.    -- ">" --
  158.    ---------
  159.  
  160.    function ">" (LTV, RTV : Stimespec) return Boolean is
  161.    begin
  162.       return Integer_64 (RTV) < Integer_64 (LTV);
  163.    end ">";
  164.  
  165.    ----------
  166.    -- ">=" --
  167.    ----------
  168.  
  169.    function ">=" (LTV, RTV : Stimespec) return Boolean is
  170.    begin
  171.       return LTV > RTV or LTV = RTV;
  172.    end ">=";
  173.  
  174. end System.Task_Clock;
  175.