1------------------------------------------------------------------------------ 2-- -- 3-- GNAT COMPILER COMPONENTS -- 4-- -- 5-- G N A T . B O U N D E D _ B U F F E R S -- 6-- -- 7-- B o d y -- 8-- -- 9-- Copyright (C) 2003-2019, AdaCore -- 10-- -- 11-- GNAT is free software; you can redistribute it and/or modify it under -- 12-- terms of the GNU General Public License as published by the Free Soft- -- 13-- ware Foundation; either version 3, or (at your option) any later ver- -- 14-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- 15-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- 16-- or FITNESS FOR A PARTICULAR PURPOSE. -- 17-- -- 18-- As a special exception under Section 7 of GPL version 3, you are granted -- 19-- additional permissions described in the GCC Runtime Library Exception, -- 20-- version 3.1, as published by the Free Software Foundation. -- 21-- -- 22-- You should have received a copy of the GNU General Public License and -- 23-- a copy of the GCC Runtime Library Exception along with this program; -- 24-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- 25-- <http://www.gnu.org/licenses/>. -- 26-- -- 27-- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). -- 28-- -- 29------------------------------------------------------------------------------ 30 31package body GNAT.Bounded_Buffers is 32 33 -------------------- 34 -- Bounded_Buffer -- 35 -------------------- 36 37 protected body Bounded_Buffer is 38 39 ------------ 40 -- Insert -- 41 ------------ 42 43 entry Insert (Item : Element) when Count /= Capacity is 44 begin 45 Values (Next_In) := Item; 46 Next_In := (Next_In mod Capacity) + 1; 47 Count := Count + 1; 48 end Insert; 49 50 ------------ 51 -- Remove -- 52 ------------ 53 54 entry Remove (Item : out Element) when Count > 0 is 55 begin 56 Item := Values (Next_Out); 57 Next_Out := (Next_Out mod Capacity) + 1; 58 Count := Count - 1; 59 end Remove; 60 61 ----------- 62 -- Empty -- 63 ----------- 64 65 function Empty return Boolean is 66 begin 67 return Count = 0; 68 end Empty; 69 70 ---------- 71 -- Full -- 72 ---------- 73 74 function Full return Boolean is 75 begin 76 return Count = Capacity; 77 end Full; 78 79 ------------ 80 -- Extent -- 81 ------------ 82 83 function Extent return Natural is 84 begin 85 return Count; 86 end Extent; 87 88 end Bounded_Buffer; 89 90end GNAT.Bounded_Buffers; 91