gcc:
[official-gcc.git] / gcc / ada / s-tpobop.ads
blob25b641dbe2914b9296bdd7f67849f7467512bd26
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 -- O P E R A T I O N 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 ------------------------------------------------------------------------------
35 -- This package contains all the extended primitives related to protected
36 -- objects with entries.
38 -- The handling of protected objects with no entries is done in
39 -- System.Tasking.Protected_Objects, the simple routines for protected
40 -- objects with entries in System.Tasking.Protected_Objects.Entries. The
41 -- split between Entries and Operations is needed to break circular
42 -- dependencies inside the run time.
44 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
45 -- Any changes to this interface may require corresponding compiler changes.
47 with Ada.Exceptions;
48 -- Used for Exception_Id
50 with System.Tasking.Protected_Objects.Entries;
52 package System.Tasking.Protected_Objects.Operations is
53 pragma Elaborate_Body;
55 type Communication_Block is private;
56 -- Objects of this type are passed between GNARL calls to allow RTS
57 -- information to be preserved.
59 procedure Protected_Entry_Call
60 (Object : Entries.Protection_Entries_Access;
61 E : Protected_Entry_Index;
62 Uninterpreted_Data : System.Address;
63 Mode : Call_Modes;
64 Block : out Communication_Block);
65 -- Make a protected entry call to the specified object.
66 -- Pend a protected entry call on the protected object represented
67 -- by Object. A pended call is not queued; it may be executed immediately
68 -- or queued, depending on the state of the entry barrier.
70 -- E
71 -- The index representing the entry to be called.
73 -- Uninterpreted_Data
74 -- This will be returned by Next_Entry_Call when this call is serviced.
75 -- It can be used by the compiler to pass information between the
76 -- caller and the server, in particular entry parameters.
78 -- Mode
79 -- The kind of call to be pended
81 -- Block
82 -- Information passed between runtime calls by the compiler
84 procedure Timed_Protected_Entry_Call
85 (Object : Entries.Protection_Entries_Access;
86 E : Protected_Entry_Index;
87 Uninterpreted_Data : System.Address;
88 Timeout : Duration;
89 Mode : Delay_Modes;
90 Entry_Call_Successful : out Boolean);
91 -- Same as the Protected_Entry_Call but with time-out specified.
92 -- This routines is used when we do not use ATC mechanism to implement
93 -- timed entry calls.
95 procedure Service_Entries (Object : Entries.Protection_Entries_Access);
96 pragma Inline (Service_Entries);
98 procedure PO_Service_Entries
99 (Self_ID : Task_Id;
100 Object : Entries.Protection_Entries_Access;
101 Unlock_Object : Boolean := True);
102 -- Service all entry queues of the specified object, executing the
103 -- corresponding bodies of any queued entry calls that are waiting
104 -- on True barriers. This is used when the state of a protected
105 -- object may have changed, in particular after the execution of
106 -- the statement sequence of a protected procedure.
108 -- Note that servicing an entry may change the value of one or more
109 -- barriers, so this routine keeps checking barriers until all of
110 -- them are closed.
112 -- This must be called with abort deferred and with the corresponding
113 -- object locked.
115 -- If Unlock_Object is set True, then Object is unlocked on return,
116 -- otherwise Object remains locked and the caller is responsible for
117 -- the required unlock.
119 procedure Complete_Entry_Body (Object : Entries.Protection_Entries_Access);
120 -- Called from within an entry body procedure, indicates that the
121 -- corresponding entry call has been serviced.
123 procedure Exceptional_Complete_Entry_Body
124 (Object : Entries.Protection_Entries_Access;
125 Ex : Ada.Exceptions.Exception_Id);
126 -- Perform all of the functions of Complete_Entry_Body. In addition,
127 -- report in Ex the exception whose propagation terminated the entry
128 -- body to the runtime system.
130 procedure Cancel_Protected_Entry_Call (Block : in out Communication_Block);
131 -- Attempt to cancel the most recent protected entry call. If the call is
132 -- not queued abortably, wait until it is or until it has completed.
133 -- If the call is actually cancelled, the called object will be
134 -- locked on return from this call. Get_Cancelled (Block) can be
135 -- used to determine if the cancellation took place; there
136 -- may be entries needing service in this case.
138 -- Block passes information between this and other runtime calls.
140 function Enqueued (Block : Communication_Block) return Boolean;
141 -- Returns True if the Protected_Entry_Call which returned the
142 -- specified Block object was queued; False otherwise.
144 function Cancelled (Block : Communication_Block) return Boolean;
145 -- Returns True if the Protected_Entry_Call which returned the
146 -- specified Block object was cancelled, False otherwise.
148 procedure Requeue_Protected_Entry
149 (Object : Entries.Protection_Entries_Access;
150 New_Object : Entries.Protection_Entries_Access;
151 E : Protected_Entry_Index;
152 With_Abort : Boolean);
153 -- If Object = New_Object, queue the protected entry call on Object
154 -- currently being serviced on the queue corresponding to the entry
155 -- represented by E.
157 -- If Object /= New_Object, transfer the call to New_Object.E,
158 -- executing or queuing it as appropriate.
160 -- With_Abort---True if the call is to be queued abortably, false
161 -- otherwise.
163 procedure Requeue_Task_To_Protected_Entry
164 (New_Object : Entries.Protection_Entries_Access;
165 E : Protected_Entry_Index;
166 With_Abort : Boolean);
167 -- Transfer task entry call currently being serviced to entry E
168 -- on New_Object.
170 -- With_Abort---True if the call is to be queued abortably, false
171 -- otherwise.
173 function Protected_Count
174 (Object : Entries.Protection_Entries'Class;
175 E : Protected_Entry_Index)
176 return Natural;
177 -- Return the number of entry calls to E on Object
179 function Protected_Entry_Caller
180 (Object : Entries.Protection_Entries'Class) return Task_Id;
181 -- Return value of E'Caller, where E is the protected entry currently
182 -- being handled. This will only work if called from within an entry
183 -- body, as required by the LRM (C.7.1(14)).
185 -- For internal use only
187 procedure PO_Do_Or_Queue
188 (Self_ID : Task_Id;
189 Object : Entries.Protection_Entries_Access;
190 Entry_Call : Entry_Call_Link;
191 With_Abort : Boolean);
192 -- This procedure either executes or queues an entry call, depending
193 -- on the status of the corresponding barrier. It assumes that abort
194 -- is deferred and that the specified object is locked.
196 private
197 type Communication_Block is record
198 Self : Task_Id;
199 Enqueued : Boolean := True;
200 Cancelled : Boolean := False;
201 end record;
202 pragma Volatile (Communication_Block);
204 -- ?????
205 -- The Communication_Block seems to be a relic. At the moment, the
206 -- compiler seems to be generating unnecessary conditional code based on
207 -- this block. See the code generated for async. select with task entry
208 -- call for another way of solving this.
210 end System.Tasking.Protected_Objects.Operations;