1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.UNBOUNDED_SYNCHRONIZED_QUEUES --
9 -- Copyright (C) 2011-2014, Free Software Foundation, Inc. --
11 -- GNAT 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 3, or (at your option) any later ver- --
14 -- sion. GNAT 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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- This unit was originally developed by Matthew J Heaney. --
28 ------------------------------------------------------------------------------
30 with Ada.Unchecked_Deallocation;
32 package body Ada.Containers.Unbounded_Synchronized_Queues is
34 pragma Annotate (CodePeer, Skip_Analysis);
36 package body Implementation is
38 -----------------------
39 -- Local Subprograms --
40 -----------------------
43 new Ada.Unchecked_Deallocation (Node_Type, Node_Access);
50 (List : in out List_Type;
51 Element : out Queue_Interfaces.Element_Type)
56 Element := List.First.Element;
59 List.First := List.First.Next;
61 if List.First = null then
65 List.Length := List.Length - 1;
75 (List : in out List_Type;
76 New_Item : Queue_Interfaces.Element_Type)
81 Node := new Node_Type'(New_Item, null);
83 if List.First = null then
85 List.Last := List.First;
88 List.Last.Next := Node;
92 List.Length := List.Length + 1;
94 if List.Length > List.Max_Length then
95 List.Max_Length := List.Length;
103 procedure Finalize (List : in out List_Type) is
107 while List.First /= null loop
109 List.First := List.First.Next;
118 function Length (List : List_Type) return Count_Type is
127 function Max_Length (List : List_Type) return Count_Type is
129 return List.Max_Length;
134 protected body Queue is
140 function Current_Use return Count_Type is
149 entry Dequeue (Element : out Queue_Interfaces.Element_Type)
153 List.Dequeue (Element);
160 entry Enqueue (New_Item : Queue_Interfaces.Element_Type) when True is
162 List.Enqueue (New_Item);
169 function Peak_Use return Count_Type is
171 return List.Max_Length;
176 end Ada.Containers.Unbounded_Synchronized_Queues;