OSDN Git Service

2008-04-08 Ed Schonberg <schonberg@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-tpobop.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                 GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS                 --
4 --                                                                          --
5 --               SYSTEM.TASKING.PROTECTED_OBJECTS.OPERATIONS                --
6 --                                                                          --
7 --                                  S p e c                                 --
8 --                                                                          --
9 --          Copyright (C) 1992-2008, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNARL is free software; you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNARL; see file COPYING.  If not, write --
19 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNARL was developed by the GNARL team at Florida State University.       --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --  This package contains all the extended primitives related to protected
35 --  objects with entries.
36
37 --  The handling of protected objects with no entries is done in
38 --  System.Tasking.Protected_Objects, the simple routines for protected
39 --  objects with entries in System.Tasking.Protected_Objects.Entries. The
40 --  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.Exceptions;
47
48 with System.Tasking.Protected_Objects.Entries;
49
50 package System.Tasking.Protected_Objects.Operations is
51    pragma Elaborate_Body;
52
53    type Communication_Block is private;
54    --  Objects of this type are passed between GNARL calls to allow RTS
55    --  information to be preserved.
56
57    procedure Protected_Entry_Call
58      (Object             : Entries.Protection_Entries_Access;
59       E                  : Protected_Entry_Index;
60       Uninterpreted_Data : System.Address;
61       Mode               : Call_Modes;
62       Block              : out Communication_Block);
63    --  Make a protected entry call to the specified object.
64    --  Pend a protected entry call on the protected object represented
65    --  by Object. A pended call is not queued; it may be executed immediately
66    --  or queued, depending on the state of the entry barrier.
67    --
68    --    E
69    --      The index representing the entry to be called.
70    --
71    --    Uninterpreted_Data
72    --      This will be returned by Next_Entry_Call when this call is serviced.
73    --      It can be used by the compiler to pass information between the
74    --      caller and the server, in particular entry parameters.
75    --
76    --    Mode
77    --      The kind of call to be pended
78    --
79    --    Block
80    --      Information passed between runtime calls by the compiler
81
82    procedure Timed_Protected_Entry_Call
83      (Object                : Entries.Protection_Entries_Access;
84       E                     : Protected_Entry_Index;
85       Uninterpreted_Data    : System.Address;
86       Timeout               : Duration;
87       Mode                  : Delay_Modes;
88       Entry_Call_Successful : out Boolean);
89    --  Same as the Protected_Entry_Call but with time-out specified.
90    --  This routines is used when we do not use ATC mechanism to implement
91    --  timed entry calls.
92
93    procedure Service_Entries (Object : Entries.Protection_Entries_Access);
94    pragma Inline (Service_Entries);
95
96    procedure PO_Service_Entries
97      (Self_ID       : Task_Id;
98       Object        : Entries.Protection_Entries_Access;
99       Unlock_Object : Boolean := True);
100    --  Service all entry queues of the specified object, executing the
101    --  corresponding bodies of any queued entry calls that are waiting
102    --  on True barriers. This is used when the state of a protected
103    --  object may have changed, in particular after the execution of
104    --  the statement sequence of a protected procedure.
105    --
106    --  Note that servicing an entry may change the value of one or more
107    --  barriers, so this routine keeps checking barriers until all of
108    --  them are closed.
109    --
110    --  This must be called with abort deferred and with the corresponding
111    --  object locked.
112    --
113    --  If Unlock_Object is set True, then Object is unlocked on return,
114    --  otherwise Object remains locked and the caller is responsible for
115    --  the required unlock.
116
117    procedure Complete_Entry_Body (Object : Entries.Protection_Entries_Access);
118    --  Called from within an entry body procedure, indicates that the
119    --  corresponding entry call has been serviced.
120
121    procedure Exceptional_Complete_Entry_Body
122      (Object : Entries.Protection_Entries_Access;
123       Ex     : Ada.Exceptions.Exception_Id);
124    --  Perform all of the functions of Complete_Entry_Body. In addition,
125    --  report in Ex the exception whose propagation terminated the entry
126    --  body to the runtime system.
127
128    procedure Cancel_Protected_Entry_Call (Block : in out Communication_Block);
129    --  Attempt to cancel the most recent protected entry call. If the call is
130    --  not queued abortably, wait until it is or until it has completed.
131    --  If the call is actually cancelled, the called object will be
132    --  locked on return from this call. Get_Cancelled (Block) can be
133    --  used to determine if the cancellation took place; there
134    --  may be entries needing service in this case.
135    --
136    --  Block passes information between this and other runtime calls.
137
138    function Enqueued (Block : Communication_Block) return Boolean;
139    --  Returns True if the Protected_Entry_Call which returned the
140    --  specified Block object was queued; False otherwise.
141
142    function Cancelled (Block : Communication_Block) return Boolean;
143    --  Returns True if the Protected_Entry_Call which returned the
144    --  specified Block object was cancelled, False otherwise.
145
146    procedure Requeue_Protected_Entry
147      (Object     : Entries.Protection_Entries_Access;
148       New_Object : Entries.Protection_Entries_Access;
149       E          : Protected_Entry_Index;
150       With_Abort : Boolean);
151    --  If Object = New_Object, queue the protected entry call on Object
152    --   currently being serviced on the queue corresponding to the entry
153    --   represented by E.
154    --
155    --  If Object /= New_Object, transfer the call to New_Object.E,
156    --   executing or queuing it as appropriate.
157    --
158    --  With_Abort---True if the call is to be queued abortably, false
159    --   otherwise.
160
161    procedure Requeue_Task_To_Protected_Entry
162      (New_Object : Entries.Protection_Entries_Access;
163       E          : Protected_Entry_Index;
164       With_Abort : Boolean);
165    --  Transfer task entry call currently being serviced to entry E
166    --   on New_Object.
167    --
168    --  With_Abort---True if the call is to be queued abortably, false
169    --   otherwise.
170
171    function Protected_Count
172      (Object : Entries.Protection_Entries'Class;
173       E      : Protected_Entry_Index)
174       return   Natural;
175    --  Return the number of entry calls to E on Object
176
177    function Protected_Entry_Caller
178      (Object : Entries.Protection_Entries'Class) return Task_Id;
179    --  Return value of E'Caller, where E is the protected entry currently
180    --  being handled. This will only work if called from within an entry
181    --  body, as required by the LRM (C.7.1(14)).
182
183    --  For internal use only
184
185    procedure PO_Do_Or_Queue
186      (Self_ID    : Task_Id;
187       Object     : Entries.Protection_Entries_Access;
188       Entry_Call : Entry_Call_Link);
189    --  This procedure either executes or queues an entry call, depending
190    --  on the status of the corresponding barrier. It assumes that abort
191    --  is deferred and that the specified object is locked.
192
193 private
194    type Communication_Block is record
195       Self      : Task_Id;
196       Enqueued  : Boolean := True;
197       Cancelled : Boolean := False;
198    end record;
199    pragma Volatile (Communication_Block);
200
201    --  The Communication_Block seems to be a relic. At the moment, the
202    --  compiler seems to be generating unnecessary conditional code based on
203    --  this block. See the code generated for async. select with task entry
204    --  call for another way of solving this ???
205
206 end System.Tasking.Protected_Objects.Operations;