1. -- 
  2. --  Copyright (c) 2009, 
  3. --  Reto Buerki, Adrian-Ken Rueegsegger 
  4. -- 
  5. --  This file is part of Alog. 
  6. -- 
  7. --  Alog is free software; you can redistribute it and/or modify 
  8. --  it under the terms of the GNU Lesser General Public License as published 
  9. --  by the Free Software Foundation; either version 2.1 of the License, or 
  10. --  (at your option) any later version. 
  11. -- 
  12. --  Alog is distributed in the hope that it will be useful, 
  13. --  but WITHOUT ANY WARRANTY; without even the implied warranty of 
  14. --  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  15. --  GNU Lesser General Public License for more details. 
  16. -- 
  17. --  You should have received a copy of the GNU Lesser General Public License 
  18. --  along with Alog; if not, write to the Free Software 
  19. --  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 
  20. --  MA  02110-1301  USA 
  21. -- 
  22.  
  23. with Ada.Containers.Doubly_Linked_Lists; 
  24.  
  25. with Alog.Log_Request; 
  26.  
  27. --  Alog Protected Containers. This package provides protected containers which 
  28. --  are safe for concurrent access. 
  29. package Alog.Protected_Containers is 
  30.  
  31.    ---------------------- 
  32.    -- Log_Request_List -- 
  33.    ---------------------- 
  34.  
  35.    type Log_Request_Storage is private; 
  36.  
  37.    protected type Log_Request_List is 
  38.  
  39.       procedure Put (Element : Log_Request.Instance); 
  40.       --  Put an element at the end of the request list. 
  41.  
  42.       entry Get (Element : out Log_Request.Instance); 
  43.       --  Get the first element from the list (and delete it). 
  44.  
  45.       procedure Done; 
  46.       --  Signal successfull processing of request previously gotten from list. 
  47.  
  48.       entry All_Done; 
  49.       --  This procedure blocks until the list is empty and there are no 
  50.       --  pending requests. A requests is pending when it is taken off the list 
  51.       --  via Get but it's successfull processing has not been signaled back 
  52.       --  via the procedure Done. 
  53.  
  54.       procedure Clear; 
  55.       --  Clear the request list by deleting all log requests. 
  56.  
  57.       function Length return Natural; 
  58.       --  Return the number of elements in the list. 
  59.  
  60.       function Pending return Natural; 
  61.       --  Return the number of pending requests. 
  62.  
  63.    private 
  64.  
  65.       Requests           : Log_Request_Storage; 
  66.       Requests_Available : Boolean := False; 
  67.       Pending_Counter    : Natural := 0; 
  68.  
  69.    end Log_Request_List; 
  70.    --  Protected variant of a log request list. This list holds log request 
  71.    --  objects and is safe for concurrent access. It operates in FIFO-Mode. 
  72.  
  73. private 
  74.  
  75.    use type Alog.Log_Request.Instance; 
  76.  
  77.    package List_Of_Log_Requests_Package is 
  78.      new Ada.Containers.Doubly_Linked_Lists 
  79.        (Element_Type => Log_Request.Instance); 
  80.  
  81.    package LOLRP renames List_Of_Log_Requests_Package; 
  82.  
  83.    type Log_Request_Storage is new LOLRP.List with null record; 
  84.  
  85. end Alog.Protected_Containers;