The signature and semantics of the priority queue operation Dequeue_Only_High_Priority changed during the ARG meeting in Edinburgh (June 2011). That operation had been a protected entry in earlier drafts of AI05-0159, but it was discovered that that operation as formerly specified was not in fact implementable, so it was changed during the Edinburgh meeting to be a protected procedure with a different signature and semantics. This revision of the sources now fully implements the protected procedure Dequeue_Only_High_Priority, to conform to its specification as described in the most recent draft of the Ada 2012 RM.
Tested on x86_64-pc-linux-gnu, committed on trunk 2011-10-06 Matthew Heaney <hea...@adacore.com> * a-cuprqu.ads, a-cuprqu.adb, a-cbprqu.ads, a-cbprqu.adb (Dequeue_Only_High_Priority): Protected procedure now implemented.
Index: a-cbprqu.adb =================================================================== --- a-cbprqu.adb (revision 179628) +++ a-cbprqu.adb (working copy) @@ -44,6 +44,24 @@ List.Container.Delete_First; end Dequeue; + procedure Dequeue + (List : in out List_Type; + At_Least : Queue_Priority; + Element : in out Queue_Interfaces.Element_Type; + Success : out Boolean) + is + begin + if List.Length = 0 + or else not Before (At_Least, Get_Priority (List.First_Element)) + then + Success := False; + return; + end if; + + List.Dequeue (Element); + Success := True; + end Dequeue; + ------------- -- Enqueue -- ------------- @@ -83,6 +101,18 @@ end if; end Enqueue; + ------------------- + -- First_Element -- + ------------------- + + function First_Element + (List : List_Type) return Queue_Interfaces.Element_Type + is + begin + -- Use Constant_Reference for this. ??? + return List.Container.First_Element; + end First_Element; + ------------ -- Length -- ------------ @@ -125,15 +155,19 @@ List.Dequeue (Element); end Dequeue; - -- ??? - -- entry Dequeue_Only_High_Priority - -- (Low_Priority : Queue_Priority; - -- Element : out Queue_Interfaces.Element_Type) when True - -- is - -- begin - -- null; - -- end Dequeue_Only_High_Priority; + -------------------------------- + -- Dequeue_Only_High_Priority -- + -------------------------------- + procedure Dequeue_Only_High_Priority + (At_Least : Queue_Priority; + Element : in out Queue_Interfaces.Element_Type; + Success : out Boolean) + is + begin + List.Dequeue (At_Least, Element, Success); + end Dequeue_Only_High_Priority; + -------------- -- Enqueue -- -------------- Index: a-cbprqu.ads =================================================================== --- a-cbprqu.ads (revision 179628) +++ a-cbprqu.ads (working copy) @@ -70,6 +70,15 @@ (List : in out List_Type; Element : out Queue_Interfaces.Element_Type); + procedure Dequeue + (List : in out List_Type; + At_Least : Queue_Priority; + Element : in out Queue_Interfaces.Element_Type; + Success : out Boolean); + + function First_Element + (List : List_Type) return Queue_Interfaces.Element_Type; + function Length (List : List_Type) return Count_Type; function Max_Length (List : List_Type) return Count_Type; @@ -102,12 +111,19 @@ overriding entry Dequeue (Element : out Queue_Interfaces.Element_Type); - -- ??? - -- not overriding - -- entry Dequeue_Only_High_Priority - -- (Low_Priority : Queue_Priority; - -- Element : out Queue_Interfaces.Element_Type); + -- The priority queue operation Dequeue_Only_High_Priority had been a + -- protected entry in early drafts of AI05-0159, but it was discovered + -- that that operation as specified was not in fact implementable. The + -- operation was changed from an entry to a protected procedure per the + -- ARG meeting in Edinburgh (June 2011), with a different signature and + -- semantics. + not overriding + procedure Dequeue_Only_High_Priority + (At_Least : Queue_Priority; + Element : in out Queue_Interfaces.Element_Type; + Success : out Boolean); + overriding function Current_Use return Count_Type; @@ -115,6 +131,7 @@ function Peak_Use return Count_Type; private + List : Implementation.List_Type (Capacity); end Queue; Index: a-cuprqu.adb =================================================================== --- a-cuprqu.adb (revision 179628) +++ a-cuprqu.adb (working copy) @@ -65,6 +65,24 @@ Free (X); end Dequeue; + procedure Dequeue + (List : in out List_Type; + At_Least : Queue_Priority; + Element : in out Queue_Interfaces.Element_Type; + Success : out Boolean) + is + begin + if List.Length = 0 + or else not Before (At_Least, Get_Priority (List.First.Element)) + then + Success := False; + return; + end if; + + List.Dequeue (Element); + Success := True; + end Dequeue; + ------------- -- Enqueue -- ------------- @@ -132,22 +150,6 @@ end loop; end Finalize; - ------------------------ - -- Have_High_Priority -- - ------------------------ - - -- ??? - -- function Have_High_Priority - -- (List : List_Type; - -- Low_Priority : Queue_Priority) return Boolean - -- is - -- begin - -- if List.Length = 0 then - -- return False; - -- end if; - -- return Before (Get_Priority (List.First.Element), Low_Priority); - -- end Have_High_Priority; - ------------ -- Length -- ------------ @@ -190,15 +192,19 @@ List.Dequeue (Element); end Dequeue; - -- ??? - -- entry Dequeue_Only_High_Priority - -- (Low_Priority : Queue_Priority; - -- Element : out Queue_Interfaces.Element_Type) when True - -- is - -- begin - -- null; - -- end Dequeue_Only_High_Priority; + -------------------------------- + -- Dequeue_Only_High_Priority -- + -------------------------------- + procedure Dequeue_Only_High_Priority + (At_Least : Queue_Priority; + Element : in out Queue_Interfaces.Element_Type; + Success : out Boolean) + is + begin + List.Dequeue (At_Least, Element, Success); + end Dequeue_Only_High_Priority; + ------------- -- Enqueue -- ------------- Index: a-cuprqu.ads =================================================================== --- a-cuprqu.ads (revision 179628) +++ a-cuprqu.ads (working copy) @@ -68,6 +68,12 @@ (List : in out List_Type; Element : out Queue_Interfaces.Element_Type); + procedure Dequeue + (List : in out List_Type; + At_Least : Queue_Priority; + Element : in out Queue_Interfaces.Element_Type; + Success : out Boolean); + function Length (List : List_Type) return Count_Type; function Max_Length (List : List_Type) return Count_Type; @@ -91,37 +97,38 @@ overriding procedure Finalize (List : in out List_Type); - -- ??? - -- not overriding - -- function Have_High_Priority - -- (List : List_Type; - -- Low_Priority : Queue_Priority) return Boolean; - end Implementation; protected type Queue (Ceiling : System.Any_Priority := Default_Ceiling) - -- ??? - -- with Priority => Ceiling is new Queue_Interfaces.Queue with - is new Queue_Interfaces.Queue with + -- ??? + -- with Priority => Ceiling is new Queue_Interfaces.Queue with + is new Queue_Interfaces.Queue with - overriding - entry Enqueue (New_Item : Queue_Interfaces.Element_Type); + overriding + entry Enqueue (New_Item : Queue_Interfaces.Element_Type); - overriding - entry Dequeue (Element : out Queue_Interfaces.Element_Type); + overriding + entry Dequeue (Element : out Queue_Interfaces.Element_Type); - -- ??? - -- not overriding - -- entry Dequeue_Only_High_Priority - -- (Low_Priority : Queue_Priority; - -- Element : out Queue_Interfaces.Element_Type); + -- The priority queue operation Dequeue_Only_High_Priority had been a + -- protected entry in early drafts of AI05-0159, but it was discovered + -- that that operation as specified was not in fact implementable. The + -- operation was changed from an entry to a protected procedure per the + -- ARG meeting in Edinburgh (June 2011), with a different signature and + -- semantics. - overriding - function Current_Use return Count_Type; + not overriding + procedure Dequeue_Only_High_Priority + (At_Least : Queue_Priority; + Element : in out Queue_Interfaces.Element_Type; + Success : out Boolean); - overriding - function Peak_Use return Count_Type; + overriding + function Current_Use return Count_Type; + overriding + function Peak_Use return Count_Type; + private List : Implementation.List_Type;