1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT LIBRARY COMPONENTS                          --
4--                                                                          --
5--                 G N A T . B O U N D E D _ M A I L B O X E 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------------------------------------------------------------------------------
31
32--  This package provides a thread-safe asynchronous communication facility
33--  in the form of mailboxes. Individual mailbox objects are bounded in size
34--  to a value specified by their Capacity discriminants.
35
36--  Mailboxes actually hold references to messages, not the message values
37--  themselves.
38
39--  Type Mailbox is defined explicitly as a protected type (via derivation
40--  from a protected type) so that clients may treat them accordingly (for
41--  example, by making conditional/timed entry calls).
42
43with System;
44with GNAT.Bounded_Buffers;
45
46generic
47   type Message (<>) is limited private;
48   type Message_Reference is access all Message;
49   --  Mailboxes hold references to Message values, of this type
50
51package GNAT.Bounded_Mailboxes is
52   pragma Preelaborate;
53
54   package Message_Refs is
55      new GNAT.Bounded_Buffers (Message_Reference);
56
57   type Mailbox is new Message_Refs.Bounded_Buffer;
58
59   --  Type Mailbox has two inherited discriminants:
60
61   --  Capacity : Positive;
62   --     Capacity is the maximum number of Message references
63   --     possibly contained at any given instant.
64
65   --  Ceiling : System.Priority;
66   --     Users must specify the ceiling priority for the object.
67   --     If the Real-Time Systems Annex is not in use this value
68   --     is not important.
69
70   --  Protected type Mailbox has the following inherited interface:
71
72   --  entry Insert (Item : Message_Reference);
73   --     Insert Item into the Mailbox. Blocks caller
74   --     until space is available.
75
76   --  entry Remove (Item : out Message_Reference);
77   --     Remove next available Message_Reference from Mailbox.
78   --     Blocks caller until a Message_Reference is available.
79
80   --  function Empty return Boolean;
81   --     Returns whether the Mailbox contains any Message_References.
82   --     Note: State may change immediately after call returns.
83
84   --  function Full return Boolean;
85   --     Returns whether any space remains within the Mailbox.
86   --     Note: State may change immediately after call returns.
87
88   --  function Extent return Natural;
89   --     Returns the number of Message_Reference values currently held
90   --     within the Mailbox.
91   --     Note: State may change immediately after call returns.
92
93   Default_Ceiling : constant System.Priority := Message_Refs.Default_Ceiling;
94   --  A convenience value for the Ceiling discriminant
95
96end GNAT.Bounded_Mailboxes;
97