Merge from mainline
[official-gcc.git] / gcc / ada / a-rttiev.ads
blob9d114d4f598120e66f5f979925f9a47f5dc969bd
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . R E A L _ T I M E . T I M I N G _ E V E N T S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2005-2006, Free Software Foundation, Inc. --
10 -- --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the contents of the part following the private keyword. --
14 -- --
15 -- GNAT is free software; you can redistribute it and/or modify it under --
16 -- terms of the GNU General Public License as published by the Free Soft- --
17 -- ware Foundation; either version 2, or (at your option) any later ver- --
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
21 -- for more details. You should have received a copy of the GNU General --
22 -- Public License distributed with GNAT; see file COPYING. If not, write --
23 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
24 -- Boston, MA 02110-1301, USA. --
25 -- --
26 -- As a special exception, if other files instantiate generics from this --
27 -- unit, or you link this unit with other files to produce an executable, --
28 -- this unit does not by itself cause the resulting executable to be --
29 -- covered by the GNU General Public License. This exception does not --
30 -- however invalidate any other reasons why the executable file might be --
31 -- covered by the GNU Public License. --
32 -- --
33 -- GNAT was originally developed by the GNAT team at New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc. --
35 -- --
36 ------------------------------------------------------------------------------
38 with Ada.Finalization;
40 package Ada.Real_Time.Timing_Events is
42 type Timing_Event is tagged limited private;
44 type Timing_Event_Handler
45 is access protected procedure (Event : in out Timing_Event);
47 procedure Set_Handler
48 (Event : in out Timing_Event;
49 At_Time : Time;
50 Handler : Timing_Event_Handler);
52 procedure Set_Handler
53 (Event : in out Timing_Event;
54 In_Time : Time_Span;
55 Handler : Timing_Event_Handler);
57 function Current_Handler
58 (Event : Timing_Event) return Timing_Event_Handler;
60 procedure Cancel_Handler
61 (Event : in out Timing_Event;
62 Cancelled : out Boolean);
64 function Time_Of_Event (Event : Timing_Event) return Time;
66 private
68 protected type Event_State is
70 -- D.15 (22/2) requires atomicity with respect to the operations
71 -- provided by the package and the timing events they manipulate. On
72 -- real-time operating systems suitable for implementing this package, a
73 -- different implementation strategy would be employed to meet that
74 -- requirement.
76 entry Set (Timeout : Time; Handler : Timing_Event_Handler);
77 -- Changes the timeout and handler values for procedure Set_Handler. Can
78 -- only execute when the event is 'available', to prevent a race
79 -- condition between the caller of Set_Handler and the internal Timer
80 -- task that processes the events. In particular, D.15 (22/2) requires
81 -- that there be no possibility of a new handler executing in response
82 -- to an old timeout.
84 procedure Reset;
85 -- First resets the timeout to Time_First and the handler to
86 -- null. Indicates that Set (for Set_Handler) can now change the timeout
87 -- and/or handler. Called only by the interal Timer task.
89 procedure Cancel;
90 -- Resets the timeout to Time_First and the handler to
91 -- null. Called by procedure Cancel_Handler and by procedure Reset.
93 function Current_Timeout return Time;
94 -- Returns the currently set timeout. The value Time_First is returned
95 -- if the Timing_Event is in the "cleared" state. Called by function
96 -- Time_of_Event.
98 function Current_Handler return Timing_Event_Handler;
99 -- Returns the currently set handler. The value null is returned if the
100 -- Timing_Event is in the "cleared" state. Called by function
101 -- Curent_Handler.
103 private
104 Timeout : Time := Time_First;
105 -- The time at which the user's handler should be invoked when the
106 -- event is "set" (i.e., when Handler is not null).
108 Handler : Timing_Event_Handler;
109 -- An access value designating the protected procedure to be invoked
110 -- at the Timeout time in the future. When this value is null the event
111 -- is said to be "cleared" and no timeout is processed.
113 Available : Boolean := True;
114 -- A flag controlling when users can change the Timeout and Handler
115 -- tuple. In particular the entry Set, called by procedure Set_Handler,
116 -- is controlled by this flag.
118 end Event_State;
120 type Timing_Event is new Ada.Finalization.Limited_Controlled with record
121 Control : Event_State;
122 end record;
124 overriding procedure Finalize (This : in out Timing_Event);
125 -- Finalization procedure is required to satisfy (RM D.15 (19/2)), which
126 -- says that the object must be cleared on finalization.
128 end Ada.Real_Time.Timing_Events;