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-tpoben.ads < prev    next >
Text File  |  2000-07-19  |  9KB  |  178 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. --                               E N T R I E S                              --
  7. --                                                                          --
  8. --                                  S p e c                                 --
  9. --                                                                          --
  10. --                             $Revision: 1.8 $
  11. --                                                                          --
  12. --          Copyright (C) 1992-1999, Free Software Foundation, Inc.         --
  13. --                                                                          --
  14. -- GNARL is free software; you can  redistribute it  and/or modify it under --
  15. -- terms of the  GNU General Public License as published  by the Free Soft- --
  16. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  17. -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
  18. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  19. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  20. -- for  more details.  You should have  received  a copy of the GNU General --
  21. -- Public License  distributed with GNARL; see file COPYING.  If not, write --
  22. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  23. -- MA 02111-1307, USA.                                                      --
  24. --                                                                          --
  25. -- As a special exception,  if other files  instantiate  generics from this --
  26. -- unit, or you link  this unit with other files  to produce an executable, --
  27. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  28. -- covered  by the  GNU  General  Public  License.  This exception does not --
  29. -- however invalidate  any other reasons why  the executable file  might be --
  30. -- covered by the  GNU Public License.                                      --
  31. --                                                                          --
  32. -- GNARL was developed by the GNARL team at Florida State University. It is --
  33. -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
  34. -- State University (http://www.gnat.com).                                  --
  35. --                                                                          --
  36. ------------------------------------------------------------------------------
  37.  
  38. --  This package contains all the simple primitives related to
  39. --  Protected_Objects with entries (i.e init, lock, unlock).
  40. --  The handling of protected objects with no entries is done in
  41. --  System.Tasking.Protected_Objects, the complex routines for protected
  42. --  objects with entries in System.Tasking.Protected_Objects.Operations.
  43. --  The split between Entries and Operations is needed to break circular
  44. --  dependencies inside the run time.
  45.  
  46. --  Note: the compiler generates direct calls to this interface, via Rtsfind.
  47. --  Any changes to this interface may require corresponding compiler changes.
  48.  
  49. with Ada.Finalization;
  50. --  used for Limited_Controlled
  51.  
  52. with Unchecked_Conversion;
  53.  
  54. package System.Tasking.Protected_Objects.Entries is
  55.    pragma Elaborate_Body;
  56.  
  57.    subtype Positive_Protected_Entry_Index is
  58.      Protected_Entry_Index range  1 .. Protected_Entry_Index'Last;
  59.  
  60.    type Find_Body_Index_Access is access
  61.      function
  62.        (O : System.Address;
  63.         E : Protected_Entry_Index)
  64.         return Protected_Entry_Index;
  65.  
  66.    type Protected_Entry_Body_Array is
  67.      array (Positive_Protected_Entry_Index range <>) of Entry_Body;
  68.    --  This is an array of the executable code for all entry bodies of
  69.    --  a protected type.
  70.  
  71.    type Protected_Entry_Body_Access is access all Protected_Entry_Body_Array;
  72.  
  73.    type Protected_Entry_Queue_Array is
  74.      array (Protected_Entry_Index range <>) of Entry_Queue;
  75.  
  76.    --  This type contains the GNARL state of a protected object. The
  77.    --  application-defined portion of the state (i.e. private objects)
  78.    --  is maintained by the compiler-generated code.
  79.    --  note that there is a simplified version of this type declared in
  80.    --  System.Tasking.PO_Simple that handle the simple case (no entries).
  81.  
  82.    type Protection_Entries (Num_Entries : Protected_Entry_Index) is new
  83.      Ada.Finalization.Limited_Controlled
  84.    with record
  85.       L                 : aliased Task_Primitives.Lock;
  86.       Compiler_Info     : System.Address;
  87.       Call_In_Progress  : Entry_Call_Link;
  88.       Ceiling           : System.Any_Priority;
  89.       Old_Base_Priority : System.Any_Priority;
  90.       Pending_Action    : Boolean;
  91.       --  Flag indicating that priority has been dipped temporarily
  92.       --  in order to avoid violating the priority ceiling of the lock
  93.       --  associated with this protected object, in Lock_Server.
  94.       --  The flag tells Unlock_Server or Unlock_And_Update_Server to
  95.       --  restore the old priority to Old_Base_Priority. This is needed
  96.       --  because of situations (bad language design?) where one
  97.       --  needs to lock a PO but to do so would violate the priority
  98.       --  ceiling.  For example, this can happen when an entry call
  99.       --  has been requeued to a lower-priority object, and the caller
  100.       --  then tries to cancel the call while its own priority is higher
  101.       --  than the ceiling of the new PO.
  102.  
  103.       Entry_Bodies      : Protected_Entry_Body_Access;
  104.  
  105.       --  The following function maps the entry index in a call (which denotes
  106.       --  the queue to the proper entry) into the body of the entry.
  107.  
  108.       Find_Body_Index   : Find_Body_Index_Access;
  109.       Entry_Queues      : Protected_Entry_Queue_Array (1 .. Num_Entries);
  110.    end record;
  111.    pragma Volatile (Protection_Entries);
  112.  
  113.    --  No default initial values for this type, since call records
  114.    --  will need to be re-initialized before every use.
  115.  
  116.    type Protection_Entries_Access is access all Protection_Entries'Class;
  117.    --  See comments in s-tassta.adb about the implicit call to Current_Master
  118.    --  generated by this declaration.
  119.  
  120.    function To_Protection_Entries is new Unchecked_Conversion
  121.      (Protection_Access, Protection_Entries_Access);
  122.  
  123.    function To_Address is
  124.      new Unchecked_Conversion (Protection_Entries_Access, System.Address);
  125.    function To_Protection is
  126.      new Unchecked_Conversion (System.Address, Protection_Entries_Access);
  127.  
  128.    function Has_Interrupt_Or_Attach_Handler
  129.      (Object : Protection_Entries_Access) return Boolean;
  130.    --  Returns True if an Interrupt_Handler or Attach_Handler pragma applies
  131.    --  to the protected object. That is to say this primitive returns False for
  132.    --  Protection, but is overriden to return True when interrupt handlers are
  133.    --  declared so the check required by C.3.1(11) can be implemented in
  134.    --  System.Tasking.Protected_Objects.Initialize_Protection.
  135.  
  136.    procedure Initialize_Protection_Entries
  137.      (Object           : Protection_Entries_Access;
  138.       Ceiling_Priority : Integer;
  139.       Compiler_Info    : System.Address;
  140.       Entry_Bodies     : Protected_Entry_Body_Access;
  141.       Find_Body_Index  : Find_Body_Index_Access);
  142.    --  Initialize the Object parameter so that it can be used by the runtime
  143.    --  to keep track of the runtime state of a protected object.
  144.  
  145.    procedure Lock_Entries (Object : Protection_Entries_Access);
  146.    --  Lock a protected object for write access. Upon return, the caller
  147.    --  owns the lock to this object, and no other call to Lock or
  148.    --  Lock_Read_Only with the same argument will return until the
  149.    --  corresponding call to Unlock has been made by the caller.
  150.  
  151.    procedure Lock_Read_Only_Entries (Object : Protection_Entries_Access);
  152.    --  Lock a protected object for read access. Upon return, the caller
  153.    --  owns the lock for read access, and no other calls to Lock with the
  154.    --  same argument will return until the corresponding call to Unlock
  155.    --  has been made by the caller. Other calls to Lock_Read_Only may (but
  156.    --  need not) return before the call to Unlock, and the corresponding
  157.    --  callers will also own the lock for read access.
  158.    --
  159.    --  Note: we are not currently using this interface, it is provided
  160.    --  for possible future use. At the current time, everyone uses Lock
  161.    --  for both read and write locks.
  162.  
  163.    procedure Unlock_Entries (Object : Protection_Entries_Access);
  164.    --  Relinquish ownership of the lock for the object represented by
  165.    --  the Object parameter. If this ownership was for write access, or
  166.    --  if it was for read access where there are no other read access
  167.    --  locks outstanding, one (or more, in the case of Lock_Read_Only)
  168.    --  of the tasks waiting on this lock (if any) will be given the
  169.    --  lock and allowed to return from the Lock or Lock_Read_Only call.
  170.  
  171. private
  172.  
  173.    procedure Finalize (Object : in out Protection_Entries);
  174.    --  Clean up a Protection object; in particular, finalize the associated
  175.    --  Lock object.
  176.  
  177. end System.Tasking.Protected_Objects.Entries;
  178.