1. -- 
  2. -- Uwe R. Zimmer, Australia, 2013 
  3. -- 
  4.  
  5. package body Queues_Pack_Protected_Ordered_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) := (Elem => Item, Reads => None_Read); 
  13.          Queue.Free := (Queue.Free + 1) mod Queue_Size; 
  14.       end Enqueue; 
  15.  
  16.       entry Dequeue (for Q in Queue_Enum) (Item : out Element) 
  17.       when not Is_Empty (Q) 
  18.         and then (Q = Queue_Enum'Last 
  19.                   or else (for all Higher in Queue_Enum'Succ (Q) .. Queue_Enum'Last 
  20.                             => Dequeue (Higher)'Count = 0 or else Is_Empty (Higher))) 
  21.         and then (Enqueue'Count = 0 or else Is_Full) is 
  22.  
  23.       begin 
  24.          Item := Queue.Elements (Queue.Readers (Q)).Elem; 
  25.          Queue.Elements (Queue.Readers (Q)).Reads (Q) := True; 
  26.          Queue.Readers (Q) := (Queue.Readers (Q) + 1) mod Queue_Size; 
  27.       end Dequeue; 
  28.  
  29.       function Is_Empty (Q : Queue_Enum) return Boolean is 
  30.         (Queue.Elements (Queue.Readers (Q)).Reads (Q)); 
  31.  
  32.       function Is_Full return Boolean is 
  33.         (Queue.Elements (Queue.Free).Reads /= All_Read); 
  34.  
  35.    end Protected_Queue; 
  36. end Queues_Pack_Protected_Ordered_Generic;