Debian Codegraph @

source_2012/sp.mss

raw
1 @comment{ $Source: e:\\cvsroot/ARM/Source/sp.mss,v $ }
2 @comment{ $Revision: 1.80 $ $Date: 2015/04/03 04:12:43 $ $Author: randy $ }
3 @Part(sysprog, Root="ada.mss")
4 @Comment{$Date: 2015/04/03 04:12:43 $}
5
6 @LabeledNormativeAnnex{Systems Programming}
7
8 @begin{Intro}
9 @Redundant[@Defn{systems programming}
10 @Defn{low-level programming}
11 @Defn{real-time systems}
12 @Defn{embedded systems}
13 @Defn{distributed systems}
14 @Defn{information systems}
15 The Systems Programming Annex specifies additional capabilities
16 provided for low-level programming. These capabilities are also
17 required in many real-time, embedded, distributed, and information systems.]
18 @end{Intro}
19
20 @begin{Extend83}
21 @Defn{extensions to Ada 83}
22 This Annex is new to Ada 95.
23 @end{Extend83}
24
25 @LabeledClause{Access to Machine Operations}
26
27 @begin{Intro}
28 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
29 @Redundant[This @Chg{Version=[3],New=[subclause],Old=[clause]} specifies rules regarding access to machine instructions
30 from within an Ada program.]
31 @ChgImplDef{Version=[2],Kind=[Revised],InitialVersion=[0],
32 Text=[@Chg{Version=[2],
33 New=[Implementation-defined intrinsic subprograms],
34 Old=[Support for access to machine instructions]}.]}
35 @end{Intro}
36
37 @begin{ImplReq}
38 @Defn{machine code insertion}
39 The implementation shall support machine code insertions
40 (see @RefSecNum{Machine Code Insertions}) or intrinsic subprograms
41 (see @RefSecNum{Conformance Rules}) (or both).
42 Implementation-defined attributes shall be provided to
43 allow the use of Ada entities as operands.
44 @end{ImplReq}
45
46 @begin{ImplAdvice}
47 The machine code or intrinsics support should allow access to all
48 operations normally available to assembly language programmers for the
49 target environment,
50 including privileged instructions, if any.
51 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
52 Text=[The machine code or intrinsics support should allow access to all
53 operations normally available to assembly language programmers for the
54 target environment.]}]}
55 @begin{Ramification}
56 Of course, on a machine with protection, an attempt to execute a
57 privileged instruction in user mode will probably trap.
58 Nonetheless, we want implementations to provide access to them so that
59 Ada can be used to write systems programs that run in privileged mode.
60 @end{Ramification}
61
62 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
63 @Defn{interface to assembly language}
64 @Defn2{Term=[language], Sec=(interface to assembly)}
65 @Defn{mixed-language programs}
66 @Defn{assembly language}
67 The @Chg{Version=[3],New=[support for ],Old=[]}interfacing @Chg{Version=[3],New=[aspects],Old=[pragmas]}
68 (see @RefSecNum{Interface to Other Languages})
69 should @Chg{Version=[3],New=[include],Old=[support]} interface to assembler;
70 the default assembler should be associated with the convention
71 identifier Assembler.
72 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
73 Text=[Interface to assembler should be supported; the default assembler
74 should be associated with the convention identifier Assembler.]}]}
75
76 If an entity is exported to assembly language, then the implementation
77 should allocate it at an addressable location,
78 and should ensure that it is retained by the linking process,
79 even if not otherwise referenced from the Ada code.
80 The implementation should assume that any call to a machine code or
81 assembler subprogram is allowed to read or update every object that is
82 specified as exported.
83 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
84 Text=[If an entity is exported to assembly language, then the implementation
85 should allocate it at an addressable location even if not otherwise referenced
86 from the Ada code. A call to a machine code or assembler subprogram should
87 be treated as if it could read or update every object that is
88 specified as exported.]}]}
89 @end{ImplAdvice}
90
91 @begin{DocReq}
92
93 The implementation shall document the overhead associated with calling
94 machine-code or intrinsic subprograms, as compared to a fully-inlined
95 call, and to a regular out-of-line call.
96 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
97 Text=[The overhead of calling machine-code or intrinsic subprograms.]}]}
98
99 The implementation shall document the types of
100 the package System.Machine_Code usable for machine code
101 insertions, and the attributes to be used in
102 machine code insertions for references to Ada entities.
103 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
104 Text=[The types and attributes used in machine code insertions.]}]}
105
106 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
107 The implementation shall document the subprogram calling conventions
108 associated with the convention identifiers available for use
109 with the @Chg{Version=[3],New=[Convention aspect],Old=[interfacing pragmas]}
110 (Ada and Assembler, at a minimum),
111 including register saving,
112 exception propagation, parameter passing, and function value returning.
113 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
114 Text=[The subprogram calling conventions for all supported convention
115 identifiers.]}]}
116
117 For exported and imported subprograms,
118 the implementation shall document the mapping
119 between the Link_Name string, if specified, or
120 the Ada designator, if not, and the external link name used
121 for such a subprogram.
122 @ChgImplDef{Version=[2],Kind=[Deleted],InitialVersion=[0],
123 Text=[@ChgDeleted{Version=[2],
124 Text=[Implementation-defined aspects of access to machine operations.]}]}
125 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
126 Text=[The mapping between the Link_Name or Ada designator and the external
127 link name.]}]}
128
129 @end{DocReq}
130
131 @begin{ImplAdvice}
132
133 The implementation should ensure that little or no overhead is associated
134 with calling intrinsic and machine-code subprograms.
135 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
136 Text=[Little or no overhead should be associated
137 with calling intrinsic and machine-code subprograms.]}]}
138
139 @Leading@;It is recommended that intrinsic subprograms be provided for convenient
140 access to any machine operations that provide special capabilities
141 or efficiency and that are not otherwise available through the language
142 constructs. Examples of such instructions
143 include:
144 @begin{itemize}
145
146 Atomic read-modify-write operations @em e.g., test and set, compare and swap,
147 decrement and test, enqueue/dequeue.
148
149 Standard numeric functions @em e.g., @i{sin}, @i{log}.
150
151 String manipulation operations @em e.g., translate and test.
152
153 Vector operations @em e.g., compare vector against thresholds.
154
155 Direct operations on I/O ports.
156
157 @end{itemize}
158 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
159 Text=[Intrinsic subprograms should be provided to access any machine operations
160 that provide special capabilities or efficiency not normally available.]}]}
161
162 @end{ImplAdvice}
163
164 @LabeledClause{Required Representation Support}
165
166 @begin{Intro}
167 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
168 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
169 This @Chg{Version=[3],New=[subclause],Old=[clause]} specifies minimal requirements on the
170 @Chg{Version=[2],New=[],Old=[implementation's ]}support for representation
171 items and related features.
172 @end{Intro}
173
174 @begin{ImplReq}
175 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
176 @PDefn2{Term=[recommended level of support], Sec=(required in Systems
177 Programming Annex)}
178 The implementation shall support at least the functionality
179 defined by the recommended levels of support in @Chg{Version=[3],New=[Clause],
180 Old=[Section]} @RefSecNum{Representation Issues}.
181 @end{ImplReq}
182
183 @LabeledClause{Interrupt Support}
184
185 @begin{Intro}
186 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
187 @Redundant[This @Chg{Version=[3],New=[subclause],Old=[clause]} specifies
188 the language-defined model for hardware interrupts
189 in addition to mechanisms for handling interrupts.]
190 @IndexSee{Term=[signal],See=(interrupt)}
191 @end{Intro}
192
193 @begin{RunTime}
194
195 @Defn{interrupt}
196 @Redundant[An @i{interrupt} represents a class of events that are detected by
197 the hardware or the system software.]
198 @Defn2{Term=[occurrence], Sec=(of an interrupt)}
199 Interrupts are said to occur. An @i{occurrence} of an interrupt is
200 separable into generation and delivery.
201 @Defn2{Term=[generation], Sec=(of an interrupt)}
202 @i{Generation} of an interrupt is the event in the underlying hardware
203 or system that makes the interrupt available to the program.
204 @Defn2{Term=[delivery], Sec=(of an interrupt)}
205 @i{Delivery} is the action that invokes part of the program as
206 response to the interrupt occurrence.
207 @Defn{pending interrupt occurrence}
208 Between generation and delivery, the interrupt occurrence @Redundant[(or
209 interrupt)] is @i{pending}.
210 @Defn{blocked interrupt}
211 Some or all interrupts may be @i{blocked}. When an interrupt is blocked, all
212 occurrences of that interrupt are prevented from being delivered.
213 @Defn2{Term=[attaching], Sec=(to an interrupt)}
214 @Defn{reserved interrupt}
215 Certain interrupts are @i{reserved}. The set of reserved interrupts is
216 implementation defined. A reserved interrupt is either an interrupt for
217 which user-defined handlers are not supported, or one which
218 already has an attached handler by some other implementation-defined means.
219 @Defn{interrupt handler}@PDefn2{Term=[handler],Sec=[interrupt]}
220 Program units can be connected to nonreserved interrupts. While
221 connected, the program unit is said to be @i{attached} to that interrupt.
222 The execution of that program unit, the @i{interrupt handler}, is invoked upon
223 delivery of the interrupt occurrence.
224 @ChgImplDef{Version=[2],Kind=[Deleted],InitialVersion=[0],
225 Text=[@ChgDeleted{Version=[2],
226 Text=[Implementation-defined aspects of interrupts.]}]}
227 @begin{Honest}
228 As an obsolescent feature,
229 interrupts may be attached to task entries by an address clause.
230 See @RefSecNum{Interrupt Entries}.
231 @end{Honest}
232
233 While a handler is attached to an interrupt, it is called once for each
234 delivered occurrence of that interrupt. While the handler executes, the
235 corresponding interrupt is blocked.
236
237 While an interrupt is blocked, all occurrences of that interrupt are prevented
238 from being delivered. Whether such occurrences remain pending or are lost is
239 implementation defined.
240
241 @Defn{default treatment}
242 Each interrupt has a @i{default treatment} which determines the system's
243 response to an occurrence of that interrupt when no user-defined
244 handler is attached. The set of possible default treatments is
245 implementation defined, as is the method (if one exists) for configuring
246 the default treatments for interrupts.
247
248 An interrupt is delivered to the handler (or default treatment) that is in
249 effect for that interrupt at the time of delivery.
250
251 An exception propagated from a handler that is invoked by an
252 interrupt has no effect.
253
254 @Redundant[If the Ceiling_Locking policy (see @RefSecNum{Priority Ceiling Locking}) is
255 in effect, the interrupt handler executes with the active priority that is the
256 ceiling priority of the corresponding protected object.]
257
258 @end{RunTime}
259
260 @begin{ImplReq}
261
262 The implementation shall provide a mechanism to determine the minimum
263 stack space that is needed
264 for each interrupt handler and to reserve that space for
265 the execution of the handler. @Redundant{This space should accommodate
266 nested invocations of the handler where the system permits this.}
267
268 If the hardware or the underlying system holds pending interrupt
269 occurrences, the implementation shall provide for later delivery
270 of these occurrences to the program.
271
272 If the Ceiling_Locking policy is not in effect, the implementation
273 shall provide means for the application to specify whether interrupts
274 are to be blocked during protected actions.
275
276 @end{ImplReq}
277
278 @begin{DocReq}
279 @Leading@;The implementation shall document the following items:
280 @begin{Discussion}
281 This information may be different for different forms of interrupt handlers.
282 @end{Discussion}
283 @begin{Enumerate}
284 For each interrupt, which interrupts are blocked from delivery when a handler
285 attached to that interrupt executes (either as a result of an interrupt
286 delivery or of an ordinary call on a procedure of the corresponding
287 protected object).
288
289 Any interrupts that cannot be blocked, and the effect of attaching
290 handlers to such interrupts, if this is permitted.
291
292 Which run-time stack an interrupt handler uses when it executes as a
293 result of an interrupt delivery; if this is configurable, what is the
294 mechanism to do so; how to specify how much space to reserve on that stack.
295
296 Any implementation- or hardware-specific activity that happens
297 before a user-defined interrupt handler gets control (e.g.,
298 reading device registers, acknowledging devices).
299
300 Any timing or other limitations imposed on the execution of interrupt handlers.
301
302 The state (blocked/unblocked) of the nonreserved interrupts
303 when the program starts; if some interrupts are unblocked, what
304 is the mechanism a program can use to protect itself before it
305 can attach the corresponding handlers.
306
307 Whether the interrupted task is allowed to resume execution before the
308 interrupt handler returns.
309
310 The treatment of interrupt occurrences that are generated while
311 the interrupt is blocked; i.e., whether one or more occurrences
312 are held for later delivery, or all are lost.
313
314 Whether predefined or implementation-defined exceptions are raised as a
315 result of the occurrence of any interrupt, and the mapping between the
316 machine interrupts (or traps) and the predefined
317 exceptions.
318
319 On a multi-processor, the rules governing the delivery of an interrupt
320 to a particular processor.
321 @end{Enumerate}
322 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
323 Text=[The treatment of interrupts.]}]}
324 @ChgNote{A Bob Duff explanation, but this is just too much junk.}
325 @end{DocReq}
326
327 @begin{ImplPerm}
328
329 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
330 If the underlying system or hardware does not allow interrupts to be
331 blocked, then no blocking is required @Redundant[as part of the execution of
332 subprograms of a protected object @Chg{Version=[2],New=[for which],Old=[whose]}
333 one of its subprograms is an interrupt handler].
334
335 In a multi-processor with more than one interrupt subsystem, it is
336 implementation defined whether (and how) interrupt sources from
337 separate subsystems share the same Interrupt_Id type
338 (see @RefSecNum{The Package Interrupts}).
339 In particular, the meaning of a blocked or pending interrupt may then be
340 applicable to one processor only.
341 @begin{discussion}
342 This issue is tightly related to the issue of scheduling on a
343 multi-processor. In a sense, if a particular interrupt source is not
344 available to all processors, the system is not truly homogeneous.
345
346 One way to approach this problem is to assign sub-ranges within
347 Interrupt_Id to each interrupt subsystem, such that @lquotes@;similar@rquotes@; interrupt
348 sources (e.g. a timer) in different subsystems get a distinct id.
349 @end{Discussion}
350
351 Implementations are allowed to impose timing or other limitations on the
352 execution of interrupt handlers.
353 @begin{Reason}
354 These limitations are often necessary to ensure proper behavior of the
355 implementation.
356 @end{Reason}
357
358 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
359 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
360 Other forms of handlers are allowed to be supported, in which
361 case@Chg{Version=[2],New=[],Old=[,]} the rules of this
362 @Chg{Version=[3],New=[subclause],Old=[@Chg{Version=[2],New=[clause],Old=[subclause]}]}
363 should be adhered to.
364
365 The active priority of the execution of an interrupt handler is allowed to
366 vary from one occurrence of the same interrupt to another.
367
368 @end{ImplPerm}
369
370 @begin{ImplAdvice}
371
372 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
373 If the Ceiling_Locking policy is not in effect, the implementation
374 should provide means for the application to specify which interrupts
375 are to be blocked during protected actions, if the underlying system allows
376 for @Chg{Version=[2],New=[finer-grained],Old=[a finer-grain]} control of
377 interrupt blocking.
378 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
379 Text=[If the Ceiling_Locking policy is not in effect and the target system
380 allows for finer-grained control of interrupt blocking, a means for the
381 application to specify which interrupts are to be blocked during protected
382 actions should be provided.]}]}
383
384 @end{ImplAdvice}
385
386 @begin{Notes}
387
388 The default treatment for an interrupt can be to keep the
389 interrupt pending or to deliver it to an implementation-defined
390 handler. Examples of actions that an implementation-defined
391 handler is allowed to perform include aborting the partition, ignoring
392 (i.e., discarding occurrences of) the interrupt, or queuing one
393 or more occurrences of the interrupt for possible later delivery
394 when a user-defined handler is attached to that interrupt.
395
396 It is a bounded error to call Task_Identification.Current_Task
397 (see @RefSecNum{The Package Task_Identification}) from an interrupt handler.
398
399 The rule that an exception propagated from an interrupt handler has no effect
400 is modeled after the rule about exceptions propagated out of task bodies.
401
402 @end{Notes}
403
404 @LabeledSubClause{Protected Procedure Handlers}
405
406 @begin{NotIso}
407 @ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 1
408 through 6 were moved to @RefSec{Obsolescent Features}.>}]}@Comment{This message
409 should be deleted if the paragraphs are ever renumbered.}
410 @end{NotIso}
411
412 @begin{Syntax}
413 @begin{SyntaxText}
414 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
415 @ChgDeleted{Version=[3],Type=[Leading],KeepNext=[T],Text=[The form of a
416 @nt{pragma} Interrupt_Handler is as follows:]}
417 @end{SyntaxText}
418
419 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
420 @DeletedPragmaSyn<Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3],
421 Text=[@key{pragma} @prag(Interrupt_Handler)(@SynI{handler_}@Syn2{name});]}>
422
423 @begin{SyntaxText}
424 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
425 @ChgDeleted{Version=[3],Type=[Leading],KeepNext=[T],Text=[The form of a
426 @nt{pragma} Attach_Handler is as follows:]}
427 @end{SyntaxText}
428
429 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
430 @DeletedPragmaSyn<Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3],
431 Text=[@key{pragma} @prag(Attach_Handler)(@SynI{handler_}@Syn2{name}, @Syn2{expression});]}>
432 @end{Syntax}
433
434 @begin{Resolution}
435 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
436 @ChgDeleted{Version=[3],Text=[For the Interrupt_Handler and Attach_Handler
437 pragmas, the @SynI{handler_}@nt{name} shall resolve to denote a protected
438 procedure with a parameterless profile.]}
439
440 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
441 @ChgDeleted{Version=[3],Text=[For the Attach_Handler pragma, the expected type
442 for the @nt{expression} is Interrupts.Interrupt_Id
443 (see @RefSecNum{The Package Interrupts}).]}
444 @end{Resolution}
445
446 @begin{StaticSem}
447 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]}
448 @ChgAdded{Version=[3],Type=[Leading],Text=[For a parameterless protected
449 procedure, the following language-defined representation aspects may be
450 specified:]}
451 @begin{Description}
452 @ChgRef{Version=[3],Kind=[Added]}
453 @ChgAdded{Version=[3],Text=[Interrupt_Handler@\
454 The type of aspect Interrupt_Handler is Boolean.
455 If directly specified, the aspect_definition shall be a static expression.
456 @Redundant[This aspect is never inherited;] if not directly specified,
457 the aspect is False.@AspectDefn{Interrupt_Handler}]}
458
459 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Interrupt_Handler],
460 Text=[@ChgAdded{Version=[3],Text=[Protected procedure may be attached to
461 interrupts.]}]}
462
463 @ChgRef{Version=[3],Kind=[Added]}
464 @ChgAdded{Version=[3],Text=[Attach_Handler@\
465 The aspect Attach_Handler is an @nt{expression}, which shall be of type
466 Interrupts.Interrupt_Id. @Redundant[This aspect is never
467 inherited.]@AspectDefn{Attach_Handler}]}
468
469 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Attach_Handler],
470 Text=[@ChgAdded{Version=[3],Text=[Protected procedure is attached to an
471 interrupt.]}]}
472
473 @end{Description}
474
475 @end{StaticSem}
476
477 @begin{Legality}
478
479 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
480 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0033-1],ARef=[AI05-0229-1]}
481 @Chg{Version=[3],New=[If either the],Old=[The]} Attach_Handler
482 @Chg{Version=[3],New=[or Interrupt_Handler aspect are specified for a
483 protected procedure, the],Old=[pragma is only allowed immediately within the
484 @nt{protected_definition} where the corresponding subprogram is declared.
485 The]} corresponding @nt{protected_@!type_@!declaration}
486 or @nt{single_@!protected_@!declaration}
487 shall be a library@Chg{Version=[2],New=[-],Old=[]}level
488 declaration@Chg{Version=[3],New=[ and shall not be declared within a
489 generic body. @PDefn{generic contract issue}In addition
490 to the places where @LegalityTitle normally apply
491 (see @RefSecNum{Generic Instantiation}), this rule also applies
492 in the private part of an instance of a generic unit],Old=[]}.
493
494 @begin{Discussion}
495 In the case of a @nt{protected_type_declaration},
496 an @nt{object_declaration} of an object of that type
497 need not be at library level.
498
499 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0033-1],ARef=[AI05-0229-1]}
500 @ChgAdded{Version=[3],Text=[We cannot allow these aspects in protected
501 declarations in a generic body, because legality rules are not checked for
502 instance bodies, and these should not be allowed if the instance is not at the
503 library level. The protected types can be declared in the private part if this
504 is desired. Note that while the 'Access to use the handler would provide the
505 check in the case of Interrupt_Handler, there is no other check for
506 Attach_Handler. Since these aspects are so similar, we want the rules to be the
507 same.]}
508 @end{Discussion}
509
510 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00253-01],ARef=[AI95-00303-01]}
511 @ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0033-1]}
512 @ChgDeleted{Version=[3],Text=[The Interrupt_Handler pragma is only
513 allowed immediately within @Chg{Version=[2],New=[the],Old=[a]}
514 @nt{protected_definition}@Chg{Version=[2],New=[ where the
515 corresponding subprogram is declared],Old=[]}.
516 The cor@!responding @nt{protected_@!type_declaration} @Chg{Version=[2],New=[or
517 @nt{single_@!protected_@!declaration} ],Old=[]}shall
518 be a library@Chg{Version=[2],New=[-],Old=[]}level
519 declaration.@Chg{Version=[2],New=[],Old=[ In addition, any
520 @nt{object_@!declaration} of such a type shall be a library level declaration.]}]}
521 @end{Legality}
522
523 @begin{RunTime}
524
525 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
526 If the @Chg{Version=[3],New=[],Old=[pragma ]}Interrupt_Handler
527 @Chg{Version=[3],New=[aspect of a protected procedure is True],Old=[appears in a
528 @nt{protected_definition}]}, then the
529 @Chg{Version=[3],New=[],Old=[corresponding ]}procedure
530 @Chg{Version=[3],New=[may],Old=[can]}
531 be attached dynamically, as a handler, to
532 interrupts (see @RefSecNum{The Package Interrupts}).
533 @Redundant[Such procedures are allowed to be attached to multiple interrupts.]
534
535 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
536 @Defn2{Term=[creation], Sec=(of a protected object)}
537 @Defn2{Term=[initialization], Sec=(of a protected object)}
538 The @nt{expression} @Chg{Version=[3],New=[specified for],Old=[in]} the
539 Attach_Handler @Chg{Version=[3],New=[aspect of a protected procedure @i<P>
540 is evaluated as part of the creation of the protected object that
541 contains @i<P>.
542 The value of the @nt{expression} identifies],Old=[pragma @Redundant[as evaluated at
543 object creation time] specifies]} an interrupt. As part
544 of the initialization of that object,
545 @Chg{Version=[3],New=[@i<P> (],Old=[if the Attach_Handler pragma is
546 specified, ]}the @SynI{handler}
547 procedure@Chg{Version=[3],New=[)],Old=[]}
548 is attached to the @Chg{Version=[3],New=[identified],Old=[specified]} interrupt.
549 @IndexCheck{Reserved_Check}
550 A check is made that the corresponding interrupt is not reserved.
551 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
552 Program_Error is raised if the check fails, and the existing treatment
553 for the interrupt is not affected.
554
555 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
556 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
557 @Defn2{Term=[initialization], Sec=(of a protected object)}
558 @IndexCheck{Ceiling_Check}
559 If the Ceiling_Locking policy (see @RefSecNum{Priority Ceiling Locking}) is
560 in effect@Chg{Version=[2],New=[,],Old=[]} then upon the initialization of a
561 protected object @Chg{Version=[3],New=[that contains a protected
562 procedure ],Old=[]}@Chg{Version=[2],New=[for which],Old=[that]} either
563 @Chg{Version=[3],New=[the],Old=[an]}
564 Attach_Handler@Chg{Version=[3],New=[ aspect is specified],Old=[]} or
565 @Chg{Version=[3],New=[the ],Old=[]} Interrupt_Handler
566 @Chg{Version=[3],New=[aspect is True],Old=[pragma applies to one of its
567 procedures]},
568 a check is made that the @Chg{Version=[3],New=[initial ],Old=[]}ceiling
569 priority @Chg{Version=[3],New=[of the object],Old=[defined in the
570 @nt{protected_definition}]} is in the range of System.@!Interrupt_Priority.
571 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
572 If the check fails, Program_Error is raised.
573
574 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0068],ARef=[AI95-00121-01]}
575 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
576 @Defn2{Term=[finalization], Sec=(of a protected object)}
577 When a protected object is finalized, for any of its procedures that are
578 attached to interrupts, the handler is detached. If the handler was
579 attached by a procedure in the Interrupts package or if no user
580 handler was previously attached to the interrupt, the default treatment is
581 restored. @Chg{New=[If @Chg{Version=[3],New=[the],Old=[an]} Attach_@!Handler
582 @Chg{Version=[3],New=[aspect],Old=[pragma]} was
583 @Chg{Version=[3],New=[specified],Old=[used]} and the most recently
584 attached handler for the same interrupt is the same as the one that was
585 attached at the time the protected object was initialized],
586 Old=[Otherwise, @Redundant[that is, if an
587 Attach_@!Handler pragma was specified]]}, the previous handler is
588 restored.
589 @begin{Discussion}
590 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0068],ARef=[AI95-00121-01]}
591 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00303-01]}
592 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
593 @Chg{New=[If all protected objects for interrupt handlers are declared at the
594 library@Chg{Version=[2],New=[ ],Old=[-]}level],Old=[Since only library-level
595 protected procedures can be attached as
596 handlers using the Interrupts package]}, the finalization discussed above
597 occurs only as part of the finalization of all library-level packages in
598 a partition.
599 @Chg{New=[However, objects of a protected type containing
600 @Chg{Version=[3],New=[procedures with ],Old=[]}an Attach_@!Handler
601 @Chg{Version=[3],New=[aspect specified],Old=[pragma]} need not be at the library level.
602 Thus, an implementation needs to be
603 able to restore handlers during the execution of the program.@Chg{Version=[2],
604 New=[ (An object with an Interrupt_@!Handler @Chg{Version=[3],New=[aspect],Old=[pragma]}
605 also need not be at the library level, but such
606 a handler cannot be attached to an interrupt using the Interrupts package.)],
607 Old=[]}],Old=[]}
608 @end{Discussion}
609
610 When a handler is attached to an interrupt, the interrupt is blocked
611 @Redundant[(subject to the @ImplPermName in @RefSecNum{Interrupt Support})]
612 during the execution of every protected action on the protected object
613 containing the handler.
614
615 @end{RunTime}
616
617 @begin{Erron}
618 @PDefn2{Term=(erroneous execution),Sec=(cause)}
619 If the Ceiling_Locking policy (see @RefSecNum{Priority Ceiling Locking}) is
620 in effect and an interrupt is delivered to a handler, and the interrupt
621 hardware priority is higher than the ceiling priority of the corresponding
622 protected object, the execution of the program is erroneous.
623
624 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0068],ARef=[AI95-00121-01]}
625 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0229-1]}
626 @ChgAdded{Version=[1],Text=[@PDefn2{Term=(erroneous execution),Sec=(cause)}
627 If the handlers for a given interrupt attached via
628 @Chg{Version=[3],New=[aspect],Old=[pragma]} Attach_Handler
629 are not attached and detached in a stack-like (LIFO) order,
630 program execution is erroneous. In particular, when a protected object is
631 finalized, the execution is erroneous if any of the procedures of the
632 protected object are attached to interrupts via
633 @Chg{Version=[3],New=[aspect],Old=[pragma]} Attach_@!Handler and
634 the most recently attached handler for the same interrupt is not the same as
635 the one that was attached at the time the protected object was initialized.]}
636 @begin{Discussion}
637 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0068],ARef=[AI95-00121-01]}
638 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
639 @ChgAdded{Version=[1],Text=[This simplifies implementation of the Attach_@!Handler
640 @Chg{Version=[3],New=[aspect],Old=[pragma]} by not requiring a check that the
641 current handler is the same as the one attached by the initialization of a
642 protected object.]}
643 @end{Discussion}
644 @end{Erron}
645
646 @begin{Metrics}
647 @Leading@Keepnext@;The following metric shall be documented by the implementation:
648 @ChgNote{This was @begin{enumerate}, which is wrong}
649 @begin{Itemize}
650 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
651 The worst@Chg{Version=[2],New=[-],Old=[ ]}case overhead for an interrupt
652 handler that is a parameterless
653 protected procedure, in clock cycles. This is the execution time not
654 directly attributable to the handler procedure or the interrupted execution.
655 It is estimated as C @en@; (A+B), where A is how long it takes to complete a given
656 sequence of instructions without any interrupt, B is how long it takes to
657 complete a normal call to a given protected procedure, and C is how long it
658 takes to complete the same sequence of instructions when it is interrupted by
659 one execution of the same procedure called via an interrupt.
660 @begin{ImplNote}
661 The instruction sequence and interrupt handler used to measure interrupt
662 handling overhead should be chosen so as to maximize the execution time cost
663 due to cache misses. For example, if the processor has cache memory and the
664 activity of an interrupt handler could invalidate the contents of cache memory, the handler should be written such that it invalidates all of the cache memory.
665 @end{ImplNote}
666 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
667 Text=[The metrics for interrupt handlers.]}]}
668 @ChgNote{This was @end{enumerate}, which is wrong}
669 @end{Itemize}
670 @end{Metrics}
671
672 @begin{ImplPerm}
673 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
674 When the @Chg{Version=[3],New=[aspects],Old=[pragmas]} Attach_Handler or
675 Interrupt_Handler @Chg{Version=[3],New=[are specified for],Old=[apply to]}
676 a protected procedure, the implementation is allowed to impose
677 implementation-defined restrictions on the
678 corresponding @nt{protected_@!type_@!declaration} and @nt{protected_@!body}.
679 @begin{Ramification}
680 The restrictions may be on the constructs that are allowed within them,
681 and on ordinary calls (i.e. not via interrupts) on protected operations in
682 these protected objects.
683 @end{Ramification}
684 @ChgImplDef{Version=[3],Kind=[Revised],InitialVersion=[2],
685 Text=[@Chg{Version=[2],
686 New=[Any restrictions on a protected procedure or its containing type when
687 @Chg{Version=[3],New=[an aspect],Old=[a @nt{pragma}]}
688 Attach_handler or Interrupt_Handler
689 @Chg{Version=[3],New=[is specified],Old=[applies]}.],Old=[]}]}
690
691 An implementation may use a different mechanism for invoking a protected
692 procedure in response to a hardware interrupt than is used for a call
693 to that protected procedure from a task.
694 @begin{Discussion}
695 This is despite the fact that the priority of an interrupt handler
696 (see @RefSecNum{Task Priorities}) is modeled after a hardware task calling the
697 handler.
698 @end{Discussion}
699
700 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
701 @Defn{notwithstanding}
702 Notwithstanding what this subclause says elsewhere,
703 the Attach_Handler and Interrupt_Handler
704 @Chg{Version=[3],New=[aspects],Old=[pragmas]} are allowed to be used
705 for other, implementation defined, forms of interrupt handlers.
706 @begin{Ramification}
707 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
708 For example, if an implementation wishes to allow interrupt
709 handlers to have parameters, it is allowed to do so via these
710 @Chg{Version=[3],New=[aspects],Old=[pragmas]};
711 it need not invent implementation-defined
712 @Chg{Version=[3],New=[aspects],Old=[pragmas]} for the purpose.
713 @end{Ramification}
714 @ChgImplDef{Version=[3],Kind=[Revised],InitialVersion=[2],
715 Text=[@Chg{Version=[2],
716 New=[Any other forms of interrupt handler supported by the
717 Attach_Handler and Interrupt_Handler
718 @Chg{Version=[3],New=[aspects],Old=[pragmas]}.],Old=[]}]}
719
720 @end{ImplPerm}
721
722 @begin{ImplAdvice}
723
724 Whenever possible, the implementation should allow interrupt handlers to be
725 called directly by the hardware.
726 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
727 Text=[Interrupt handlers should be called directly by the hardware.]}]}
728
729 Whenever practical, the implementation should
730 detect violations of any implementation-defined restrictions
731 before run time.
732 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
733 Text=[Violations of any implementation-defined restrictions on interrupt
734 handlers should be detected before run time.]}]}
735
736 @end{ImplAdvice}
737
738 @begin{Notes}
739
740 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
741 The Attach_Handler @Chg{Version=[3],New=[aspect may],Old=[pragma can]}
742 provide static attachment of handlers to
743 interrupts if the implementation supports preelaboration of protected
744 objects. (See @RefSecNum{Preelaboration Requirements}.)
745
746 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
747 @Chg{Version=[2],New=[A],Old=[The ceiling priority of a]}
748 protected object that
749 @Chg{Version=[2],New=[has a (protected) procedure],
750 Old=[one of its procedures is]}
751 attached to an interrupt should
752 @Chg{Version=[2],New=[have a ceiling priority],
753 Old=[be]} at least as high as the highest
754 processor priority at which that interrupt will ever be delivered.
755
756 Protected procedures can also be attached dynamically to interrupts
757 via operations declared in the predefined package Interrupts.
758
759 An example of a possible implementation-defined restriction is
760 disallowing the use of the standard storage pools within the body of
761 a protected procedure that is an interrupt handler.
762
763 @end{Notes}
764
765 @begin{Incompatible95}
766 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00253-01]}
767 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
768 @b[Amendment Correction:] Corrected the wording so that the rules for the
769 use of Attach_Handler and Interrupt_Handler are identical. This means
770 that uses of pragma Interrupt_Handler outside of the target protected type
771 or single protected object are now illegal.]}
772 @end{Incompatible95}
773
774 @begin{DiffWord95}
775 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0068],ARef=[AI95-00121-01]}
776 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified the meaning of
777 @lquotes@;the previous handler@rquotes when finalizing protected objects
778 containing interrupt handlers.]}
779
780 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00303-01]}
781 @ChgAdded{Version=[2],Text=[Dropped the requirement that an object of a
782 type containing an Interrupt_Handler pragma must be declared at the library
783 level. This was a generic contract model violation. This change is not
784 an extension, as an attempt to attach such a handler with a routine in
785 package Interrupts will fail an accessibility check anyway. Moreover,
786 implementations can retain the rule as an implementation-defined
787 restriction on the use of the type, as permitted by the @ImplPermTitle
788 above.]}
789 @end{Diffword95}
790
791 @begin{Extend2005}
792 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
793 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
794 Aspects Interrupt_Handler and Attach_Handler are new; @nt{pragma}s
795 Interrupt_Handler and Attach_Handler are now obsolescent.]}
796 @end{Extend2005}
797
798 @begin{DiffWord2005}
799 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0033-1]}
800 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
801 Added missing generic contract wording for the aspects Attach_Handler and
802 Interrupt_Handler.]}
803 @end{DiffWord2005}
804
805
806
807 @LabeledSubClause{The Package Interrupts}
808
809 @begin{StaticSem}
810
811 @Leading@Keepnext@;The following language-defined packages exist:
812 @begin{example}
813 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0167-1]}
814 @key{with} System;@ChildUnit{Parent=[Ada],Child=[Interrupts]}@Chg{Version=[3],New=[
815 @key{with} System.Multiprocessors;],Old=[]}
816 @key[package] Ada.Interrupts @key[is]
817 @key[type] @AdaTypeDefn{Interrupt_Id} @key[is] @RI{implementation-defined};
818 @key[type] @AdaTypeDefn{Parameterless_Handler} @key[is]
819 @key[access] @key[protected] @key[procedure];
820
821 @ChgRef{Version=[1], Kind=[Deleted]}
822 @Chg[New=<>,Old=<@ @;@comment{Empty paragraph to hang junk paragraph number from original RM}>]
823
824 @key[function] @AdaSubDefn{Is_Reserved} (Interrupt : Interrupt_Id)
825 @key[return] Boolean;
826
827 @key[function] @AdaSubDefn{Is_Attached} (Interrupt : Interrupt_Id)
828 @key[return] Boolean;
829
830 @key[function] @AdaSubDefn{Current_Handler} (Interrupt : Interrupt_Id)
831 @key[return] Parameterless_Handler;
832
833 @key[procedure] @AdaSubDefn{Attach_Handler}
834 (New_Handler : @key[in] Parameterless_Handler;
835 Interrupt : @key[in] Interrupt_Id);
836
837 @key[procedure] @AdaSubDefn{Exchange_Handler}
838 (Old_Handler : @key[out] Parameterless_Handler;
839 New_Handler : @key[in] Parameterless_Handler;
840 Interrupt : @key[in] Interrupt_Id);
841
842 @key[procedure] @AdaSubDefn{Detach_Handler}
843 (Interrupt : @key[in] Interrupt_Id);
844
845 @key[function] @AdaSubDefn{Reference} (Interrupt : Interrupt_Id)
846 @key{return} System.Address;
847
848 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0167-1]}
849 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Get_CPU} (Interrupt : Interrupt_Id)
850 @key{return} System.Multiprocessors.CPU_Range;]}
851
852 @key[private]
853 ... -- @RI{not specified by the language}
854 @key[end] Ada.Interrupts;
855
856
857 @key[package] Ada.Interrupts.Names @key[is]@ChildUnit{Parent=[Ada.Interrupts],Child=[Names]}
858 @RI{implementation-defined} : @key[constant] Interrupt_Id :=
859 @RI{implementation-defined};
860 . . .
861 @RI{implementation-defined} : @key[constant] Interrupt_Id :=
862 @RI{implementation-defined};
863 @key[end] Ada.Interrupts.Names;
864 @end{example}
865
866 @end{StaticSem}
867
868 @begin{RunTime}
869
870 The Interrupt_Id type is an implementation-defined discrete type used to
871 identify interrupts.
872
873 The Is_Reserved function returns True if and only if the specified
874 interrupt is reserved.
875
876 The Is_Attached function returns True if and only if a user-specified
877 interrupt handler is attached to the interrupt.
878
879 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0069],ARef=[AI95-00166-01]}
880 The Current_Handler function returns a value that represents the
881 attached handler of the interrupt. If no user-defined handler is attached to
882 the interrupt, Current_Handler returns @Chg{New=[@key{null}],
883 Old=[a value that designates the default treatment; calling Attach_Handler
884 or Exchange_Handler with this value restores the default treatment]}.
885
886 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
887 The Attach_Handler procedure attaches the specified handler to the
888 interrupt, overriding any existing treatment (including a user handler)
889 in effect for that interrupt.
890 If New_Handler is @key[null], the default treatment is restored.
891 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
892 If New_Handler designates a protected procedure @Chg{Version=[3],New=[for],
893 Old=[to]} which the @Chg{Version=[3],New=[aspect],
894 Old=[pragma]}
895 Interrupt_@!Handler @Chg{Version=[3],New=[is False],Old=[does not apply]},
896 Program_Error is raised. In
897 this case, the operation does not modify the existing interrupt treatment.
898
899 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0069],ARef=[AI95-00166-01]}
900 The Exchange_Handler procedure operates in the same manner as Attach_Handler
901 with the addition that the value returned in Old_Handler designates the
902 previous treatment for the specified interrupt.@Chg{New=[ If the previous
903 treatment is not a user-defined handler, @key[null] is returned.],Old=[]}
904 @begin{Ramification}
905 Calling Attach_Handler or Exchange_Handler with this value for New_Handler
906 restores the previous handler.
907
908 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0069],ARef=[AI95-00166-01]}
909 @ChgAdded{Version=[1],Text=[If the application uses only parameterless procedures as
910 handlers (other types of handlers may be provided by the implementation, but are not
911 required by the standard), then if Old_Handler is not @key(null), it may be
912 called to execute the previous handler. This provides a way to cascade
913 application interrupt handlers. However, the default handler cannot be
914 cascaded this way (Old_Handler must be @key(null) for the default handler).]}
915 @end{Ramification}
916
917 The Detach_Handler procedure restores the default treatment for the
918 specified interrupt.
919
920 For all operations defined in this package that take a parameter of type
921 Interrupt_Id, with the exception of Is_Reserved and Reference, a check is
922 made that the specified interrupt is not reserved.
923 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
924 Program_Error is raised if this check fails.
925
926 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
927 If, by using the Attach_Handler, Detach_Handler, or Exchange_Handler
928 procedures, an attempt is made to
929 detach a handler that was attached statically (using the
930 @Chg{Version=[3],New=[aspect],Old=[pragma]}
931 Attach_Handler), the handler is not detached and Program_Error is
932 raised.
933 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
934
935 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
936 The Reference function returns a value of type System.Address that can
937 be used to attach a task entry@Chg{Version=[2],New=[],Old=[,]} via an
938 address clause (see @RefSecNum{Interrupt Entries}) to the interrupt
939 specified by Interrupt. This function raises Program_Error if attaching
940 task entries to interrupts (or to this particular interrupt) is not supported.
941 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
942
943 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0153-3]}
944 @ChgAdded{Version=[3],Text=[The function Get_CPU returns the processor on which
945 the handler for Interrupt is executed. If the handler can execute on more than
946 one processor the value System.Multiprocessors.Not_A_Specific_CPU is returned.]}
947
948 @end{RunTime}
949
950 @begin{ImplReq}
951
952 At no time during attachment or exchange of handlers shall the current handler
953 of the corresponding interrupt be undefined.
954
955 @end{ImplReq}
956
957 @begin{DocReq}
958
959 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
960 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
961 If the Ceiling_Locking policy (see @RefSecNum{Priority Ceiling Locking}) is
962 in effect@Chg{Version=[2],New=[,],Old=[]} the implementation shall document
963 the default ceiling priority
964 assigned to a protected object that contains
965 @Chg{Version=[3],New=[a protected procedure that specifies ],Old=[]}either
966 the Attach_Handler or
967 Interrupt_Handler @Chg{Version=[3],New=[aspects],Old=[pragmas]},
968 but @Chg{Version=[3],New=[does not specify],Old=[not]} the
969 Interrupt_Priority @Chg{Version=[3],New=[aspect],Old=[pragma]}.
970 @Redundant[This default need not be the same for all interrupts.]
971 @ChgDocReq{Version=[3],Kind=[RevisedAdded],InitialVersion=[2],
972 Text=[@ChgAdded{Version=[2],
973 Text=[If the Ceiling_Locking policy is in effect, the default ceiling priority
974 for a protected object that @Chg{Version=[3],New=[specifies],Old=[contains]}
975 an interrupt handler @Chg{Version=[3],New=[aspect],Old=[pragma]}.]}]}
976
977 @end{DocReq}
978
979 @begin{ImplAdvice}
980
981 If implementation-defined forms of interrupt handler procedures are supported,
982 such as protected procedures with parameters, then for each such form of a
983 handler, a type analogous to Parameterless_@!Handler should be specified in a
984 child package of Interrupts, with the same operations as in the
985 predefined package Interrupts.
986
987 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
988 Text=[If implementation-defined forms of interrupt handler procedures are
989 supported, then for each such form of a
990 handler, a type analogous to Parameterless_@!Handler should be specified in a
991 child package of Interrupts, with the same operations as in the
992 predefined package Interrupts.]}]}
993
994 @end{ImplAdvice}
995
996 @begin{Notes}
997
998 The package Interrupts.Names contains implementation-defined
999 names (and constant values) for the interrupts that are supported by
1000 the implementation.
1001
1002 @end{Notes}
1003
1004 @begin{Examples}
1005 @Leading@Keepnext@i{Example of interrupt handlers:}
1006 @begin{example}
1007 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
1008 Device_Priority : @key[constant]
1009 @key[array] (1..5) of System.Interrupt_Priority := ( ... );@Softpage
1010 @key[protected] @key[type] Device_Interface
1011 (Int_Id : Ada.Interrupts.Interrupt_Id) @Chg{Version=[3],New=[
1012 @key[with] Interrupt_Priority => Device_Priority(Int_Id) ],Old=[]}@key[is]
1013 @key[procedure] Handler@Chg{Version=[3],New=[
1014 @key[with] Attach_Handler => Int_Id],Old=[;
1015 @key[pragma] Attach_Handler(Handler, Int_Id)]};
1016 ...
1017 @Chg{Version=[3],New=[],Old=[@key[pragma] Interrupt_Priority(Device_Priority(Int_Id));
1018 ]}@key[end] Device_Interface;@Softpage
1019 ...
1020 Device_1_Driver : Device_Interface(1);
1021 ...
1022 Device_5_Driver : Device_Interface(5);
1023 ...
1024 @end{example}
1025 @end{Examples}
1026
1027 @begin{DiffWord95}
1028 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0069],ARef=[AI95-00166-01]}
1029 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that the value
1030 returned by Current_Handler and Exchange_Handler for the default treatment
1031 is null.]}
1032 @end{Diffword95}
1033
1034 @begin{Incompatible2005}
1035 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0167-1]}
1036 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}
1037 Function Get_CPU is added to Interrupts. If Interrupts is referenced in
1038 a @nt{use_clause}, and an entity @i<E> with a @nt{defining_identifier} of
1039 Get_CPU is defined in a package that is also referenced in a @nt{use_clause},
1040 the entity @i<E> may no longer be use-visible, resulting in errors. This
1041 should be rare and is easily fixed if it does occur.]}
1042 @end{Incompatible2005}
1043
1044
1045
1046 @ISOOnlyRMNewPageVer{Version=[3]}@Comment{For ISO version of Ada 2012 Standard}
1047 @LabeledClause{Preelaboration Requirements}
1048
1049 @begin{Intro}
1050 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
1051 @Redundant[This @Chg{Version=[3],New=[subclause],Old=[clause]} specifies
1052 additional implementation and documentation
1053 requirements for the Preelaborate pragma (see @RefSecNum{Elaboration Control}).]
1054 @end{Intro}
1055
1056 @begin{ImplReq}
1057
1058 The implementation shall not incur any run-time overhead for the elaboration
1059 checks of subprograms and @ntf{protected_bodies} declared in preelaborated
1060 library units.
1061 @Defn2{Term=[preelaborated],Sec=[implementation requirements]}
1062
1063 The implementation shall not execute any memory write operations after
1064 load time for the elaboration of constant objects
1065 declared immediately within the
1066 declarative region of a preelaborated library package, so long as the
1067 subtype and initial expression (or default initial expressions if
1068 initialized by default) of the @nt<object_declaration> satisfy the
1069 following restrictions.
1070 @Defn{load time}
1071 The meaning of @i{load time} is implementation defined.
1072 @begin{Discussion}
1073 On systems where the image of the partition is initially copied from
1074 disk to RAM, or from ROM to RAM, prior to starting execution of the
1075 partition,
1076 the intention is that @lquotes@;load time@rquotes@; consist of this initial copying
1077 step.
1078 On other systems, load time and run time might actually be interspersed.
1079 @end{Discussion}
1080 @begin{itemize}
1081 Any @nt<subtype_mark> denotes a statically constrained subtype, with
1082 statically constrained subcomponents, if any;
1083
1084 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00161-01]}
1085 @ChgAdded{Version=[2],Text=[no @nt{subtype_mark} denotes a controlled type, a
1086 private type, a private extension, a generic formal private type, a generic
1087 formal derived type, or a descendant of such a type;]}
1088
1089 @begin{Reason}
1090 @ChgRef{Version=[2],Kind=[Added]}
1091 @ChgAdded{Version=[2],Text=[For an
1092 implementation that uses the registration method of finalization, a
1093 controlled object will require some code executed to register the object
1094 at the appropriate point. The other types are those that @i{might} have a
1095 controlled component. None of these types were allowed in preelaborated
1096 units in Ada 95. These types are covered by the @ImplAdviceTitle, of course,
1097 so they should still execute as little code as possible.]}
1098 @end{Reason}
1099
1100 any @nt<constraint> is a static constraint;
1101
1102 any @nt<allocator> is for an access-to-constant type;
1103
1104 any uses of predefined operators appear only within static expressions;
1105
1106 any @ntf<primaries> that are @nt<name>s, other than @nt<attribute_reference>s
1107 for the Access or Address attributes, appear only within static expressions;
1108 @begin{ramification}
1109 This cuts out @nt<attribute_reference>s that are not static, except for
1110 Access and Address.
1111 @end{Ramification}
1112
1113 any @nt<name> that is not part of a static expression is an expanded
1114 name or @nt<direct_name> that statically denotes some entity;
1115 @begin{Ramification}
1116 This cuts out @nt<function_call>s and @nt<type_conversion>s that are not
1117 static, including calls on attribute functions like 'Image and 'Value.
1118 @end{Ramification}
1119
1120 any @nt<discrete_choice> of an @nt<array_aggregate> is static;
1121
1122 no language-defined check associated with the elaboration of the
1123 @nt<object_declaration> can fail.
1124 @begin{Reason}
1125 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
1126 The intent is that aggregates all of whose scalar subcomponents are static@Chg{Version=[2],New=[],Old=[,]}
1127 and all of whose access subcomponents are @key(null), allocators for
1128 access-to-constant types, or X'Access, will be supported with no run-time
1129 code generated.
1130 @end{Reason}
1131 @end{itemize}
1132
1133 @end{ImplReq}
1134
1135 @begin{DocReq}
1136
1137 The implementation shall document any circumstances under which the
1138 elaboration of a preelaborated package causes code to be executed at run time.
1139 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
1140 Text=[Any circumstances when the elaboration of a preelaborated package
1141 causes code to be executed.]}]}
1142
1143 The implementation shall document whether the method used for initialization
1144 of preelaborated variables allows a partition to be restarted without
1145 reloading.
1146 @ChgDocReq{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
1147 Text=[Whether a partition can be restarted without reloading.]}]}
1148 @ChgImplDef{Version=[2],Kind=[Deleted],InitialVersion=[0],
1149 Text=[@ChgDeleted{Version=[2],
1150 Text=[Implementation-defined aspects of preelaboration.]}]}
1151 @begin{discussion}
1152 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
1153 This covers the issue of the @Chg{Version=[2],New=[run-time system],Old=[RTS]}
1154 itself being restartable,
1155 so that need not be a separate @DocReqName.
1156 @end{discussion}
1157
1158 @end{DocReq}
1159
1160 @begin{ImplAdvice}
1161
1162 It is recommended that preelaborated packages be implemented in such a
1163 way that there should be little or no code executed at run time for the
1164 elaboration of entities not already covered by the @ImplReqName@;s.
1165
1166 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
1167 Text=[Preelaborated packages should be implemented such that little or no
1168 code is executed at run time for the elaboration of entities.]}]}
1169 @end{ImplAdvice}
1170
1171 @begin{DiffWord95}
1172 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00161-01]}
1173 @ChgAdded{Version=[2],Text=[Added wording to exclude the additional kinds
1174 of types allowed in preelaborated units from the @ImplReqTitle.]}
1175 @end{DiffWord95}
1176
1177
1178 @LabeledRevisedClause{Version=[4],New=[Aspect Discard_Names],
1179 Old=[Pragma Discard_Names]}
1180
1181 @begin{Intro}
1182 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0072-1]}
1183 @Redundant[@Chg{Version=[4],New=[Specifying the aspect],Old=[A @nt{pragma}]}
1184 Discard_Names @Chg{Version=[4],New=[can],Old=[may]} be used to request a
1185 reduction in storage used for the names of
1186 @Chg{Version=[4],New=[],Old=[certain ]}entities@Chg{Version=[4],New=[ with
1187 runtime name text],Old=[]}.]
1188 @end{Intro}
1189
1190 @begin{StaticSem}
1191 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0072-1]}
1192 @ChgAdded{Version=[4],Text=[An entity with @i{runtime name text} is a
1193 nonderived enumeration first subtype, a tagged first subtype, or an
1194 exception.@Defn{entity with runtime name text}@Defn2{Term=[runtime name text],Sec=[entity with]}]}
1195
1196 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0072-1]}
1197 @ChgAdded{Version=[4],Type=[Leading],Text=[For an entity with runtime name
1198 text, the following language-defined representation aspect may be specified:]}
1199
1200 @begin{Description}
1201 @ChgRef{Version=[4],Kind=[Added]}
1202 @ChgAdded{Version=[4],Text=[Discard_Names@\The type of aspect Discard_Names
1203 is Boolean. If directly specified, the @nt{aspect_definition} shall be
1204 a static expression. If not specified (including by inheritance), the
1205 aspect is False.@AspectDefn{Discard_Names}]}
1206
1207 @ChgAspectDesc{Version=[4],Kind=[Added],Aspect=[Discard_Names],
1208 Text=[@ChgAdded{Version=[4],Text=[Requests a reduction in storage for names associated
1209 with an entity.]}]}
1210 @end{Description}
1211 @end{StaticSem}
1212
1213 @begin{Syntax}
1214 @begin{SyntaxText}
1215 @Leading@Keepnext@;The form of a @nt{pragma} Discard_Names is as follows:
1216 @end{SyntaxText}
1217
1218 @PragmaSyn`@key{pragma} @prag(Discard_Names)[([On => ] @Syn2[local_name])];'
1219
1220 @begin{SyntaxText}
1221 A @nt{pragma} Discard_Names is allowed only immediately within a
1222 @nt{declarative_part}, immediately within a @nt{package_specification},
1223 or as a configuration pragma.
1224 @PDefn2{Term=[configuration pragma], Sec=(Discard_Names)}
1225 @PDefn2{Term=[pragma, configuration], Sec=(Discard_Names)}
1226 @end{SyntaxText}
1227 @end{Syntax}
1228
1229 @begin{Legality}
1230 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0072-1]}
1231 The @nt{local_name} (if present) shall denote
1232 @Chg{Version=[4],New=[an entity with runtime name text],Old=[a nonderived
1233 enumeration @Redundant[first] subtype,
1234 a tagged @Redundant[first] subtype, or an exception]}.
1235 The pragma @Chg{Version=[4],New=[specifies that the aspect Discard_Names
1236 for],Old=[applies to]} the type or
1237 exception@Chg{Version=[4],New=[ has the value True],Old=[]}.
1238 Without a @nt{local_name}, the pragma @Chg{Version=[4],New=[specifies that],
1239 Old=[applies to]} all
1240 @Chg{Version=[4],New=[],Old=[such ]}entities@Chg{Version=[4],New=[ with
1241 runtime name text],Old=[]}
1242 declared after the pragma, within the same declarative
1243 region@Chg{Version=[4],New=[ have the value True for aspect
1244 Discard_Names],Old=[]}.
1245 Alternatively, the pragma can be used as a configuration pragma.
1246 @Chg{Version=[4],New=[If the configuration pragma Discard_Names applies to a
1247 compilation unit, all entities with runtime name text declared in the
1248 compilation unit have the value True for the aspect Discard_Names.],Old=[If the
1249 pragma applies to a type, then it applies also to all descendants of the type]}.
1250
1251 @begin{Ramification}
1252 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0072-1]}
1253 @ChgAdded{Version=[4],Text=[If the aspect is specified for a type, then
1254 it is inherited by all descendants of the type. The aspect cannot be
1255 specified as False on a derived type (because specifying the aspect is
1256 not allowed on derived enumeration types, and by rule applying to all
1257 aspects for other types (see @RefSecNum{Aspect Specifications})).]}
1258 @end{Ramification}
1259
1260 @end{Legality}
1261
1262 @begin{StaticSem}
1263 @PDefn2{Term=[representation pragma], Sec=(Discard_Names)}
1264 @PDefn2{Term=[pragma, representation], Sec=(Discard_Names)}
1265 If a @nt{local_name} is given, then
1266 a @nt{pragma} Discard_Names is a representation pragma.
1267
1268 @begin{Ramification}
1269 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
1270 @ChgRef{Version=[4],Kind=[Deleted],ARef=[AI12-0072-1]}@ChgNote{Explicit now.}
1271 @ChgDeleted{Version=[4],Text=[@Chg{Version=[3],New=[Representation
1272 pragmas automatically specify aspects of the same name,
1273 so Discard_Names can be used as an @nt{aspect_mark} in an
1274 @nt{aspect_specification} instead of using the pragma on individual
1275 entities.],Old=[]}]}
1276 @end{Ramification}
1277
1278 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01],ARef=[AI95-00400-01]}
1279 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0072-1]}
1280 If the @Chg{Version=[4],New=[aspect Discard_Names is True
1281 for],Old=[pragma applies to]} an enumeration type,
1282 then the semantics of the @Chg{Version=[2],New=[Wide_Wide_Image],Old=[Wide_Image]}
1283 and @Chg{Version=[2],New=[Wide_Wide_Value],Old=[Wide_Value]} attributes
1284 are implementation defined for that type@Redundant[; the
1285 semantics of Image@Chg{Version=[2],New=[, Wide_Image,],Old=[ and]}
1286 Value@Chg{Version=[2],New=[, and Wide_Value],Old=[]} are still defined in
1287 terms of @Chg{Version=[2],New=[Wide_Wide_Image],Old=[Wide_Image]}
1288 and @Chg{Version=[2],New=[Wide_Wide_Value],Old=[Wide_Value]}].
1289 In addition, the semantics of Text_IO.Enumeration_IO are implementation
1290 defined.
1291 If the @Chg{Version=[4],New=[aspect Discard_Names is True
1292 for],Old=[pragma applies to]} a tagged type,
1293 then the semantics of the Tags.@!@Chg{Version=[2],New=[Wide_Wide_@!Expanded_@!Name],
1294 Old=[Expanded_@!Name]} function
1295 are implementation defined for that type@Chg{Version=[2],New=[@Redundant[; the
1296 semantics of Tags.@!Expanded_@!Name and Tags.@!Wide_@!Expanded_@!Name are still
1297 defined in terms of Tags.@!Wide_Wide_@!Expanded_@!Name]], Old=[]}.
1298 If the @Chg{Version=[4],New=[aspect Discard_Names is True
1299 for],Old=[pragma applies to]} an exception,
1300 then the semantics of the Exceptions.@!@Chg{Version=[2],New=[Wide_Wide_@!Exception_@!Name],
1301 Old=[Exception_@!Name]} function
1302 are implementation defined for that exception@Chg{Version=[2],New=[@Redundant[; the
1303 semantics of Exceptions.@!Exception_@!Name and Exceptions.@!Wide_@!Exception_@!Name
1304 are still defined in terms of Exceptions.@!Wide_Wide_@!Exception_@!Name]], Old=[]}.
1305
1306 @ChgImplDef{Version=[4],Kind=[Revised],InitialVersion=[0],
1307 Text=[The semantics of @Chg{Version=[4],New=[some attributes and functions of
1308 an entity for which aspect],Old=[pragma]}
1309 Discard_Names@Chg{Version=[4],New=[ is True],Old=[]}.]}
1310 @begin{Ramification}
1311 The Width attribute is still defined in terms of Image.
1312
1313 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
1314 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0072-1]}
1315 The semantics of S'@Chg{Version=[2],New=[Wide_Wide_Image],Old=[Wide_Image]}
1316 and S'@Chg{Version=[2],New=[Wide_Wide_Value],Old=[Wide_Value]} are
1317 implementation defined for any subtype of an enumeration type
1318 @Chg{Version=[4],New=[for],Old=[to]} which
1319 the @Chg{Version=[4],New=[aspect is True],Old=[pragma applies]}.
1320 (The pragma@Chg{Version=[4],New=[, if used,],Old=[]} actually names
1321 the first subtype, of course.)
1322 @end{Ramification}
1323 @end{StaticSem}
1324
1325 @begin{ImplAdvice}
1326 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0072-1]}
1327 If the @Chg{Version=[4],New=[aspect Discard_Names is True
1328 for],Old=[pragma applies to]} an entity, then the implementation should
1329 reduce the amount of storage used for storing names associated with that
1330 entity.
1331 @ChgImplAdvice{Version=[4],Kind=[Revised],InitialVersion=[2],
1332 Text=[@ChgAdded{Version=[2],
1333 Text=[If @Chg{Version=[4],New=[aspect],Old=[@nt{pragma}]} Discard_Names
1334 @Chg{Version=[4],New=[is True for],Old=[applies to]} an entity, then
1335 the amount of storage used for storing names associated with that entity
1336 should be reduced.]}]}
1337 @begin{Reason}
1338 A typical implementation of the Image attribute for enumeration types is
1339 to store a table containing the names of all the enumeration literals.
1340 @Chg{Version=[4],New=[Aspect],Old=[Pragma]} Discard_Names allows the
1341 implementation to avoid storing such a
1342 table without having to prove that the Image attribute is never used
1343 (which can be difficult in the presence of separate compilation).
1344
1345 We did not specify the semantics of the Image attribute
1346 @Chg{Version=[4],New=[when aspect Discard_Names is True],Old=[in the presence
1347 of this pragma]} because different semantics might be desirable in
1348 different situations.
1349 In some cases, it might make sense to use the Image attribute to print
1350 out a useful value that can be used to identify the entity given
1351 information in compiler-generated listings.
1352 In other cases, it might make sense to get an error at compile time or
1353 at run time.
1354 In cases where memory is plentiful, the simplest implementation makes
1355 sense: ignore the @Chg{Version=[4],New=[aspect],Old=[pragma]}.
1356 Implementations that are capable of avoiding the extra storage in cases
1357 where the Image attribute is never used might also wish to ignore the
1358 @Chg{Version=[4],New=[aspect],Old=[pragma]}.
1359
1360 The same applies to the Tags.Expanded_Name and Exceptions.Exception_Name
1361 functions.
1362 @end{Reason}
1363 @end{ImplAdvice}
1364
1365 @begin{DiffWord95}
1366 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01],ARef=[AI95-00400-01]}
1367 @ChgAdded{Version=[2],Text=[Updated the wording to reflect that the double
1368 wide image and value functions are now the master versions that the others
1369 are defined from.]}
1370 @end{DiffWord95}
1371
1372 @begin{DiffWord2012}
1373 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0072-1]}
1374 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Defined the pragma in terms of
1375 the aspect Discard_Names, and added a missing definition of the meaning of
1376 the configuration pragma. This is not intended to make any semantic change
1377 (Ada 2012 has an aspect Discard_Names defined via blanket rules for
1378 representation pragmas in @RefSecNum{Operational and Representation Aspects}
1379 and @RefSecNum{Aspect Specifications}), just to clarify the meaning.]}
1380 @end{DiffWord2012}
1381
1382
1383 @LabeledClause{Shared Variable Control}
1384
1385 @begin{Intro}
1386 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1],ARef=[AI05-0299-1]}
1387 @Redundant[This @Chg{Version=[3],New=[subclause defines],Old=[clause specifies]}
1388 representation @Chg{Version=[3],New=[aspects],Old=[pragmas]} that control the
1389 use of shared variables.]
1390 @end{Intro}
1391
1392 @begin{NotIso}
1393 @ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 2
1394 through 6 were moved to @RefSec{Obsolescent Features}.>}]}@Comment{This message
1395 should be deleted if the paragraphs are ever renumbered.}
1396 @end{NotIso}
1397
1398 @begin{Syntax}
1399 @begin{SyntaxText}
1400 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
1401 @ChgDeleted{Version=[3],Type=[Leading],Text=[The form for pragmas Atomic,
1402 Volatile, Atomic_Components, and Volatile_Components is as follows:]}
1403 @end{SyntaxText}
1404
1405 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
1406 @DeletedPragmaSyn<Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3],
1407 Text=[@key{pragma} @prag(Atomic)(@Syn2{local_name});]}>
1408
1409 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
1410 @DeletedPragmaSyn<Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3],
1411 Text=[@key{pragma} @prag(Volatile)(@Syn2{local_name});]}>
1412
1413 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
1414 @DeletedPragmaSyn<Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3],
1415 Text=[@key{pragma} @prag(Atomic_Components)(@SynI{array_}@Syn2{local_name});]}>
1416
1417 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
1418 @DeletedPragmaSyn<Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3],
1419 Text=[@key{pragma} @prag(Volatile_Components)(@SynI{array_}@Syn2{local_name});]}>
1420
1421 @end{Syntax}
1422
1423 @Comment{Original: @begin{Intro}, Replaced with below for Ada 2012}
1424 @begin{StaticSem}
1425
1426 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]}
1427 @ChgAdded{Version=[3],Type=[Leading],Text=[For an @nt{object_declaration}, a
1428 @nt{component_declaration}, or a @nt{full_type_declaration}, the following
1429 representation aspects may be specified:]}
1430
1431 @begin{Description}
1432 @ChgRef{Version=[3],Kind=[Added]}
1433 @ChgAdded{Version=[3],Text=[Atomic@\The type of aspect Atomic is
1434 Boolean.@AspectDefn{Atomic}]}
1435
1436 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Atomic],
1437 Text=[@ChgAdded{Version=[3],Text=[Declare that a type, object, or component is
1438 atomic.]}]}
1439
1440 @ChgRef{Version=[3],Kind=[Added]}
1441 @ChgAdded{Version=[3],Text=[Independent@\The type of aspect Independent is
1442 Boolean.@AspectDefn{Independent}]}
1443
1444 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Independent],
1445 Text=[@ChgAdded{Version=[3],Text=[Declare that a type, object, or component
1446 is independently addressable.]}]}
1447
1448 @ChgRef{Version=[3],Kind=[Added]}
1449 @ChgAdded{Version=[3],Text=[Volatile@\The type of aspect Volatile is
1450 Boolean.@AspectDefn{Volatile}]}
1451
1452 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Volatile],
1453 Text=[@ChgAdded{Version=[3],Text=[Declare that a type, object, or component
1454 is volatile.]}]}
1455
1456 @end{Description}
1457
1458 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]}
1459 @ChgAdded{Version=[3],Type=[Leading],Text=[For a @nt{full_type_declaration} of
1460 an array type (including the anonymous type of an @nt{object_declaration}
1461 of an anonymous array object), the following representation aspects may be
1462 specified:]}
1463
1464 @begin{Description}
1465 @ChgRef{Version=[3],Kind=[Added]}
1466 @ChgAdded{Version=[3],Text=[Atomic_Components@\The type of aspect
1467 Atomic_Components is Boolean.@AspectDefn{Atomic_Components}]}
1468
1469 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Atomic_Components],
1470 Text=[@ChgAdded{Version=[3],Text=[Declare that the components of
1471 an array type or object are atomic.]}]}
1472
1473 @ChgRef{Version=[3],Kind=[Added]}
1474 @ChgAdded{Version=[3],Text=[Volatile_Components@\The type of aspect
1475 Volatile_Components is Boolean.@AspectDefn{Volatile_Components}]}
1476
1477 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Volatile_Components],
1478 Text=[@ChgAdded{Version=[3],Text=[Declare that the components of
1479 an array type or object are volatile.]}]}
1480
1481 @end{Description}
1482
1483 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]}
1484 @ChgAdded{Version=[3],Type=[Leading],Text=[For a @nt{full_type_declaration}
1485 (including the anonymous type of an @nt{object_declaration} of an anonymous
1486 array object), the following representation aspect may be specified:]}
1487
1488 @begin{Description}
1489 @ChgRef{Version=[3],Kind=[Added]}
1490 @ChgAdded{Version=[3],Text=[Independent_Components@\The type of aspect
1491 Independent_Components is Boolean.@AspectDefn{Independent_Components}]}
1492
1493 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Independent_Components],
1494 Text=[@ChgAdded{Version=[3],Text=[Declare that the components of an array
1495 or record type, or an array object, are independently addressable.]}]}
1496
1497 @end{Description}
1498
1499 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]}
1500 @ChgAdded{Version=[3],Text=[If any of these aspects are directly
1501 specified, the @nt{aspect_definition} shall be a static expression. If not
1502 specified (including by inheritance), each of these aspects is False.]}
1503
1504 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00272-01]}
1505 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
1506 @Defn{atomic}
1507 An @i{atomic} type is one @Chg{Version=[3],New=[for],Old=[to]} which
1508 @Chg{Version=[3],New=[the aspect],Old=[a pragma]} Atomic
1509 @Chg{Version=[3],New=[is True],Old=[applies]}.
1510 An @i{atomic} object (including a component)
1511 is one @Chg{Version=[3],New=[for],Old=[to]} which
1512 @Chg{Version=[3],New=[the aspect],Old=[a pragma]} Atomic
1513 @Chg{Version=[3],New=[is True],Old=[applies]},
1514 or a component of an array @Chg{Version=[3],New=[for],Old=[to]} which
1515 @Chg{Version=[3],New=[the aspect],Old=[a pragma]} Atomic_Components
1516 @Chg{Version=[3],New=[is True for the associated type],Old=[applies]},
1517 or any object of an atomic type@Chg{Version=[2],
1518 New=[, other than objects obtained by evaluating a slice],Old=[]}.
1519 @begin{Ramification}
1520 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00272-01]}
1521 @ChgAdded{Version=[2],Text=[A slice of an atomic array object is not itself
1522 atomic. That's necessary as executing a read or write of a dynamic number
1523 of components in a single instruction is not possible on many targets.]}
1524 @end{Ramification}
1525
1526 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
1527 @Defn{volatile}
1528 A @i{volatile} type is one @Chg{Version=[3],New=[for],Old=[to]} which
1529 @Chg{Version=[3],New=[the aspect],Old=[a pragma]} Volatile
1530 @Chg{Version=[3],New=[is True],Old=[applies]}.
1531 A @i{volatile} object (including a component)
1532 is one @Chg{Version=[3],New=[for],Old=[to]} which
1533 @Chg{Version=[3],New=[the aspect],Old=[a pragma]} Volatile
1534 @Chg{Version=[3],New=[is True],Old=[applies]},
1535 or a component of an array @Chg{Version=[3],New=[for],Old=[to]} which
1536 @Chg{Version=[3],New=[the aspect],Old=[a pragma]} Volatile_@!Components
1537 @Chg{Version=[3],New=[is True for the associated type],Old=[applies]},
1538 or any object of a volatile type.
1539 In addition, every atomic type or object is also defined to be volatile.
1540 Finally, if an object is volatile, then so
1541 are all of its subcomponents @Redundant[(the same does not apply to atomic)].
1542
1543 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0009-1],ARef=[AI05-0229-1]}
1544 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0001-1]}
1545 @ChgAdded{Version=[3],Text=[When True, the aspects Independent and
1546 Independent_Components @i<specify as independently addressable> the named object
1547 or component(s), or in the case of a type, all objects or components
1548 of that type. All atomic objects @Chg{Version=[4],New=[and aliased
1549 objects ],Old=[]}are considered to be specified as independently
1550 addressable.@Defn{specified as independently addressable}@Defn2{Term=[independently addressable],Sec=[specified]}]}
1551
1552 @begin{Ramification}
1553 @ChgRef{Version=[3],Kind=[AddedNormal]}
1554 @ChgAdded{Version=[3],Text=[If the compiler cannot guarantee that an object
1555 (including a component) for which aspect Independent or aspect
1556 Independent_Components is True is independently addressable from
1557 any other nonoverlapping object, then the aspect specification
1558 must be rejected.]}
1559
1560 @ChgRef{Version=[3],Kind=[AddedNormal]}
1561 @ChgAdded{Version=[3],Text=[Similarly, an atomic object (including atomic
1562 components) is always independently addressable from any other nonoverlapping
1563 object. Any representation item which would prevent this from being true should
1564 be rejected, notwithstanding what this Standard says elsewhere (specifically,
1565 in the Recommended Level of Support).]}
1566 @end{Ramification}
1567
1568 @Comment{Original: @end{Intro}, Replaced with below for Ada 2012}
1569 @end{StaticSem}
1570
1571 @begin{NotIso}
1572 @ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraph 9
1573 was moved to @RefSec{Obsolescent Features}.>}]}@Comment{This message
1574 should be deleted if the paragraphs are ever renumbered.}@ChgNote{We use
1575 this message rather than the "automatic one" to get rid of the resolution
1576 subheader}
1577 @end{NotIso}
1578
1579 @begin{Resolution}
1580 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
1581 @ChgDeleted{Version=[3],Text=[The @nt{local_name} in an Atomic or Volatile
1582 pragma shall resolve to denote either an @nt{object_declaration}, a
1583 noninherited @nt{component_@!declaration}, or a @nt{full_type_@!declaration}.
1584 The @SynI{array_}@nt{local_name} in an Atomic_@!Components or
1585 Volatile_@!Components pragma shall resolve to denote the declaration of an array
1586 type or an array object of an anonymous type.]}
1587 @end{Resolution}
1588
1589 @begin{Legality}
1590
1591 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]}
1592 @ChgAdded{Version=[3],Text=[If aspect Independent_Components is specified for a
1593 @nt{full_type_declaration}, the declaration shall be that of an array or record
1594 type.]}
1595
1596 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
1597 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0001-1]}
1598 @Defn{indivisible}
1599 It is illegal to @Chg{Version=[3],New=[specify],Old=[apply]}
1600 either @Chg{Version=[3],New=[of the aspects],Old=[an]} Atomic or
1601 Atomic_Components @Chg{Version=[3],New=[],Old=[pragma ]}to
1602 @Chg{Version=[3],New=[have the value True for ],Old=[]}an
1603 object or type if the implementation cannot support the indivisible
1604 @Chg{Version=[4],New=[and independent ],Old=[]}reads
1605 and updates required by the @Chg{Version=[3],New=[aspect],Old=[pragma]}
1606 (see below).
1607
1608 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0001-1]}
1609 It is illegal to specify the Size attribute of an atomic object, the
1610 Component_Size attribute for an array type with atomic components, or the layout
1611 attributes of an atomic component, in a way that prevents the implementation
1612 from performing the required indivisible
1613 @Chg{Version=[4],New=[and independent ],Old=[]}reads and updates.
1614
1615 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0142-4],ARef=[AI05-0218-1]}
1616 If an atomic object is passed as a parameter, then
1617 @Chg{Version=[3],New=[],Old=[the type of ]}the formal
1618 parameter shall either @Chg{Version=[3],New=[have an],Old=[be]} atomic
1619 @Chg{Version=[3],New=[type ],Old=[]}or allow pass by
1620 copy@Chg{Version=[3],New=[],Old=[ @Redundant[(that
1621 is, not be a nonatomic by-reference type)]]}. If an atomic object is used
1622 as an actual for a generic formal object of mode @key{in out}, then the
1623 type of the generic formal object shall be atomic. If the @nt<prefix> of
1624 an @nt<attribute_reference> for an Access attribute denotes an atomic
1625 object @Redundant[(including a component)], then the designated type of
1626 the resulting access type shall be atomic. If an atomic type is used as
1627 an actual for a generic formal derived type, then the ancestor of the
1628 formal type shall be atomic@Chg{Version=[3],New=[],Old=[ or allow pass by copy]}.
1629 Corresponding rules apply to volatile objects and types.
1630
1631 @begin{Ramification}
1632 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4]}
1633 @ChgAdded{Version=[3],Text=[A formal parameter allows pass by copy
1634 if it is not @key[aliased] and it is of a type that allows pass by copy (that
1635 is, is not a by-reference type).]}
1636 @end{Ramification}
1637
1638 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0218-1]}
1639 @ChgAdded{Version=[3],Text=[If a volatile type is used as an actual for a
1640 generic formal array type, then the element type of the formal type shall be
1641 volatile.]}
1642
1643 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
1644 If @Chg{Version=[3],New=[an aspect],Old=[a pragma]} Volatile,
1645 Volatile_Components, Atomic, or Atomic_Components
1646 @Chg{Version=[3],New=[is directly specified to have the value
1647 True for],Old=[applies to]} a stand-alone constant object, then
1648 @Chg{Version=[3],New=[the aspect],Old=[a pragma]} Import shall
1649 also @Chg{Version=[3],New=[be specified as True for],Old=[apply to]} it.
1650 @begin{Ramification}
1651 Hence, no initialization expression is allowed for such a constant. Note
1652 that a constant that is atomic or volatile because of its type is allowed.
1653 @end{Ramification}
1654 @begin{Reason}
1655 Stand-alone constants that are explicitly specified as Atomic or Volatile
1656 only make sense if they are being manipulated outside the Ada program.
1657 From the Ada perspective the object is read-only. Nevertheless, if
1658 imported and atomic or volatile, the implementation should presume it
1659 might be altered externally.
1660 For an imported stand-alone constant that is not atomic or
1661 volatile, the implementation can assume that it will not be
1662 altered.
1663 @end{Reason}
1664 @begin{Honest}
1665 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0218-1]}
1666 @ChgAdded{Version=[3],Text=[Volatile_Components and Atomic_Components actually
1667 are aspects of the anonymous array type; this rule only applies when the
1668 aspect is specified directly on the constant object and not when the (named)
1669 array type has the aspect.]}
1670 @end{Honest}
1671
1672 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0009-1],ARef=[AI05-0229-1]}
1673 @ChgAdded{Version=[3],Text=[It is illegal to specify the aspect Independent or
1674 Independent_Components as True for a component, object or type if the
1675 implementation cannot provide the independent addressability required by the
1676 aspect (see @RefSecNum{Shared Variables}).]}
1677
1678 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0009-1],ARef=[AI05-0229-1]}
1679 @ChgAdded{Version=[3],Text=[It is illegal to specify a representation aspect for
1680 a component, object or type for which the aspect Independent or
1681 Independent_Components is True, in a way that prevents the implementation from
1682 providing the independent addressability required by the aspect.]}
1683
1684 @end{Legality}
1685
1686 @begin{NotIso}
1687 @ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraph 14
1688 was moved to @RefSec{Obsolescent Features}.>}]}@Comment{This message
1689 should be deleted if the paragraphs are ever renumbered.}@ChgNote{We use
1690 this message rather than the "automatic one" to get rid of the resolution
1691 subheader}
1692 @end{NotIso}
1693
1694 @begin{StaticSem}
1695 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
1696 @ChgDeleted{Version=[3],Text=[@PDefn2{Term=[representation pragma], Sec=(Atomic)}
1697 @PDefn2{Term=[pragma, representation], Sec=(Atomic)}
1698 @PDefn2{Term=[representation pragma], Sec=(Volatile)}
1699 @PDefn2{Term=[pragma, representation], Sec=(Volatile)}
1700 @PDefn2{Term=[representation pragma], Sec=(Atomic_Components)}
1701 @PDefn2{Term=[pragma, representation], Sec=(Atomic_Components)}
1702 @PDefn2{Term=[representation pragma], Sec=(Volatile_Components)}
1703 @PDefn2{Term=[pragma, representation], Sec=(Volatile_Components)}
1704 These @nt{pragma}s are representation pragmas
1705 (see @RefSecNum{Operational and Representation Aspects}).]}
1706 @end{StaticSem}
1707
1708 @begin{RunTime}
1709
1710 For an atomic object (including an atomic component) all reads and
1711 updates of the object as a whole are indivisible.
1712
1713 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0117-1],ARef=[AI05-0275-1]}
1714 @Chg{Version=[3],New=[All tasks of the program (on all processors) that
1715 read or update volatile variables see the same order of
1716 updates to the variables. A use of an atomic variable or other mechanism may be
1717 necessary to avoid erroneous execution and to ensure that access to
1718 nonatomic volatile variables is sequential (see @RefSecNum{Shared Variables}).],
1719 Old=[For a volatile object all reads and updates of the object as a whole are
1720 performed directly to memory.]}
1721
1722 @begin{ImplNote}
1723 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0117-1],ARef=[AI05-0275-1]}
1724 @Chg{Version=[3],New=[To ensure this, on a multiprocessor, any read or
1725 update of an atomic object may require the use of an appropriate memory
1726 barrier.],Old=[This precludes any use of register temporaries,
1727 caches, and other similar optimizations for that object.]}
1728 @end{ImplNote}
1729
1730 @begin{Discussion}
1731 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0275-1]}
1732 @ChgAdded{Version=[3],Text=[From @RefSecNum{Shared Variables} it follows that
1733 (in non-erroneous programs) accesses to variables, including those shared by
1734 multiple tasks, are always sequential. This guarantees that no task will ever
1735 see partial updates of any variable. For volatile variables (including atomic
1736 variables), the above rule additionally specifies that all tasks see the same
1737 order of updates.]}
1738
1739 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0275-1]}
1740 @ChgAdded{Version=[3],Text=[If for a shared variable @i<X>, a read of @i<X>
1741 occurs sequentially after an update of @i<X>, then the read will return the
1742 updated value if @i<X> is volatile or atomic, but may or or may not return the
1743 updated value if @i<X> is nonvolatile. For nonvolatile accesses, a signaling
1744 action is needed in order to share the updated value.]}
1745
1746 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0275-1]}
1747 @ChgAdded{Version=[3],Text=[Because accesses to the same atomic variable by
1748 different tasks establish a sequential order between the actions of those tasks,
1749 implementations may be required to emit memory barriers around such updates or
1750 use atomic instructions that imply such barriers.]}
1751 @end{Discussion}
1752
1753 @Defn2{Term=[sequential], Sec=(actions)}
1754 Two actions are sequential (see @RefSecNum{Shared Variables}) if each
1755 is the read or update of the same atomic object.
1756
1757 @PDefn2{Term=[by-reference type], Sec=(atomic or volatile)}
1758 If a type is atomic or volatile and it is not a by-copy type, then the type
1759 is defined to be a by-reference type. If any subcomponent of a type is
1760 atomic or volatile, then the type is defined to be a by-reference type.
1761
1762 If an actual parameter is atomic or volatile, and the corresponding
1763 formal parameter is not, then the parameter is passed by copy.
1764 @begin{ImplNote}
1765 Note that in the case where such a parameter is normally passed by
1766 reference, a copy of the actual will have to be produced at the call-site,
1767 and a pointer to the copy passed to the formal parameter. If the actual
1768 is atomic, any copying has to use indivisible read on the way in, and
1769 indivisible write on the way out.
1770 @end{ImplNote}
1771 @begin{Reason}
1772 It has to be known at compile time whether an atomic or a volatile parameter
1773 is to be passed by copy or by reference. For some types, it is unspecified
1774 whether parameters are passed by copy or by reference. The above rules
1775 further specify the parameter passing rules involving atomic and volatile
1776 types and objects.
1777 @end{Reason}
1778
1779 @end{RunTime}
1780
1781 @begin{ImplReq}
1782
1783 @PDefn2{Term=[external effect], Sec=(volatile/atomic objects)}
1784 The external effect of a program
1785 (see @RefSecNum(Conformity of an Implementation with the Standard))
1786 is defined to include each read and update
1787 of a volatile or atomic object. The implementation shall not
1788 generate any memory reads or updates of atomic or volatile
1789 objects other than those specified by the program.
1790 @begin{Discussion}
1791 The presumption is that volatile or atomic objects might reside in an
1792 @lquotes@;active@rquotes@; part of the address space where each read has a
1793 potential side effect, and at the very least might deliver a different value.
1794
1795 @Leading@;The rule above and the definition of external effect are intended to
1796 prevent (at least) the following incorrect optimizations, where V is
1797 a volatile variable:
1798 @begin{itemize}
1799 X:= V; Y:=V; cannot be allowed to be translated as Y:=V; X:=V;
1800
1801 Deleting redundant loads: X:= V; X:= V; shall read the value of V from
1802 memory twice.
1803
1804 Deleting redundant stores: V:= X; V:= X; shall write into V twice.
1805
1806 Extra stores: V:= X+Y; should not translate to something like V:= X; V:= V+Y;
1807
1808 Extra loads: X:= V; Y:= X+Z; X:=X+B; should not translate to something like
1809 Y:= V+Z; X:= V+B;
1810
1811 Reordering of loads from volatile variables: X:= V1; Y:= V2; (whether or not
1812 V1 = V2) should not translate to Y:= V2; X:= V1;
1813
1814 Reordering of stores to volatile variables: V1:= X; V2:= X; should not
1815 translate to V2:=X; V1:= X;
1816 @end{itemize}
1817 @end{Discussion}
1818
1819 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
1820 @ChgRef{Version=[4],Kind=[Deleted],ARef=[AI12-0001-1]}
1821 @ChgDeleted{Version=[4],Text=[If @Chg{Version=[3],New=[the],Old=[a pragma]} Pack
1822 @Chg{Version=[3],New=[aspect is True for],Old=[applies to]} a type any of whose
1823 subcomponents are atomic,
1824 the implementation shall not pack the atomic subcomponents more tightly
1825 than that for which it can support indivisible reads and updates.]}
1826 @begin{ImplNote}
1827 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0009-1]}
1828 @ChgRef{Version=[4],Kind=[Deleted],ARef=[AI12-0001-1]}
1829 @ChgDeleted{Version=[4],Text=[@Chg{Version=[3],New=[Usually, specifying aspect Pack for such a type
1830 will be illegal as the Recommended Level of Support cannot be achieved;
1831 otherwise, a],Old=[A]} warning might be appropriate if
1832 no packing whatsoever can be achieved.]}
1833 @end{ImplNote}
1834 @end{ImplReq}
1835
1836 @begin{ImplAdvice}
1837 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00259-01]}
1838 @ChgAdded{Version=[2],Text=[A load or store of a volatile object whose size is
1839 a multiple of System.Storage_Unit and whose alignment is nonzero, should be
1840 implemented by accessing exactly the bits of the object and no others.]}
1841 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
1842 Text=[A load or store of a volatile object whose size is
1843 a multiple of System.Storage_Unit and whose alignment is nonzero, should be
1844 implemented by accessing exactly the bits of the object and no others.]}]}
1845
1846 @begin{Reason}
1847 @ChgRef{Version=[2],Kind=[AddedNormal]}
1848 @ChgAdded{Version=[2],Text=[Since any object can be a volatile object,
1849 including packed array components and bit-mapped record components, we
1850 require the above only when it is reasonable to assume that the machine
1851 can avoid accessing bits outside of the object.]}
1852 @end{Reason}
1853
1854 @begin{Ramification}
1855 @ChgRef{Version=[2],Kind=[AddedNormal]}
1856 @ChgAdded{Version=[2],Text=[This implies that the load or store of a
1857 volatile object that meets the above requirement should not be combined
1858 with that of any other object, nor should it access any bits not
1859 belonging to any other object. This means that the suitability of the
1860 implementation for memory-mapped I/O can be determined from its
1861 documentation, as any cases where the implementation does not follow
1862 @ImplAdviceTitle must be documented.]}
1863 @end{Ramification}
1864
1865 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00259-01]}
1866 @ChgAdded{Version=[2],Text=[A load or store of an atomic object should, where
1867 possible, be implemented by a single load or store instruction.]}
1868 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
1869 Text=[A load or store of an atomic object should be implemented by a single
1870 load or store instruction.]}]}
1871
1872 @end{ImplAdvice}
1873
1874 @begin{Notes}
1875
1876 An imported volatile or atomic constant behaves as a constant (i.e.
1877 read-only) with respect to other parts of the Ada program, but can
1878 still be modified by an @lquotes@;external source.@rquotes@;
1879
1880 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0001-1]}
1881 @ChgAdded{Version=[4],Text=[Specifying the Pack aspect cannot override the
1882 effect of specifying an Atomic or Atomic_Components aspect.]}
1883
1884 @end{Notes}
1885
1886 @begin{Incompatible83}
1887 @Defn{incompatibilities with Ada 83}
1888 Pragma Atomic replaces Ada 83's pragma Shared.
1889 The name @lquotes@;Shared@rquotes@; was confusing,
1890 because the pragma was not used to mark variables as shared.
1891 @end{Incompatible83}
1892
1893 @begin{DiffWord95}
1894 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00259-01]}
1895 @ChgAdded{Version=[2],Text=[Added @ImplAdviceTitle to clarify the meaning
1896 of Atomic and Volatile in machine terms. The documentation that this
1897 advice applies will make the use of Ada implementations more predictable
1898 for low-level (such as device register) programming.]}
1899
1900 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00272-01]}
1901 @ChgAdded{Version=[2],Text=[Added wording to clarify that a slice of an
1902 object of an atomic type is not atomic, just like a component of an atomic
1903 type is not (necessarily) atomic.]}
1904 @end{Diffword95}
1905
1906 @begin{Incompatible2005}
1907 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0218-1]}
1908 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
1909 Plugged a hole involving volatile components of formal types when the formal
1910 type's component has a nonvolatile type. This was done by making certain
1911 actual types illegal for formal derived and formal array types; these types
1912 were allowed for Ada 95 and Ada 2005.]}
1913 @end{Incompatible2005}
1914
1915 @begin{Extend2005}
1916 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0009-1],ARef=[AI05-0229-1]}
1917 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
1918 Aspects Independent and Independent_Components are new; they eliminate
1919 ambiguity about independent addressability.]}
1920
1921 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
1922 @ChgAdded{Version=[3],Text=[Aspects Atomic, Atomic_Components, Volatile,
1923 and Volatile_Components are
1924 new; @nt{pragma}s Atomic, Atomic_Components, Volatile, and
1925 Volatile_Components are now obsolescent.]}
1926 @end{Extend2005}
1927
1928 @begin{DiffWord2005}
1929 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0117-1],ARef=[AI05-0275-1]}
1930 @ChgAdded{Version=[3],Text=[Revised the definition of volatile to
1931 eliminate overspecification and simply focus on the root requirement (that
1932 all tasks see the same view of volatile objects). This is not an
1933 inconsistency; "memory" arguably includes on-chip caches so long as those are
1934 kept consistent. Moreover, it is difficult to imagine a program that could tell
1935 the difference.]}
1936
1937 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4]}
1938 @ChgAdded{Version=[3],Text=[Added wording to take explicitly aliased
1939 parameters (see @RefSecNum{Subprogram Declarations}) into
1940 account when determining the legality of parameter passing of volatile and
1941 atomic objects.]}
1942 @end{DiffWord2005}
1943
1944 @begin{DiffWord2012}
1945 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0001-1]}
1946 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified that aliased objects
1947 are considered to be specified as independently addressable, and also
1948 eliminated an unnecessary rule.]}
1949 @end{DiffWord2012}
1950
1951
1952 @LabeledRevisedClause{Version=[2],New=[Task Information],
1953 Old=[Task Identification and Attributes]}
1954
1955 @begin{Intro}
1956 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00266-02]}
1957 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
1958 @Redundant[This @Chg{Version=[3],New=[subclause],Old=[clause]}
1959 describes operations and attributes that can be
1960 used to obtain the identity of a task. In addition,
1961 a package that associates user-defined information with a task is
1962 defined.@Chg{Version=[2],New=[ Finally, a package that associates
1963 termination procedures with a task or set of tasks is defined.],Old=[]}]
1964 @end{Intro}
1965
1966 @begin{DiffWord95}
1967 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
1968 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
1969 @ChgAdded{Version=[2],Text=[The title and text here were updated to reflect
1970 the addition of task termination procedures to this @Chg{Version=[3],New=[subclause],Old=[clause]}.]}
1971 @end{DiffWord95}
1972
1973 @LabeledSubClause{The Package Task_Identification}
1974
1975 @begin{StaticSem}
1976 @Leading@Keepnext@;The following language-defined library package exists:
1977 @begin{example}
1978 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00362-01]}
1979 @key[package] Ada.Task_Identification @key[is]@ChildUnit{Parent=[Ada],Child=[Task_Identification]}@Chg{Version=[2],New=[
1980 @key[pragma] Preelaborate(Task_Identification);],Old=[]}
1981 @key[type] @AdaTypeDefn{Task_Id} @key[is] @key{private};@Chg{Version=[2],New=[
1982 @key[pragma] Preelaborable_Initialization (Task_Id);],Old=[]}
1983 @AdaSubDefn{Null_Task_Id} : @key{constant} Task_Id;
1984 @key{function} "=" (Left, Right : Task_Id) @key{return} Boolean;
1985
1986 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0070],ARef=[AI95-00101-01]}
1987 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0189-1]}
1988 @key{function} @AdaSubDefn{Image} (T : Task_Id) @key{return} String;
1989 @key[function] @AdaSubDefn{Current_Task} @key[return] Task_Id;@Chg{Version=[3],New=[
1990 @key[function] @AdaSubDefn{Environment_Task} @key[return] Task_Id;],Old=[]}
1991 @Key[procedure] @AdaSubDefn{Abort_Task} (T : @key[in] @Chg{New=[],Old=[@key[out] ]}Task_Id);
1992
1993 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0189-1]}
1994 @key[function] @AdaSubDefn{Is_Terminated} (T : Task_Id) @key{return} Boolean;
1995 @key[function] @AdaSubDefn{Is_Callable} (T : Task_Id) @key{return} Boolean;@Chg{Version=[3],New=[
1996 @key[function] @AdaSubDefn{Activation_Is_Complete} (T : Task_Id) @key{return} Boolean;],Old=[]}
1997 @key[private]
1998 ... -- @RI{not specified by the language}
1999 @key[end] Ada.Task_Identification;
2000 @end{example}
2001 @end{StaticSem}
2002
2003 @begin{RunTime}
2004
2005 A value of the type Task_Id identifies an existent task. The constant
2006 Null_Task_Id does not identify any task. Each object of the type Task_Id
2007 is default initialized to the value of Null_Task_Id.
2008
2009 The function "=" returns True if and only if Left and Right identify the same
2010 task or both have the value Null_Task_Id.
2011
2012 The function Image returns an implementation-defined string that identifies
2013 T. If T equals Null_Task_Id, Image returns an empty string.
2014 @ImplDef{The result of the Task_Identification.Image attribute.}
2015
2016 The function Current_Task returns a value that identifies the calling task.
2017
2018 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0189-1]}
2019 @ChgAdded{Version=[3],Text=[The function Environment_Task returns a value that
2020 identifies the environment task.]}
2021
2022 The effect of Abort_Task is the same as the @nt{abort_statement} for the
2023 task identified by T. @Redundant[In addition, if T identifies the
2024 environment task, the entire partition is aborted, See @RefSecNum{Partitions}.]
2025
2026 The functions Is_Terminated and Is_Callable return the value of the
2027 corresponding attribute of the task identified by T.
2028 @begin{Ramification}
2029 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0115],ARef=[AI95-00206-01]}
2030 @ChgAdded{Version=[1],Text=[These routines can be called with an argument
2031 identifying the environment task. Is_Terminated will always be False for such a
2032 call, but Is_Callable (usually True) could be False if the environment task is
2033 waiting for the termination of dependent tasks. Thus, a dependent task can use
2034 Is_Callable to determine if the main subprogram has completed.]}
2035 @end{Ramification}
2036
2037 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0189-1]}
2038 @ChgAdded{Version=[3],Text=[The function Activation_Is_Complete returns True if the
2039 task identified by T has completed its activation (whether successfully or not).
2040 It returns False otherwise. If T identifies the environment task,
2041 Activation_Is_Complete returns True after the elaboration of the
2042 @nt{library_item}s of the partition has completed.]}
2043
2044 @Leading@;For @PrefixType{a @nt<prefix> T that is of a task type
2045 @Redundant[(after any implicit dereference)]},
2046 the following attribute is defined:
2047 @begin{Description}
2048
2049 @Attribute{Prefix=<T>, AttrName=<Identity>,
2050 Text=[Yields a value of the type Task_Id that identifies
2051 the task denoted by T.]}
2052
2053 @end{Description}
2054 @EndPrefixType{}
2055
2056 @Leading@;For @PrefixType{a @nt<prefix> E that denotes an
2057 @nt<entry_declaration>},
2058 the following attribute is defined:
2059 @begin{Description}
2060 @ChgAttribute{Version=[3],Kind=[Revised],ChginAnnex=[T],
2061 Leading=<F>, Prefix=<E>, AttrName=<Caller>, ARef=[AI05-0262-1],
2062 InitialVersion=[0], Text=[Yields a value of the type Task_Id that
2063 identifies the task whose call is now being serviced. Use of this
2064 attribute is allowed only inside an
2065 @Chg{Version=[3],New=[],Old=[@nt{entry_body}
2066 or ]}@nt{accept_statement}@Chg{Version=[3],New=[,
2067 or @nt{entry_body} after the
2068 @nt{entry_barrier}, ],Old=[]}corresponding
2069 to the @nt{entry_declaration} denoted by E.]}
2070 @end{Description}
2071 @EndPrefixType{}
2072
2073 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
2074 Program_Error is raised if a value of Null_Task_Id is passed
2075 as a parameter to Abort_Task, Is_Terminated, and Is_Callable.
2076
2077 @PDefn2{Term=[potentially blocking operation],Sec=(Abort_Task)}
2078 @PDefn2{Term=[blocking, potentially],Sec=(Abort_Task)}
2079 Abort_Task is a potentially blocking operation
2080 (see @RefSecNum{Protected Subprograms and Protected Actions}).
2081 @end{RunTime}
2082
2083 @begin{Bounded}
2084 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00237-01]}
2085 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0004-1]}
2086 @PDefn2{Term=(bounded error),Sec=(cause)}
2087 It is a bounded error to call the Current_Task function from
2088 an @Chg{Version=[3],New=[@nt{entry_body}],Old=[entry body]}@Chg{Version=[2],New=[,],Old=[ or an]}
2089 interrupt handler@Chg{Version=[2],New=[, or finalization of a task attribute],Old=[]}.
2090 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
2091 Program_Error is raised, or an implementation-defined value of the type
2092 Task_Id is returned.
2093 @ChgImplDef{Version=[2],Kind=[Revised],InitialVersion=[0],
2094 Text=[The value of Current_Task when in
2095 a protected entry@Chg{Version=[2],New=[,],Old=[ or]} interrupt handler@Chg{Version=[2],
2096 New=[, or finalization of a task attribute],Old=[]}.]}
2097 @begin{ImplNote}
2098 This value could be Null_Task_Id, or the ID of some user task, or that of
2099 an internal task created by the implementation.
2100 @end{ImplNote}
2101 @begin{Ramification}
2102 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00237-01]}@Comment{This really should reference AI05-0004, but we don't have that yet. And that hasn't been approved, either}
2103 @ChgAdded{Version=[2],Text=[An entry barrier is syntactically part of an
2104 @nt{entry_body}, so a call to Current_Task from an entry barrier is also
2105 covered by this rule.]}
2106 @end{Ramification}
2107
2108 @end{Bounded}
2109
2110 @begin{Erron}
2111 @PDefn2{Term=(erroneous execution),Sec=(cause)}
2112 If a value of Task_Id is passed as a parameter to any of the operations
2113 declared in this package (or any language-defined child of this
2114 package), and the corresponding task object no longer exists,
2115 the execution of the program is erroneous.
2116 @end{Erron}
2117
2118 @begin{DocReq}
2119
2120 The implementation shall document the effect of calling Current_Task
2121 from an entry body or interrupt handler.
2122 @ChgImplDef{Version=[2],Kind=[Deleted],InitialVersion=[0],
2123 Text=[@ChgDeleted{Version=[2],
2124 Text=[The effect of calling Current_Task from an
2125 entry body or interrupt handler.]}]}
2126 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
2127 Text=[The effect of calling Current_Task from an
2128 entry body or interrupt handler.]}]}
2129 @end{DocReq}
2130
2131 @begin{Notes}
2132
2133 This package is intended for use in writing user-defined task scheduling
2134 packages and constructing server tasks. Current_Task can be used in
2135 conjunction with other operations requiring a task as an argument such
2136 as Set_Priority (see @RefSecNum{Dynamic Priorities}).
2137
2138 The function Current_Task and the attribute Caller can return a
2139 Task_Id value that identifies the environment task.
2140
2141 @end{Notes}
2142
2143 @begin{Extend95}
2144 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00362-01]}
2145 @ChgAdded{Version=[2],Text=[Task_Identification is now preelaborated,
2146 so it can be used in preelaborated units.]}
2147 @end{Extend95}
2148
2149 @begin{DiffWord95}
2150 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0070],ARef=[AI95-00101-01]}
2151 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Corrected the mode of the
2152 parameter to Abort_Task to @key{in}.]}
2153
2154 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00237-01]}
2155 @ChgAdded{Version=[2],Text=[Corrected the wording to include finalization
2156 of a task attribute in the bounded error case; we don't want to specify
2157 which task does these operations.]}
2158 @end{Diffword95}
2159
2160 @begin{Incompatible2005}
2161 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0189-1]}
2162 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}
2163 Functions Environment_Task and Activation_Is_Complete are added to
2164 Task_Identification. If Task_Identification is referenced in a @nt{use_clause}, and an
2165 entity @i<E> with a @nt{defining_identifier} of Environment_Task or
2166 Activation_Is_Complete is defined in a package that is also referenced in a
2167 @nt{use_clause}, the entity @i<E> may no longer be use-visible, resulting in
2168 errors. This should be rare and is easily fixed if it does occur.]}
2169 @end{Incompatible2005}
2170
2171
2172 @LabeledSubClause{The Package Task_Attributes}
2173
2174 @begin{StaticSem}
2175 @Leading@Keepnext@;The following language-defined generic library package exists:
2176 @begin{example}
2177 @key{with} Ada.Task_Identification; @key{use} Ada.Task_Identification;
2178 @key{generic}
2179 @key{type} Attribute @key{is} @key{private};
2180 Initial_Value : @key[in] Attribute;
2181 @key{package} Ada.Task_Attributes @key{is}@ChildUnit{Parent=[Ada],Child=[Task_Attributes]}
2182
2183 @key{type} @AdaTypeDefn{Attribute_Handle} @key{is} @key{access} @key{all} Attribute;
2184
2185 @key{function} @AdaSubDefn{Value}(T : Task_Id := Current_Task)
2186 @key{return} Attribute;
2187
2188 @key{function} @AdaSubDefn{Reference}(T : Task_Id := Current_Task)
2189 @key{return} Attribute_Handle;
2190
2191 @key{procedure} @AdaSubDefn{Set_Value}(Val : @key[in] Attribute;
2192 T : @key[in] Task_Id := Current_Task);
2193 @key{procedure} @AdaSubDefn{Reinitialize}(T : @key[in] Task_Id := Current_Task);
2194
2195 @key{end} Ada.Task_Attributes;
2196 @end{example}
2197
2198 @end{StaticSem}
2199
2200 @begin{RunTime}
2201
2202 When an instance of Task_Attributes is elaborated in
2203 a given active partition, an object of the
2204 actual type corresponding to the formal type Attribute
2205 is implicitly created for each task (of that partition)
2206 that exists and is not yet terminated.
2207 This object acts as a user-defined attribute of the task.
2208 A task created previously
2209 in the partition and not yet terminated has this attribute
2210 from that point on. Each task subsequently created in the partition
2211 will have this attribute when created. In all these cases, the initial value
2212 of the given attribute is Initial_Value.
2213
2214 The Value operation returns the value of the corresponding attribute of T.
2215
2216 The Reference operation returns an access value that designates the
2217 corresponding attribute of T.
2218
2219 The Set_Value operation performs any finalization on the old value of the
2220 attribute of T and assigns Val to that attribute
2221 (see @RefSecNum{Assignment Statements} and
2222 @RefSecNum{Assignment and Finalization}).
2223
2224 The effect of the Reinitialize operation is the same as Set_Value where
2225 the Val parameter is replaced with Initial_Value.
2226 @begin{ImplNote}
2227 In most cases, the attribute memory can be reclaimed at this point.
2228 @end{ImplNote}
2229
2230 @Defn2{Term=[Tasking_Error],Sec=(raised by failure of run-time check)}
2231 For all the operations declared in this package, Tasking_Error is raised
2232 if the task identified by T is terminated.
2233 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
2234 Program_Error is raised if the value of T is Null_Task_Id.
2235
2236 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00237-01]}
2237 @ChgAdded{Version=[2],Text=[After a task has terminated, all of its attributes
2238 are finalized, unless they have been finalized earlier. When the master of an
2239 instantiation of Ada.Task_Attributes is finalized, the corresponding attribute
2240 of each task is finalized, unless it has been finalized earlier.]}
2241 @begin{Reason}
2242 @ChgRef{Version=[2],Kind=[AddedNormal]}
2243 @ChgAdded{Version=[2],Text=[This is necessary so that a task attribute does
2244 not outlive its type. For instance, that's possible if the instantiation is
2245 nested, and the attribute is on a library-level task.]}
2246 @end{Reason}
2247 @begin{Ramification}
2248 @ChgRef{Version=[2],Kind=[AddedNormal]}
2249 @ChgAdded{Version=[2],Text=[The task owning an attribute cannot, in general,
2250 finalize that attribute. That's because the attributes are finalized @i<after>
2251 the task is terminated; moreover, a task may have attributes as soon as it is
2252 created; the task may never even have been activated.]}
2253 @end{Ramification}
2254 @end{RunTime}
2255
2256 @begin{Bounded}
2257 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0071],ARef=[AI95-00165-01]}
2258 @ChgAdded{Version=[1],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
2259 If the package Ada.Task_Attributes is instantiated with a controlled type and
2260 the controlled type has user-defined Adjust or Finalize operations that in
2261 turn access task attributes by any of the above operations, then a call of
2262 Set_Value of the instantiated package constitutes a bounded error. The call
2263 may perform as expected or may result in forever blocking the calling task and
2264 subsequently some or all tasks of the partition.]}
2265 @end{Bounded}
2266
2267 @begin{Erron}
2268 @PDefn2{Term=(erroneous execution),Sec=(cause)}
2269 It is erroneous to dereference the access value returned by a given
2270 call on Reference after a subsequent call on Reinitialize for
2271 the same task attribute, or after the associated task terminates.
2272 @begin{Reason}
2273 This allows the storage to be reclaimed for the object
2274 associated with an attribute upon Reinitialize or task termination.
2275 @end{Reason}
2276
2277 @PDefn2{Term=(erroneous execution),Sec=(cause)}
2278 If a value of Task_Id is passed as a parameter to any of the operations
2279 declared in this package and the corresponding task object no longer exists,
2280 the execution of the program is erroneous.
2281
2282 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0071],ARef=[AI95-00165-01]}
2283 @ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00237-01]}
2284 @ChgAdded{Version=[1],Text=[@PDefn2{Term=(erroneous execution),Sec=(cause)}
2285 @Chg{Version=[2],New=[An access],Old=[Accesses]} to @Chg{Version=[2],New=[a ],Old=[]}task
2286 @Chg{Version=[2],New=[attribute],Old=[attributes]} via a value of type
2287 Attribute_Handle @Chg{Version=[2],New=[is],Old=[are]}
2288 erroneous if executed concurrently with @Chg{Version=[2],New=[another such access],
2289 Old=[each other]} or @Chg{Version=[2],New=[a call],Old=[with calls]} of any of the
2290 operations declared in package Task_Attributes.@Chg{Version=[2],New=[ An access
2291 to a task attribute is erroneous if executed
2292 concurrently with or after the finalization of the task attribute.],Old=[]}]}
2293 @begin{Reason}
2294 @ChgRef{Version=[1],Kind=[Added]}
2295 @ChgAdded{Version=[1],Text=[There is no requirement of atomicity on accesses
2296 via a value of type Attribute_Handle.]}
2297 @end{Reason}
2298 @begin{Ramification}
2299 @ChgRef{Version=[2],Kind=[Added]}
2300 @ChgAdded{Version=[2],Text=[A task attribute can only be accessed after
2301 finalization through a value of type Attribute_Handle. Operations in
2302 package Task_Attributes cannot be used to access a task attribute after
2303 finalization, because either the master of the instance has been or is in the
2304 process of being left (in which case the instance is out of scope and thus
2305 cannot be called), or the associated task is already terminated (in which
2306 case Tasking_Error is raised for any attempt to call a task attribute
2307 operation).]}
2308 @end{Ramification}
2309 @end{Erron}
2310
2311 @begin{ImplReq}
2312 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0071],ARef=[AI95-00165-01]}
2313 @Chg{New=[For a given attribute of a given task, the],Old=[The]} implementation
2314 shall perform @Chg{New=[the operations declared in this package],
2315 Old=[each of the above operations for a given attribute of a given task]}
2316 atomically with respect to any @Chg{New=[of these operations of],
2317 Old=[other of the above operations for]} the same attribute of the same task.
2318 @Chg{New=[The granularity of any locking mechanism necessary to achieve such
2319 atomicity is implementation defined.],Old=[]}
2320 @ChgImplDef{Version=[1],Kind=[Added],Text=[@Chg{New=[Granularity of
2321 locking for Task_Attributes.],Old=[]}]}
2322
2323 @begin{Ramification}
2324 Hence, other than by dereferencing an access value returned by
2325 Reference, an attribute of a given task can be safely read and updated
2326 concurrently by multiple tasks.
2327 @end{Ramification}
2328
2329 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00237-01]}
2330 @Chg{Version=[2],New=[After],Old=[When a]} task
2331 @Chg{Version=[2],New=[attributes are finalized],Old=[terminates]},
2332 the implementation shall @Chg{Version=[2],New=[],Old=[finalize
2333 all attributes of the task, and ]}reclaim any
2334 @Chg{Version=[2],New=[],Old=[other ]}storage associated with the attributes.
2335 @end{ImplReq}
2336
2337 @begin{DocReq}
2338
2339 The implementation shall document the limit on the number of attributes
2340 per task, if any, and the limit on the total storage for attribute values
2341 per task, if such a limit exists.
2342
2343 In addition, if these limits can be configured, the implementation shall
2344 document how to configure them.
2345 @ChgImplDef{Version=[2],Kind=[Deleted],InitialVersion=[0],
2346 Text=[@ChgDeleted{Version=[2],
2347 Text=[@Chg{New=[Limits on the number and size of task attributes, and how to configure them.],
2348 Old=[Implementation-defined aspects of Task_Attributes.]}]}]}
2349 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
2350 Text=[For package Task_Attributes, limits on the number and size of task
2351 attributes, and how to configure any limits.]}]}
2352 @end{DocReq}
2353
2354 @begin{Metrics}
2355
2356 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
2357 The implementation shall document the following metrics: A task calling the
2358 following subprograms shall execute @Chg{Version=[2],New=[at],Old=[in]} a
2359 sufficiently high priority as to not
2360 be preempted during the measurement period. This period shall start just
2361 before issuing the call and end just after the call completes. If the
2362 attributes of task T are accessed by the measurement tests, no other task
2363 shall access attributes of that task during the measurement period.
2364 For all measurements described here, the Attribute type shall be a scalar
2365 @Chg{Version=[2],New=[type ],Old=[]}whose size is equal to the size of the
2366 predefined @Chg{Version=[2],New=[type Integer],Old=[integer size]}.
2367 For each measurement, two cases shall be documented: one
2368 where the accessed attributes are of the calling task @Redundant[(that is,
2369 the default value for the T parameter is used)], and the other, where T
2370 identifies another, nonterminated, task.
2371
2372 @Leading@;The following calls (to subprograms in the Task_Attributes package)
2373 shall be measured:
2374 @begin{Itemize}
2375 a call to Value, where the return value is Initial_Value;
2376
2377 a call to Value, where the return value is not equal to Initial_Value;
2378
2379 a call to Reference, where the return value designates a value equal to
2380 Initial_Value;
2381
2382 a call to Reference, where the return value designates a value not equal
2383 to Initial_Value;
2384
2385 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
2386 a call to Set_Value where the Val parameter is not equal to Initial_Value
2387 and the old attribute value is equal to Initial_Value@Chg{Version=[2],New=[;],Old=[.]}
2388
2389 a call to Set_Value where the Val parameter is not equal to Initial_Value
2390 and the old attribute value is not equal to Initial_Value.
2391
2392 @end{Itemize}
2393 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
2394 Text=[The metrics for the Task_Attributes package.]}]}
2395 @end{Metrics}
2396
2397 @begin{ImplPerm}
2398
2399 An implementation need not actually create the object corresponding
2400 to a task attribute
2401 until its value is set to something other than that of Initial_Value,
2402 or until Reference is called for the task attribute.
2403 Similarly, when the value of the attribute is
2404 to be reinitialized to that of Initial_Value,
2405 the object may instead be finalized and its storage reclaimed, to
2406 be recreated when needed later.
2407 While the object does not exist, the function Value may
2408 simply return Initial_Value, rather than implicitly creating the object.
2409 @begin{Discussion}
2410 The effect of this permission can only be observed if the assignment
2411 operation for the corresponding type has side effects.
2412 @end{Discussion}
2413 @begin{ImplNote}
2414 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
2415 This permission means that even though every task has every
2416 attribute, storage need only be allocated for those attributes
2417 @Chg{Version=[2],New=[for which function Reference has been invoked],Old=[that
2418 have been Reference'd]} or set to a value other than that
2419 of Initial_Value.
2420 @end{ImplNote}
2421
2422 An implementation is allowed to place restrictions on the maximum number of
2423 attributes a task may have, the maximum size of each attribute, and the
2424 total storage size allocated for all the attributes of a task.
2425
2426 @end{ImplPerm}
2427
2428 @begin{ImplAdvice}
2429
2430 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
2431 Some implementations are targeted to domains in which memory use at run
2432 time must be completely deterministic. For such implementations, it is
2433 recommended that the storage for task attributes will be pre-allocated
2434 statically and not from the heap. This can be accomplished by either
2435 placing restrictions on the number and the size of the @Chg{Version=[2],
2436 New=[],Old=[task's ]}attributes@Chg{Version=[2],New=[ of a task],Old=[]},
2437 or by using the pre-allocated storage for the first N attribute objects,
2438 and the heap for the others. In the latter case, N should be documented.
2439
2440 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
2441 Text=[If the target domain requires deterministic memory use at run
2442 time, storage for task attributes should be pre-allocated
2443 statically and the number of attributes pre-allocated should be documented.]}]}
2444
2445 @begin{Discussion}
2446 @ChgRef{Version=[2],Kind=[AddedNormal]}
2447 @ChgAdded{Version=[2],Text=[We don't mention @lquotes@;restrictions on the
2448 size and number@rquotes (that is, limits) in the text for the
2449 Annex, because it is covered by the @DocReqName above, and we try not to
2450 repeat requirements in the Annex (they're enough work to meet without
2451 having to do things twice).]}
2452 @end{Discussion}
2453 @end{ImplAdvice}
2454
2455 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00237-01]}
2456 @ChgAdded{Version=[2],Text=[Finalization of task attributes and reclamation of
2457 associated storage should be performed as soon as possible after task
2458 termination.]}
2459 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
2460 Text=[Finalization of task attributes and reclamation of
2461 associated storage should be performed as soon as possible after task
2462 termination.]}]}
2463 @begin{Reason}
2464 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00237-01]}
2465 @ChgAdded{Version=[2],Text=[This is necessary because the normative wording
2466 only says that attributes are finalized @lquotes@;after@rquotes@;
2467 task termination. Without this advice, waiting until the instance is
2468 finalized would meet the requirements (it is after termination, but may be
2469 a very long time after termination). We can't say anything more specific
2470 than this, as we do not want to require the overhead of an interaction with
2471 the tasking system to be done at a specific point.]}
2472 @end{Reason}
2473 @begin{Notes}
2474
2475 An attribute always exists (after instantiation), and has the initial value.
2476 It need not occupy memory until the first operation that potentially
2477 changes the attribute value. The same holds true after Reinitialize.
2478
2479 The result of the Reference function should be used with care; it is always
2480 safe to use that result in the task body whose attribute is being
2481 accessed. However, when the result is being used by another task, the
2482 programmer must make sure that the task whose attribute is being accessed
2483 is not yet terminated. Failing to do so could make the program execution
2484 erroneous.
2485
2486 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00434-01]}
2487 @ChgDeleted{Version=[2],Text=[As specified in
2488 @RefSecNum{The Package Task_Identification}, if the parameter T (in a call
2489 on a subprogram of an instance of this package) identifies a nonexistent
2490 task, the execution of the program is erroneous.]}
2491 @end{Notes}
2492
2493 @begin{DiffWord95}
2494 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0071],ARef=[AI95-00165-01]}
2495 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that use of task
2496 attribute operations from within a task attribute operation (by an Adjust
2497 or Finalize call) is a bounded error, and that concurrent use of attribute
2498 handles is erroneous.]}
2499
2500 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00237-01]}
2501 @ChgAdded{Version=[2],Text=[Clarified the wording so that the finalization
2502 takes place after the termination of the task or when the instance is
2503 finalized (whichever is sooner).]}
2504 @end{Diffword95}
2505
2506 @LabeledAddedSubClause{Version=[2],Name=[The Package Task_Termination]}
2507
2508 @begin{StaticSem}
2509
2510 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
2511 @ChgAdded{Version=[2],KeepNext=[T],Type=[Leading],Text=[The following
2512 language-defined library package exists:]}
2513 @begin{Example}
2514 @ChgRef{Version=[2],Kind=[AddedNormal]}
2515 @ChgAdded{Version=[2],Text=[@key<with> Ada.Task_Identification;
2516 @key<with> Ada.Exceptions;
2517 @key<package> Ada.Task_Termination @key<is>@ChildUnit{Parent=[Ada],Child=[Task_Termination]}
2518 @key<pragma> Preelaborate(Task_Termination);]}
2519
2520 @ChgRef{Version=[2],Kind=[AddedNormal]}
2521 @ChgAdded{Version=[2],Text=[ @key<type> @AdaTypeDefn{Cause_Of_Termination} @key<is> (Normal, Abnormal, Unhandled_Exception);]}
2522
2523 @ChgRef{Version=[2],Kind=[AddedNormal]}
2524 @ChgAdded{Version=[2],Text=[ @key<type> @AdaTypeDefn{Termination_Handler} @key<is access protected procedure>
2525 (Cause : @key<in> Cause_Of_Termination;
2526 T : @key<in> Ada.Task_Identification.Task_Id;
2527 X : @key<in> Ada.Exceptions.Exception_Occurrence);]}
2528
2529 @ChgRef{Version=[2],Kind=[AddedNormal]}
2530 @ChgAdded{Version=[2],Text=[ @key<procedure> @AdaSubDefn{Set_Dependents_Fallback_Handler}
2531 (Handler: @key<in> Termination_Handler);
2532 @key<function> @AdaSubDefn{Current_Task_Fallback_Handler} @key<return> Termination_Handler;]}
2533
2534 @ChgRef{Version=[2],Kind=[AddedNormal]}
2535 @ChgAdded{Version=[2],Text=[ @key<procedure> @AdaSubDefn{Set_Specific_Handler}
2536 (T : @key<in> Ada.Task_Identification.Task_Id;
2537 Handler : @key<in> Termination_Handler);
2538 @key<function> @AdaSubDefn{Specific_Handler} (T : Ada.Task_Identification.Task_Id)
2539 @key<return> Termination_Handler;]}
2540
2541 @ChgRef{Version=[2],Kind=[AddedNormal]}
2542 @ChgAdded{Version=[2],Text=[@key<end> Ada.Task_Termination;]}
2543 @end{Example}
2544
2545 @end{StaticSem}
2546
2547 @begin{RunTime}
2548
2549 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
2550 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0202-1]}
2551 @ChgAdded{Version=[2],Text=[@Defn{termination handler}@Defn2{Term=[handler],Sec=[termination]}
2552 The type Termination_Handler identifies a protected
2553 procedure to be executed by the implementation when a task terminates. Such a
2554 protected procedure is called a @i<handler>. In all cases T identifies the task
2555 that is terminating. If the task terminates due to completing the last
2556 statement of its body, or as a result of waiting on a terminate alternative,
2557 @Chg{Version=[3],New=[and the finalization of the task completes normally, ],Old=[]}then
2558 Cause is set to Normal and X is set to Null_Occurrence. If the task
2559 terminates because it is being aborted, then Cause is set to
2560 Abnormal@Chg{Version=[3],New=[;],Old=[ and]} X is set to
2561 Null_Occurrence@Chg{Version=[3],New=[ if the finalization of the task completes normally],Old=[]}.
2562 If the task terminates because of an exception raised
2563 by the execution of its @nt{task_body}, then Cause is set to
2564 Unhandled_Exception@Chg{Version=[3],New=[;],Old=[ and]} X is set to the
2565 associated exception occurrence@Chg{Version=[3],New=[ if the finalization
2566 of the task completes normally],Old=[]}.@Chg{Version=[3],New=[ Independent of
2567 how the task completes, if finalization of the task propagates an exception,
2568 then Cause is either Unhandled_Exception or Abnormal, and X is an exception
2569 occurrence that identifies the Program_Error exception.],Old=[]}]}
2570
2571 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
2572 @ChgAdded{Version=[2],Text=[@Defn{fall-back handler}@Defn2{Term=[termination handler],Sec=[fall-back]}
2573 @Defn{specific handler}@Defn2{Term=[termination handler],Sec=[specific]}
2574 @Defn2{Term=[set],Sec=[termination handler]}
2575 @Defn2{Term=[cleared],Sec=[termination handler]}
2576 Each task has two termination handlers, a @i<fall-back handler> and a
2577 @i<specific handler>. The specific handler applies only to the task itself,
2578 while the fall-back handler applies only to the dependent tasks of the task.
2579 A handler is said to be @i<set> if it is associated
2580 with a nonnull value of type Termination_Handler, and @i<cleared> otherwise.
2581 When a task is created, its specific handler and fall-back handler are cleared.]}
2582
2583 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
2584 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
2585 @ChgAdded{Version=[2],Text=[The procedure Set_Dependents_Fallback_Handler
2586 changes the fall-back handler for the calling
2587 task@Chg{Version=[3],New=[:],Old=[;]} if Handler is @key{null},
2588 that fall-back handler is cleared@Chg{Version=[3],New=[;],Old=[,]}
2589 otherwise@Chg{Version=[3],New=[,],Old=[]} it is set to be Handler.@key{all}.
2590 If a fall-back handler had previously been set it is replaced.]}
2591
2592 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
2593 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
2594 @ChgAdded{Version=[2],Text=[The function Current_Task_Fallback_Handler returns
2595 the fall-back handler that is currently set for the calling task, if one is
2596 set; otherwise@Chg{Version=[3],New=[,],Old=[]} it returns @key{null}.]}
2597
2598 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
2599 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
2600 @ChgAdded{Version=[2],Text=[The procedure Set_Specific_Handler changes the
2601 specific handler for the task identified by
2602 T@Chg{Version=[3],New=[:],Old=[;]} if Handler is @key{null}, that
2603 specific handler is cleared@Chg{Version=[3],New=[;],Old=[,]}
2604 otherwise@Chg{Version=[3],New=[,],Old=[]} it is set to be Handler.@key{all}. If
2605 a specific handler had previously been set it is replaced.]}
2606
2607 @begin{Ramification}
2608 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
2609 @ChgAdded{Version=[3],Text=[This package cannot portably be used to set
2610 a handler on the program as a whole. It is possible to call
2611 Set_Specific_Handler with the environment task's ID. But any call to the
2612 handler would necessarily be a @BoundedName, as the handler is called
2613 after the task's finalization has completed. In the case of the environment
2614 task, that includes any possible protected objects, and calling a protected
2615 object after it is finalized is a @BoundedName
2616 (see @RefSecNum{Protected Units and Protected Objects}). This might work in
2617 a particular implementation, but it cannot be depended upon.]}
2618 @end{Ramification}
2619
2620 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
2621 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
2622 @ChgAdded{Version=[2],Text=[The function Specific_Handler returns the specific
2623 handler that is currently set for the task identified by T, if one is set;
2624 otherwise@Chg{Version=[3],New=[,],Old=[]} it returns @key{null}.]}
2625
2626 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
2627 @ChgAdded{Version=[2],Text=[As part of the finalization of a @nt{task_body},
2628 after performing the actions specified in
2629 @RefSecNum{Assignment and Finalization} for finalization of a
2630 master, the specific handler for the task, if one is set, is executed.
2631 If the specific handler is cleared, a search
2632 for a fall-back handler proceeds by recursively following the master
2633 relationship for the task. If a task is found whose fall-back handler is set,
2634 that handler is executed; otherwise, no handler is executed.]}
2635
2636 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
2637 @ChgAdded{Version=[2],Text=[For Set_Specific_Handler or
2638 Specific_Handler, Tasking_Error is raised if the task identified by T has
2639 already terminated. Program_Error is raised if the value of T is
2640 Ada.Task_Identification.Null_Task_Id.]}
2641
2642 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
2643 @ChgAdded{Version=[2],Text=[An exception propagated from a handler that is
2644 invoked as part of the termination of a task has no effect.]}
2645
2646 @end{RunTime}
2647
2648 @begin{Erron}
2649 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
2650 @ChgAdded{Version=[2],Text=[For a call of Set_Specific_Handler or
2651 Specific_Handler, if the task identified by T no longer exists, the execution
2652 of the program is erroneous.]}
2653 @end{Erron}
2654
2655 @begin{Extend95}
2656 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
2657 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2658 Package Task_Termination is new.]}
2659 @end{Extend95}
2660
2661 @begin{DiffWord2005}
2662 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0202-1]}
2663 @ChgAdded{Version=[3],Text=[@b<Correction:> Specified what is passed to the
2664 handler if the finalization of the task fails after it is completed. This was
2665 not specified at all in Ada 2005, so there is a possibility that some program
2666 depended on some other behavior of an implementation. But as this case is
2667 very unlikely (and only occurs when there is already a significant bug in
2668 the program - so should not occur in fielded systems), we're not listing
2669 this as an inconsistency.]}
2670 @end{DiffWord2005}