home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adav313.zip / gnat-3_13p-os2-bin-20010916.zip / emx / gnatlib / s-taprob.adb < prev    next >
Text File  |  2000-07-19  |  5KB  |  128 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS               --
  4. --                                                                          --
  5. --      S Y S T E M . T A S K I N G . P R O T E C T E D _ O B J E C T S     --
  6. --                                                                          --
  7. --                                  B o d y                                 --
  8. --                                                                          --
  9. --                             $Revision: 1.78 $
  10. --                                                                          --
  11. --             Copyright (C) 1991-1999 Florida State University             --
  12. --                                                                          --
  13. -- GNARL is free software; you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNARL; see file COPYING.  If not, write --
  21. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  22. -- MA 02111-1307, USA.                                                      --
  23. --                                                                          --
  24. -- As a special exception,  if other files  instantiate  generics from this --
  25. -- unit, or you link  this unit with other files  to produce an executable, --
  26. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  27. -- covered  by the  GNU  General  Public  License.  This exception does not --
  28. -- however invalidate  any other reasons why  the executable file  might be --
  29. -- covered by the  GNU Public License.                                      --
  30. --                                                                          --
  31. -- GNARL was developed by the GNARL team at Florida State University. It is --
  32. -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
  33. -- State University (http://www.gnat.com).                                  --
  34. --                                                                          --
  35. ------------------------------------------------------------------------------
  36.  
  37. pragma Polling (Off);
  38. --  Turn off polling, we do not want ATC polling to take place during
  39. --  tasking operations. It causes infinite loops and other problems.
  40.  
  41. with System.Task_Primitives.Operations;
  42. --  used for Write_Lock
  43. --           Unlock
  44.  
  45. with Ada.Exceptions;
  46. --  used for Raise_Exception
  47.  
  48. package body System.Tasking.Protected_Objects is
  49.  
  50.    use Ada.Exceptions;
  51.    use System.Task_Primitives.Operations;
  52.  
  53.    ---------------------------
  54.    -- Initialize_Protection --
  55.    ---------------------------
  56.  
  57.    procedure Initialize_Protection
  58.      (Object           : Protection_Access;
  59.       Ceiling_Priority : Integer)
  60.    is
  61.       Init_Priority : Integer := Ceiling_Priority;
  62.    begin
  63.       if Init_Priority = Unspecified_Priority then
  64.          Init_Priority  := System.Priority'Last;
  65.       end if;
  66.  
  67.       Initialize_Lock (Init_Priority, Object.L'Access);
  68.       Object.Ceiling := System.Any_Priority (Init_Priority);
  69.    end Initialize_Protection;
  70.  
  71.    ----------
  72.    -- Lock --
  73.    ----------
  74.  
  75.    procedure Lock (Object : Protection_Access) is
  76.       Ceiling_Violation : Boolean;
  77.    begin
  78.       --  The lock is made without defering abortion.
  79.  
  80.       --  Therefore the abortion has to be deferred before calling this
  81.       --  routine. This means that the compiler has to generate a Defer_Abort
  82.       --  call before the call to Lock.
  83.  
  84.       --  The caller is responsible for undeferring abortion, and compiler
  85.       --  generated calls must be protected with cleanup handlers to ensure
  86.       --  that abortion is undeferred in all cases.
  87.  
  88.       Write_Lock (Object.L'Access, Ceiling_Violation);
  89.  
  90.       if Ceiling_Violation then
  91.          Raise_Exception (Program_Error'Identity, "Ceiling Violation");
  92.       end if;
  93.    end Lock;
  94.  
  95.    --------------------
  96.    -- Lock_Read_Only --
  97.    --------------------
  98.  
  99.    procedure Lock_Read_Only (Object : Protection_Access) is
  100.       Ceiling_Violation : Boolean;
  101.    begin
  102.       Read_Lock (Object.L'Access, Ceiling_Violation);
  103.  
  104.       if Ceiling_Violation then
  105.          Raise_Exception (Program_Error'Identity, "Ceiling Violation");
  106.       end if;
  107.    end Lock_Read_Only;
  108.  
  109.    ------------
  110.    -- Unlock --
  111.    ------------
  112.  
  113.    procedure Unlock (Object : Protection_Access) is
  114.    begin
  115.       Unlock (Object.L'Access);
  116.    end Unlock;
  117.  
  118.    -------------------------
  119.    -- Finalize_Protection --
  120.    -------------------------
  121.  
  122.    procedure Finalize_Protection (Object : in out Protection) is
  123.    begin
  124.       Finalize_Lock (Object.L'Unrestricted_Access);
  125.    end Finalize_Protection;
  126.  
  127. end System.Tasking.Protected_Objects;
  128.