2015-05-05 Yvan Roux <yvan.roux@linaro.org>
[official-gcc.git] / gcc / ada / g-boubuf.ads
blobf94641ff620987a649fa637139d6fa45e49d3fc3
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- G N A T . B O U N D E D _ B U F F E R S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2003-2010, 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 was originally developed by the GNAT team at New York University. --
28 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
29 -- --
30 ------------------------------------------------------------------------------
32 -- This package provides a thread-safe generic bounded buffer abstraction.
33 -- Instances are useful directly or as parts of the implementations of other
34 -- abstractions, such as mailboxes.
36 -- Bounded_Buffer is declared explicitly as a protected type, rather than as
37 -- a simple limited private type completed as a protected type, so that
38 -- clients may make calls accordingly (i.e., conditional/timed entry calls).
40 with System;
42 generic
43 type Element is private;
44 -- The type of the values contained within buffer objects
46 package GNAT.Bounded_Buffers is
47 pragma Pure;
49 type Content is array (Positive range <>) of Element;
50 -- Content is an internal artefact that cannot be hidden because protected
51 -- types cannot contain type declarations.
53 Default_Ceiling : constant System.Priority := System.Default_Priority;
54 -- A convenience value for the Ceiling discriminant
56 protected type Bounded_Buffer
57 (Capacity : Positive;
58 -- Objects of type Bounded_Buffer specify the maximum number of Element
59 -- values they can hold via the discriminant Capacity.
61 Ceiling : System.Priority)
62 -- Users must specify the ceiling priority for the object. If the
63 -- Real-Time Systems Annex is not in use this value is not important.
65 pragma Priority (Ceiling);
67 entry Insert (Item : Element);
68 -- Insert Item into the buffer, blocks caller until space is available
70 entry Remove (Item : out Element);
71 -- Remove next available Element from buffer. Blocks caller until an
72 -- Element is available.
74 function Empty return Boolean;
75 -- Returns whether the instance contains any Elements.
76 -- Note: State may change immediately after call returns.
78 function Full return Boolean;
79 -- Returns whether any space remains within the instance.
80 -- Note: State may change immediately after call returns.
82 function Extent return Natural;
83 -- Returns the number of Element values currently held
84 -- within the instance.
85 -- Note: State may change immediately after call returns.
87 private
88 Values : Content (1 .. Capacity);
89 -- The container for the values held by the buffer instance
91 Next_In : Positive := 1;
92 -- The index of the next Element inserted. Wraps around
94 Next_Out : Positive := 1;
95 -- The index of the next Element removed. Wraps around
97 Count : Natural := 0;
98 -- The number of Elements currently held
99 end Bounded_Buffer;
101 end GNAT.Bounded_Buffers;