1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149 | -- --
-- package Copyright (c) Dmitry A. Kazakov --
-- Generic_Indefinite_FIFO Luebeck --
-- Generic_Signaled Summer, 2008 --
-- Interface --
-- Last revision : 09:14 29 Jun 2008 --
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU General Public License as --
-- published by the Free Software Foundation; either version 2 of --
-- the License, or (at your option) any later version. This library --
-- is distributed in the hope that it will be useful, but WITHOUT --
-- ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. You should have --
-- received a copy of the GNU General Public License along with --
-- this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from --
-- this unit, or you link this unit with other files to produce an --
-- executable, this unit does not by itself cause the resulting --
-- executable to be covered by the GNU General Public License. This --
-- exception does not however invalidate any other reasons why the --
-- executable file might be covered by the GNU Public License. --
--____________________________________________________________________--
with System.Storage_Elements; use System.Storage_Elements;
with System.Storage_Pools; use System.Storage_Pools;
with Ada.Finalization;
generic
package Generic_Indefinite_FIFO.Generic_Signaled is
--
-- Signaled_FIFO -- The queue
--
-- Size - The maximal number of elements in the queue + 1
--
type Signaled_FIFO is new FIFO with private;
--
-- Cancel -- Prematurely cancel waiting
--
-- Queue - The queue
--
-- This operation terminates waiting of any tasks blocked on Queue.
-- Blocking calls to Get (when queue is empty) or to Put (when queue is
-- full) are released with propagation of End_Error. Differently to
-- Delete, Get, Peek and Put, Cancel can be called from any task.
--
procedure Cancel (Queue : in out Signaled_FIFO);
--
-- Delete -- Overrides Generic_FIFO...
--
procedure Delete
( Queue : in out Signaled_FIFO;
Count : Natural := 1
);
--
-- Get -- Overrides Generic_FIFO...
--
-- Queue - The queue
-- [ Timeout ] - Blocking timeout
--
-- Returns :
--
-- The element from the queue
--
-- Exceptions :
--
-- Constraint_Error - Timeout expiration when Queue is still empty
-- End_Error - Canceled by a call to Cancel
--
function Get (Queue : Signaled_FIFO) return Element_Type;
function Get (Queue : Signaled_FIFO; Timeout : Duration)
return Element_Type;
--
-- Peek -- Overrides Generic_FIFO...
--
-- Queue - The queue
-- Timeout - Blocking timeout
--
-- Returns :
--
-- The element from the queue
--
-- Exceptions :
--
-- Constraint_Error - Timeout expiration when Queue is still empty
-- End_Error - Canceled by a call to Cancel
--
function Peek (Queue : Signaled_FIFO) return Element_Type;
function Peek (Queue : Signaled_FIFO; Timeout : Duration)
return Element_Type;
--
-- Put -- Overrides Generic_FIFO...
--
-- Queue - The queue
-- Element - To put into FIFO
-- [ Timeout ] - Blocking timeout
--
-- Exceptions :
--
-- Constraint_Error - Timeout expiration when Queue is still full
-- End_Error - Canceled by a call to Cancel
--
procedure Put
( Queue : in out Signaled_FIFO;
Element : Element_Type
);
procedure Put
( Queue : in out Signaled_FIFO;
Element : Element_Type;
Timeout : Duration
);
private
protected type Signal (Queue : access Signaled_FIFO) is
entry Break;
procedure Release_Get;
procedure Release_Put;
entry Wait_To_Get;
entry Wait_To_Put (Element : Element_Type);
private
Released_Get : Boolean := False;
Released_Put : Boolean := False;
end Signal;
type Signaled_FIFO is new FIFO with record
Event : Signal (Signaled_FIFO'Unchecked_Access);
Put_Blocked : Boolean := False;
Get_Blocked : Boolean := False;
pragma Atomic (Get_Blocked);
pragma Atomic (Put_Blocked);
end record;
procedure Lock_Free_Put
( Queue : in out Signaled_FIFO;
Element : Element_Type
);
pragma Inline (Delete);
pragma Inline (Get);
pragma Inline (Lock_Free_Put);
pragma Inline (Peek);
pragma Inline (Put);
end Generic_Indefinite_FIFO.Generic_Signaled;
|