How to rename protected object entry

Viewed 78

I want to rename Synchronized_Queue_Interface Enqueue entry, but don’t understand how to do it right.

with Ada.Containers.Synchronized_Queue_Interfaces;
with Ada.Containers.Unbounded_Synchronized_Queues;

package Test is
   
   use Ada.Containers;
   
   package Boolean_Queue_Interfaces is new Synchronized_Queue_Interfaces
     (Element_Type => Boolean);
   
   package Boolean_Queues is new Unbounded_Synchronized_Queues
     (Queue_Interfaces => Boolean_Queue_Interfaces);
   
   Queue : Boolean_Queues.Queue;
   
   procedure Enqueue (New_Item : Boolean) renames Queue.Enqueue;  --  Illegal

end Test;
1 Answers

The form you need to use is this:

Protected Type Example is
    Entry Queue( Item : Integer );
Private
    Element : Integer := 0;
End Example;


Protected Body Example is
    Entry Queue( Item : Integer ) when true is
    Begin
        Element:= Item;
    End Queue;
End Example;    

V : example;

Procedure Q( X : Integer )
  renames V.Queue;

This is what you have, however it looks like the compiler is not able to tell the overloaded forms apart (Boolean_Queue_Interfaces.Queue.Enqueue vs Boolean_Queues.Queue.Enqueue). -- The best way to resolve this is to be explicit:

procedure Do_it( Item : Boolean )
  renames Boolean_Queues.Queue(Queue).Enqueue;

You should probably file a bug report, certainly asking for better error-messaging.

Related