1. -- 
  2. -- Uwe R. Zimmer, Australia, 2014 
  3. -- 
  4.  
  5. package body Queue_Pack_Protected_Generic is 
  6.  
  7.    protected body Protected_Queue is 
  8.  
  9.       entry Enqueue (Item : Element) when not Is_Full is 
  10.  
  11.       begin 
  12.          Queue.Elements (Queue.Free) := Item; 
  13.          Queue.Free     := Index'Succ (Queue.Free); 
  14.          Queue.Is_Empty := False; 
  15.       end Enqueue; 
  16.  
  17.       entry Dequeue (Item : out Element) when not Is_Empty is 
  18.  
  19.       begin 
  20.          Item           := Queue.Elements (Queue.Top); 
  21.          Queue.Top      := Index'Succ (Queue.Top); 
  22.          Queue.Is_Empty := Queue.Top = Queue.Free; 
  23.       end Dequeue; 
  24.  
  25.       procedure Empty_Queue is 
  26.  
  27.       begin 
  28.          Queue.Top      := Index'First; 
  29.          Queue.Free     := Index'First; 
  30.          Queue.Is_Empty := True; 
  31.       end Empty_Queue; 
  32.  
  33.       function Is_Empty return Boolean is 
  34.         (Queue.Is_Empty); 
  35.  
  36.       function Is_Full return Boolean is 
  37.         (not Queue.Is_Empty and then Queue.Top = Queue.Free); 
  38.  
  39.    end Protected_Queue; 
  40. end Queue_Pack_Protected_Generic;