1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . T A S K I N G . A S Y N C _ D E L A Y S --
10 -- Copyright (C) 1998-2001 Free Software Foundation, Inc. --
12 -- GNARL is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNARL; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
30 -- GNARL was developed by the GNARL team at Florida State University. It is --
31 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
32 -- State University (http://www.gnat.com). --
34 ------------------------------------------------------------------------------
36 -- This package contains the procedures to implements timeouts (delays)
37 -- for asynchronous select statements.
39 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
40 -- Any changes to this interface may require corresponding compiler changes.
42 package System
.Tasking
.Async_Delays
is
44 -- Suppose the following source code is given:
47 -- ...continuation for timeout case...
49 -- ...abortable part...
52 -- The compiler should expand this to the following:
55 -- DB : aliased Delay_Block;
57 -- if System.Tasking.Async_Delays.Enqueue_Duration
58 -- (When, DB'Unchecked_Access)
62 -- procedure _clean is
64 -- System.Tasking.Async_Delays.Cancel_Async_Delay
65 -- (DB'Unchecked_Access);
70 -- ...abortable part...
74 -- E105b : exception_occurrence;
76 -- save_occurrence (E105b, get_current_excep.all.all);
78 -- reraise_occurrence_no_defer (E105b);
84 -- when _abort_signal =>
89 -- if Timed_Out (DB'Unchecked_Access) then
90 -- ...continuation for timeout case...
98 type Delay_Block
is limited private;
99 type Delay_Block_Access
is access all Delay_Block
;
101 function Enqueue_Duration
103 D
: Delay_Block_Access
) return Boolean;
104 -- Enqueue the specified relative delay. Returns True if the delay has
105 -- been enqueued, False if it has already expired.
106 -- If the delay has been enqueued, abortion is deferred.
108 procedure Cancel_Async_Delay
(D
: Delay_Block_Access
);
109 -- Cancel the specified asynchronous delay
111 function Timed_Out
(D
: Delay_Block_Access
) return Boolean;
112 pragma Inline
(Timed_Out
);
113 -- Return True if the delay specified in D has timed out
115 -- There are child units for delays on Ada.Calendar.Time and
116 -- Ada.Real_Time.Time, so that an application will not need to link in
117 -- features that is not using.
121 type Delay_Block
is record
123 -- ID of the calling task
125 Level
: ATC_Level_Base
;
126 -- Normally Level is the ATC nesting level of the
127 -- async. select statement to which this delay belongs, but
128 -- after a call has been dequeued we set it to
129 -- ATC_Level_Infinity so that the Cancel operation can
130 -- detect repeated calls, and act idempotently.
132 Resume_Time
: Duration;
133 -- The absolute wake up time, represented as Duration
135 Timed_Out
: Boolean := False;
136 -- Set to true if the delay has timed out
138 Succ
, Pred
: Delay_Block_Access
;
139 -- A double linked list
142 -- The above "overlaying" of Self_ID and Level to hold other
143 -- data that has a non-overlapping lifetime is an unabashed
144 -- hack to save memory.
146 procedure Time_Enqueue
148 D
: Delay_Block_Access
);
149 pragma Inline
(Time_Enqueue
);
150 -- Used by the child units to enqueue delays on the timer queue
151 -- implemented in the body of this package.
153 end System
.Tasking
.Async_Delays
;