OSDN Git Service

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