annotate gcc/ada/libgnarl/s-taasde.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . T A S K I N G . A S Y N C _ D E L A Y S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1998-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNARL is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNARL was developed by the GNARL team at Florida State University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- This package contains the procedures to implements timeouts (delays) for
kono
parents:
diff changeset
33 -- asynchronous select statements.
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
kono
parents:
diff changeset
36 -- Any changes to this interface may require corresponding compiler changes.
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 package System.Tasking.Async_Delays is
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 -- Suppose the following source code is given:
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 -- select delay When;
kono
parents:
diff changeset
43 -- ...continuation for timeout case...
kono
parents:
diff changeset
44 -- then abort
kono
parents:
diff changeset
45 -- ...abortable part...
kono
parents:
diff changeset
46 -- end select;
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 -- The compiler should expand this to the following:
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 -- declare
kono
parents:
diff changeset
51 -- DB : aliased Delay_Block;
kono
parents:
diff changeset
52 -- begin
kono
parents:
diff changeset
53 -- if System.Tasking.Async_Delays.Enqueue_Duration
kono
parents:
diff changeset
54 -- (When, DB'Unchecked_Access)
kono
parents:
diff changeset
55 -- then
kono
parents:
diff changeset
56 -- begin
kono
parents:
diff changeset
57 -- A101b : declare
kono
parents:
diff changeset
58 -- procedure _clean is
kono
parents:
diff changeset
59 -- begin
kono
parents:
diff changeset
60 -- System.Tasking.Async_Delays.Cancel_Async_Delay
kono
parents:
diff changeset
61 -- (DB'Unchecked_Access);
kono
parents:
diff changeset
62 -- return;
kono
parents:
diff changeset
63 -- end _clean;
kono
parents:
diff changeset
64 -- begin
kono
parents:
diff changeset
65 -- abort_undefer.all;
kono
parents:
diff changeset
66 -- ...abortable part...
kono
parents:
diff changeset
67 -- exception
kono
parents:
diff changeset
68 -- when all others =>
kono
parents:
diff changeset
69 -- declare
kono
parents:
diff changeset
70 -- E105b : exception_occurrence;
kono
parents:
diff changeset
71 -- begin
kono
parents:
diff changeset
72 -- save_occurrence (E105b, get_current_excep.all.all);
kono
parents:
diff changeset
73 -- _clean;
kono
parents:
diff changeset
74 -- reraise_occurrence_no_defer (E105b);
kono
parents:
diff changeset
75 -- end;
kono
parents:
diff changeset
76 -- at end
kono
parents:
diff changeset
77 -- _clean;
kono
parents:
diff changeset
78 -- end A101b;
kono
parents:
diff changeset
79 -- exception
kono
parents:
diff changeset
80 -- when _abort_signal =>
kono
parents:
diff changeset
81 -- abort_undefer.all;
kono
parents:
diff changeset
82 -- end;
kono
parents:
diff changeset
83 -- end if;
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 -- if Timed_Out (DB'Unchecked_Access) then
kono
parents:
diff changeset
86 -- ...continuation for timeout case...
kono
parents:
diff changeset
87 -- end if;
kono
parents:
diff changeset
88 -- end;
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 -----------------
kono
parents:
diff changeset
91 -- Delay_Block --
kono
parents:
diff changeset
92 -----------------
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 type Delay_Block is limited private;
kono
parents:
diff changeset
95 type Delay_Block_Access is access all Delay_Block;
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 function Enqueue_Duration
kono
parents:
diff changeset
98 (T : Duration;
kono
parents:
diff changeset
99 D : Delay_Block_Access) return Boolean;
kono
parents:
diff changeset
100 -- Enqueue the specified relative delay. Returns True if the delay has
kono
parents:
diff changeset
101 -- been enqueued, False if it has already expired. If the delay has been
kono
parents:
diff changeset
102 -- enqueued, abort is deferred.
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 procedure Cancel_Async_Delay (D : Delay_Block_Access);
kono
parents:
diff changeset
105 -- Cancel the specified asynchronous delay
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 function Timed_Out (D : Delay_Block_Access) return Boolean;
kono
parents:
diff changeset
108 pragma Inline (Timed_Out);
kono
parents:
diff changeset
109 -- Return True if the delay specified in D has timed out
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 -- There are child units for delays on Ada.Calendar.Time/Ada.Real_Time.Time
kono
parents:
diff changeset
112 -- so that an application need not link in features that it is not using.
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 private
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 type Delay_Block is limited record
kono
parents:
diff changeset
117 Self_Id : Task_Id;
kono
parents:
diff changeset
118 -- ID of the calling task
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 Level : ATC_Level_Base;
kono
parents:
diff changeset
121 -- Normally Level is the ATC nesting level of the asynchronous select
kono
parents:
diff changeset
122 -- statement to which this delay belongs, but after a call has been
kono
parents:
diff changeset
123 -- dequeued we set it to ATC_Level_Infinity so that the Cancel operation
kono
parents:
diff changeset
124 -- can detect repeated calls, and act idempotently.
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 Resume_Time : Duration;
kono
parents:
diff changeset
127 -- The absolute wake up time, represented as Duration
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 Timed_Out : Boolean := False;
kono
parents:
diff changeset
130 -- Set to true if the delay has timed out
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 Succ, Pred : Delay_Block_Access;
kono
parents:
diff changeset
133 -- A double linked list
kono
parents:
diff changeset
134 end record;
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 -- The above "overlaying" of Self_Id and Level to hold other data that has
kono
parents:
diff changeset
137 -- a non-overlapping lifetime is an unabashed hack to save memory.
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 procedure Time_Enqueue
kono
parents:
diff changeset
140 (T : Duration;
kono
parents:
diff changeset
141 D : Delay_Block_Access);
kono
parents:
diff changeset
142 pragma Inline (Time_Enqueue);
kono
parents:
diff changeset
143 -- Used by the child units to enqueue delays on the timer queue implemented
kono
parents:
diff changeset
144 -- in the body of this package. T denotes a point in time as the duration
kono
parents:
diff changeset
145 -- elapsed since the epoch of the Ada real-time clock.
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 end System.Tasking.Async_Delays;