1 ------------------------------------------------------------------------------
3 -- GNAT 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 --
9 -- Copyright (C) 1998-2006, Free Software Foundation, Inc. --
11 -- GNARL is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNARL; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
32 ------------------------------------------------------------------------------
34 -- This package contains the procedures to implements timeouts (delays) for
35 -- asynchronous select statements.
37 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
38 -- Any changes to this interface may require corresponding compiler changes.
40 package System
.Tasking
.Async_Delays
is
42 -- Suppose the following source code is given:
45 -- ...continuation for timeout case...
47 -- ...abortable part...
50 -- The compiler should expand this to the following:
53 -- DB : aliased Delay_Block;
55 -- if System.Tasking.Async_Delays.Enqueue_Duration
56 -- (When, DB'Unchecked_Access)
60 -- procedure _clean is
62 -- System.Tasking.Async_Delays.Cancel_Async_Delay
63 -- (DB'Unchecked_Access);
68 -- ...abortable part...
72 -- E105b : exception_occurrence;
74 -- save_occurrence (E105b, get_current_excep.all.all);
76 -- reraise_occurrence_no_defer (E105b);
82 -- when _abort_signal =>
87 -- if Timed_Out (DB'Unchecked_Access) then
88 -- ...continuation for timeout case...
96 type Delay_Block
is limited private;
97 type Delay_Block_Access
is access all Delay_Block
;
99 function Enqueue_Duration
101 D
: Delay_Block_Access
) return Boolean;
102 -- Enqueue the specified relative delay. Returns True if the delay has
103 -- been enqueued, False if it has already expired. If the delay has been
104 -- enqueued, abort is deferred.
106 procedure Cancel_Async_Delay
(D
: Delay_Block_Access
);
107 -- Cancel the specified asynchronous delay
109 function Timed_Out
(D
: Delay_Block_Access
) return Boolean;
110 pragma Inline
(Timed_Out
);
111 -- Return True if the delay specified in D has timed out
113 -- There are child units for delays on Ada.Calendar.Time and
114 -- Ada.Real_Time.Time, so that an application will not need to link in
115 -- features that is not using.
119 type Delay_Block
is record
121 -- ID of the calling task
123 Level
: ATC_Level_Base
;
124 -- Normally Level is the ATC nesting level of the
125 -- async. select statement to which this delay belongs, but
126 -- after a call has been dequeued we set it to
127 -- ATC_Level_Infinity so that the Cancel operation can
128 -- detect repeated calls, and act idempotently.
130 Resume_Time
: Duration;
131 -- The absolute wake up time, represented as Duration
133 Timed_Out
: Boolean := False;
134 -- Set to true if the delay has timed out
136 Succ
, Pred
: Delay_Block_Access
;
137 -- A double linked list
140 -- The above "overlaying" of Self_ID and Level to hold other
141 -- data that has a non-overlapping lifetime is an unabashed
142 -- hack to save memory.
144 procedure Time_Enqueue
146 D
: Delay_Block_Access
);
147 pragma Inline
(Time_Enqueue
);
148 -- Used by the child units to enqueue delays on the timer queue
149 -- implemented in the body of this package.
151 end System
.Tasking
.Async_Delays
;