annotate gcc/ada/libgnarl/s-tpobop.ads @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- SYSTEM.TASKING.PROTECTED_OBJECTS.OPERATIONS --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNARL is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNARL was developed by the GNARL team at Florida State University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- This package contains all the extended primitives related to protected
kono
parents:
diff changeset
33 -- objects with entries.
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 -- The handling of protected objects with no entries is done in
kono
parents:
diff changeset
36 -- System.Tasking.Protected_Objects, the simple routines for protected
kono
parents:
diff changeset
37 -- objects with entries in System.Tasking.Protected_Objects.Entries. The
kono
parents:
diff changeset
38 -- split between Entries and Operations is needed to break circular
kono
parents:
diff changeset
39 -- dependencies inside the run time.
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
kono
parents:
diff changeset
42 -- Any changes to this interface may require corresponding compiler changes.
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 with Ada.Exceptions;
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 with System.Tasking.Protected_Objects.Entries;
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 package System.Tasking.Protected_Objects.Operations is
kono
parents:
diff changeset
49 pragma Elaborate_Body;
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 type Communication_Block is private;
kono
parents:
diff changeset
52 -- Objects of this type are passed between GNARL calls to allow RTS
kono
parents:
diff changeset
53 -- information to be preserved.
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 procedure Protected_Entry_Call
kono
parents:
diff changeset
56 (Object : Entries.Protection_Entries_Access;
kono
parents:
diff changeset
57 E : Protected_Entry_Index;
kono
parents:
diff changeset
58 Uninterpreted_Data : System.Address;
kono
parents:
diff changeset
59 Mode : Call_Modes;
kono
parents:
diff changeset
60 Block : out Communication_Block);
kono
parents:
diff changeset
61 -- Make a protected entry call to the specified object.
kono
parents:
diff changeset
62 -- Pend a protected entry call on the protected object represented
kono
parents:
diff changeset
63 -- by Object. A pended call is not queued; it may be executed immediately
kono
parents:
diff changeset
64 -- or queued, depending on the state of the entry barrier.
kono
parents:
diff changeset
65 --
kono
parents:
diff changeset
66 -- E
kono
parents:
diff changeset
67 -- The index representing the entry to be called.
kono
parents:
diff changeset
68 --
kono
parents:
diff changeset
69 -- Uninterpreted_Data
kono
parents:
diff changeset
70 -- This will be returned by Next_Entry_Call when this call is serviced.
kono
parents:
diff changeset
71 -- It can be used by the compiler to pass information between the
kono
parents:
diff changeset
72 -- caller and the server, in particular entry parameters.
kono
parents:
diff changeset
73 --
kono
parents:
diff changeset
74 -- Mode
kono
parents:
diff changeset
75 -- The kind of call to be pended
kono
parents:
diff changeset
76 --
kono
parents:
diff changeset
77 -- Block
kono
parents:
diff changeset
78 -- Information passed between runtime calls by the compiler
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 procedure Timed_Protected_Entry_Call
kono
parents:
diff changeset
81 (Object : Entries.Protection_Entries_Access;
kono
parents:
diff changeset
82 E : Protected_Entry_Index;
kono
parents:
diff changeset
83 Uninterpreted_Data : System.Address;
kono
parents:
diff changeset
84 Timeout : Duration;
kono
parents:
diff changeset
85 Mode : Delay_Modes;
kono
parents:
diff changeset
86 Entry_Call_Successful : out Boolean);
kono
parents:
diff changeset
87 -- Same as the Protected_Entry_Call but with time-out specified.
kono
parents:
diff changeset
88 -- This routines is used when we do not use ATC mechanism to implement
kono
parents:
diff changeset
89 -- timed entry calls.
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 procedure Service_Entries (Object : Entries.Protection_Entries_Access);
kono
parents:
diff changeset
92 pragma Inline (Service_Entries);
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 procedure PO_Service_Entries
kono
parents:
diff changeset
95 (Self_ID : Task_Id;
kono
parents:
diff changeset
96 Object : Entries.Protection_Entries_Access;
kono
parents:
diff changeset
97 Unlock_Object : Boolean := True);
kono
parents:
diff changeset
98 -- Service all entry queues of the specified object, executing the
kono
parents:
diff changeset
99 -- corresponding bodies of any queued entry calls that are waiting
kono
parents:
diff changeset
100 -- on True barriers. This is used when the state of a protected
kono
parents:
diff changeset
101 -- object may have changed, in particular after the execution of
kono
parents:
diff changeset
102 -- the statement sequence of a protected procedure.
kono
parents:
diff changeset
103 --
kono
parents:
diff changeset
104 -- Note that servicing an entry may change the value of one or more
kono
parents:
diff changeset
105 -- barriers, so this routine keeps checking barriers until all of
kono
parents:
diff changeset
106 -- them are closed.
kono
parents:
diff changeset
107 --
kono
parents:
diff changeset
108 -- This must be called with abort deferred and with the corresponding
kono
parents:
diff changeset
109 -- object locked.
kono
parents:
diff changeset
110 --
kono
parents:
diff changeset
111 -- If Unlock_Object is set True, then Object is unlocked on return,
kono
parents:
diff changeset
112 -- otherwise Object remains locked and the caller is responsible for
kono
parents:
diff changeset
113 -- the required unlock.
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 procedure Complete_Entry_Body (Object : Entries.Protection_Entries_Access);
kono
parents:
diff changeset
116 -- Called from within an entry body procedure, indicates that the
kono
parents:
diff changeset
117 -- corresponding entry call has been serviced.
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 procedure Exceptional_Complete_Entry_Body
kono
parents:
diff changeset
120 (Object : Entries.Protection_Entries_Access;
kono
parents:
diff changeset
121 Ex : Ada.Exceptions.Exception_Id);
kono
parents:
diff changeset
122 -- Perform all of the functions of Complete_Entry_Body. In addition,
kono
parents:
diff changeset
123 -- report in Ex the exception whose propagation terminated the entry
kono
parents:
diff changeset
124 -- body to the runtime system.
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 procedure Cancel_Protected_Entry_Call (Block : in out Communication_Block);
kono
parents:
diff changeset
127 -- Attempt to cancel the most recent protected entry call. If the call is
kono
parents:
diff changeset
128 -- not queued abortably, wait until it is or until it has completed.
kono
parents:
diff changeset
129 -- If the call is actually cancelled, the called object will be
kono
parents:
diff changeset
130 -- locked on return from this call. Get_Cancelled (Block) can be
kono
parents:
diff changeset
131 -- used to determine if the cancellation took place; there
kono
parents:
diff changeset
132 -- may be entries needing service in this case.
kono
parents:
diff changeset
133 --
kono
parents:
diff changeset
134 -- Block passes information between this and other runtime calls.
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 function Enqueued (Block : Communication_Block) return Boolean;
kono
parents:
diff changeset
137 -- Returns True if the Protected_Entry_Call which returned the
kono
parents:
diff changeset
138 -- specified Block object was queued; False otherwise.
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 function Cancelled (Block : Communication_Block) return Boolean;
kono
parents:
diff changeset
141 -- Returns True if the Protected_Entry_Call which returned the
kono
parents:
diff changeset
142 -- specified Block object was cancelled, False otherwise.
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 procedure Requeue_Protected_Entry
kono
parents:
diff changeset
145 (Object : Entries.Protection_Entries_Access;
kono
parents:
diff changeset
146 New_Object : Entries.Protection_Entries_Access;
kono
parents:
diff changeset
147 E : Protected_Entry_Index;
kono
parents:
diff changeset
148 With_Abort : Boolean);
kono
parents:
diff changeset
149 -- If Object = New_Object, queue the protected entry call on Object
kono
parents:
diff changeset
150 -- currently being serviced on the queue corresponding to the entry
kono
parents:
diff changeset
151 -- represented by E.
kono
parents:
diff changeset
152 --
kono
parents:
diff changeset
153 -- If Object /= New_Object, transfer the call to New_Object.E,
kono
parents:
diff changeset
154 -- executing or queuing it as appropriate.
kono
parents:
diff changeset
155 --
kono
parents:
diff changeset
156 -- With_Abort---True if the call is to be queued abortably, false
kono
parents:
diff changeset
157 -- otherwise.
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 procedure Requeue_Task_To_Protected_Entry
kono
parents:
diff changeset
160 (New_Object : Entries.Protection_Entries_Access;
kono
parents:
diff changeset
161 E : Protected_Entry_Index;
kono
parents:
diff changeset
162 With_Abort : Boolean);
kono
parents:
diff changeset
163 -- Transfer task entry call currently being serviced to entry E
kono
parents:
diff changeset
164 -- on New_Object.
kono
parents:
diff changeset
165 --
kono
parents:
diff changeset
166 -- With_Abort---True if the call is to be queued abortably, false
kono
parents:
diff changeset
167 -- otherwise.
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 function Protected_Count
kono
parents:
diff changeset
170 (Object : Entries.Protection_Entries'Class;
kono
parents:
diff changeset
171 E : Protected_Entry_Index)
kono
parents:
diff changeset
172 return Natural;
kono
parents:
diff changeset
173 -- Return the number of entry calls to E on Object
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 function Protected_Entry_Caller
kono
parents:
diff changeset
176 (Object : Entries.Protection_Entries'Class) return Task_Id;
kono
parents:
diff changeset
177 -- Return value of E'Caller, where E is the protected entry currently
kono
parents:
diff changeset
178 -- being handled. This will only work if called from within an entry
kono
parents:
diff changeset
179 -- body, as required by the LRM (C.7.1(14)).
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 -- For internal use only
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 procedure PO_Do_Or_Queue
kono
parents:
diff changeset
184 (Self_ID : Task_Id;
kono
parents:
diff changeset
185 Object : Entries.Protection_Entries_Access;
kono
parents:
diff changeset
186 Entry_Call : Entry_Call_Link);
kono
parents:
diff changeset
187 -- This procedure either executes or queues an entry call, depending
kono
parents:
diff changeset
188 -- on the status of the corresponding barrier. It assumes that abort
kono
parents:
diff changeset
189 -- is deferred and that the specified object is locked.
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 private
kono
parents:
diff changeset
192 type Communication_Block is record
kono
parents:
diff changeset
193 Self : Task_Id;
kono
parents:
diff changeset
194 Enqueued : Boolean := True;
kono
parents:
diff changeset
195 Cancelled : Boolean := False;
kono
parents:
diff changeset
196 end record;
kono
parents:
diff changeset
197 pragma Volatile (Communication_Block);
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 -- When a program contains limited interfaces, the compiler generates the
kono
parents:
diff changeset
200 -- predefined primitives associated with dispatching selects. One of the
kono
parents:
diff changeset
201 -- parameters of these routines is of type Communication_Block. Even if
kono
parents:
diff changeset
202 -- the program lacks implementing concurrent types, the tasking runtime is
kono
parents:
diff changeset
203 -- dragged in unconditionally because of Communication_Block. To avoid this
kono
parents:
diff changeset
204 -- case, the compiler uses type Dummy_Communication_Block which defined in
kono
parents:
diff changeset
205 -- System.Soft_Links. If the structure of Communication_Block is changed,
kono
parents:
diff changeset
206 -- the corresponding dummy type must be changed as well.
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 -- The Communication_Block seems to be a relic. At the moment, the
kono
parents:
diff changeset
209 -- compiler seems to be generating unnecessary conditional code based on
kono
parents:
diff changeset
210 -- this block. See the code generated for async. select with task entry
kono
parents:
diff changeset
211 -- call for another way of solving this ???
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 end System.Tasking.Protected_Objects.Operations;