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 / a-caldel.adb < prev    next >
Text File  |  1996-09-28  |  5KB  |  130 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                 GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS               --
  4. --                                                                          --
  5. --                   A D A . C A L E N D A R . D E L A Y S                  --
  6. --                                                                          --
  7. --                                  B o d y                                 --
  8. --                                                                          --
  9. --                             $Revision: 1.17 $                            --
  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 System;
  27. --  Used for, Priority
  28.  
  29. with System.Task_Timer;
  30. --  Used for, Timer
  31.  
  32. with System.Task_Primitives;
  33. --  Used for, Cond_Timed_Wait
  34. --            Lock
  35. --            Condition_Variable
  36. --            Initialize_Lock
  37. --            Initialize_Cond
  38. --            Write_Lock
  39. --            Unlock
  40.  
  41. with System.Task_Clock;
  42. --  Used for, Stimespec
  43.  
  44. with System.Task_Clock.Machine_Specifics;
  45. --  Used for, Stimespec_Ticks;
  46.  
  47. with Ada.Calendar.Conv;
  48. --  Used for, Time_To_Stimespec
  49.  
  50. package body Ada.Calendar.Delays is
  51.  
  52.    function "+" (L, R : System.Task_Clock.Stimespec) return
  53.      System.Task_Clock.Stimespec renames System.Task_Clock."+";
  54.  
  55.    ------------------
  56.    -- Delay_Object --
  57.    ------------------
  58.  
  59.    protected body Delay_Object is
  60.       entry Wait (T : Duration; D : access System.Task_Timer.Delay_Block)
  61.         when True is
  62.  
  63.       begin
  64.          requeue System.Task_Timer.Timer.Enqueue_Duration with abort;
  65.       end Wait;
  66.    end Delay_Object;
  67.  
  68.    ------------------------
  69.    -- Delay_Until_Object --
  70.    ------------------------
  71.  
  72.    protected body Delay_Until_Object is
  73.       entry Wait (T : Time; D : access System.Task_Timer.Delay_Block)
  74.         when True is
  75.  
  76.       begin
  77.          requeue System.Task_Timer.Timer.Enqueue_Calendar_Time with abort;
  78.       end Wait;
  79.    end Delay_Until_Object;
  80.  
  81.    ---------------
  82.    -- Delay_For --
  83.    ---------------
  84.  
  85.    procedure Delay_For (D : Duration) is
  86.       L : System.Task_Primitives.Lock;
  87.       C : System.Task_Primitives.Condition_Variable;
  88.       Error, Result : Boolean;
  89.    begin
  90.       Task_Primitives.Initialize_Lock (System.Priority'Last, L);
  91.       Task_Primitives.Initialize_Cond (C);
  92.  
  93.       Task_Primitives.Write_Lock (L, Error);
  94.       Task_Primitives.Cond_Timed_Wait
  95.         (C,
  96.          L,
  97.          Calendar.Conv.Time_To_Stimespec (Clock + D) +
  98.            System.Task_Clock.Machine_Specifics.Stimespec_Ticks,
  99.          Result);
  100.       Task_Primitives.Unlock (L);
  101.       Task_Primitives.Finalize_Cond (C);
  102.       Task_Primitives.Finalize_Lock (L);
  103.    end Delay_For;
  104.  
  105.    -----------------
  106.    -- Delay_Until --
  107.    -----------------
  108.  
  109.    procedure Delay_Until (T : Time) is
  110.       L : System.Task_Primitives.Lock;
  111.       C : System.Task_Primitives.Condition_Variable;
  112.       Error, Result : Boolean;
  113.    begin
  114.       Task_Primitives.Initialize_Lock (System.Priority'Last, L);
  115.       Task_Primitives.Initialize_Cond (C);
  116.  
  117.       Task_Primitives.Write_Lock (L, Error);
  118.       Task_Primitives.Cond_Timed_Wait
  119.         (C,
  120.          L,
  121.          Calendar.Conv.Time_To_Stimespec (T) +
  122.            System.Task_Clock.Machine_Specifics.Stimespec_Ticks,
  123.          Result);
  124.       Task_Primitives.Unlock (L);
  125.       Task_Primitives.Finalize_Cond (C);
  126.       Task_Primitives.Finalize_Lock (L);
  127.    end Delay_Until;
  128.  
  129. end Ada.Calendar.Delays;
  130.