------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Cheddar is a GNU GPL real-time scheduling analysis tool. -- This program provides services to automatically check schedulability and -- other performance criteria of real-time architecture models. -- -- Copyright (C) 2002-2020, Frank Singhoff, Alain Plantec, Jerome Legrand, -- Hai Nam Tran, Stephane Rubini -- -- The Cheddar project was started in 2002 by -- Frank Singhoff, Lab-STICC UMR 6285, Université de Bretagne Occidentale -- -- Cheddar has been published in the "Agence de Protection des Programmes/France" in 2008. -- Since 2008, Ellidiss technologies also contributes to the development of -- Cheddar and provides industrial support. -- -- The full list of contributors and sponsors can be found in AUTHORS.txt and SPONSORS.txt -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- -- -- Contact : cheddar@listes.univ-brest.fr -- ------------------------------------------------------------------------------ -- Last update : -- $Rev$ -- $Date$ -- $Author: singhoff $ ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with Text_IO; use Text_IO; package body fifos is procedure reset (my_fifo : in out fifo) is begin my_fifo.queue := 0; my_fifo.head := 0; my_fifo.size := 0; end reset; procedure put (my_fifo : in fifo) is index : element_range := my_fifo.queue; begin Put_Line ("Fifo : queue = " & my_fifo.queue'img & "; head = " & my_fifo.head'img & "; size = " & my_fifo.size'img); while (index /= my_fifo.head) loop put (my_fifo.data (index)); New_Line; if (index = element_range'last) then index := element_range'first; else index := index + 1; end if; end loop; New_Line; New_Line; end put; procedure insert (my_fifo : in out fifo; e : in element) is tmp : element_range; begin if (my_fifo.head = element_range'last) then tmp := element_range'first; else tmp := my_fifo.head + 1; end if; if (my_fifo.queue = tmp) then raise full_fifo; end if; my_fifo.data (my_fifo.head) := e; if (my_fifo.head = element_range'last) then my_fifo.head := element_range'first; else my_fifo.head := my_fifo.head + 1; end if; my_fifo.size := my_fifo.size + 1; end insert; procedure extract (my_fifo : in out fifo; e : in out element) is begin if is_empty (my_fifo) then raise empty_fifo; end if; e := my_fifo.data (my_fifo.queue); if (my_fifo.queue = element_range'last) then my_fifo.queue := element_range'first; else my_fifo.queue := my_fifo.queue + 1; end if; my_fifo.size := my_fifo.size - 1; end extract; procedure extract_any_where (my_fifo : in out fifo; e : in element) is index : element_range := my_fifo.queue; begin if is_empty (my_fifo) then raise empty_fifo; end if; -- Looking for the element -- while (index /= my_fifo.head) loop if e = my_fifo.data (index) then while index /= my_fifo.head loop if index = element_range'last then my_fifo.data (index) := my_fifo.data (element_range'first); else my_fifo.data (index) := my_fifo.data (index + 1); end if; if (index = element_range'last) then index := element_range'first; else index := index + 1; end if; end loop; if (my_fifo.head = element_range'first) then my_fifo.head := element_range'last; else my_fifo.head := my_fifo.head - 1; end if; my_fifo.size := my_fifo.size - 1; return; end if; if (index = element_range'last) then index := element_range'first; else index := index + 1; end if; end loop; raise element_not_found; end extract_any_where; function consult (my_fifo : in fifo) return element is begin if is_empty (my_fifo) then raise empty_fifo; end if; return (my_fifo.data (my_fifo.queue)); end consult; function is_empty (my_fifo : in fifo) return Boolean is begin return (my_fifo.queue = my_fifo.head); end is_empty; function get_size (my_fifo : in fifo) return Natural is begin return (my_fifo.size); end get_size; end fifos;