1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- G N A T . S E M A P H O R E S --
9 -- Copyright (C) 2003-2010, AdaCore --
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. --
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. --
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/>. --
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). --
30 ------------------------------------------------------------------------------
32 -- This package provides classic counting semaphores and binary semaphores.
33 -- Both types are visibly defined as protected types so that users can make
34 -- conditional and timed calls when appropriate.
38 package GNAT.Semaphores is
40 Default_Ceiling : constant System.Priority := System.Default_Priority;
41 -- A convenient value for the priority discriminants that follow
43 ------------------------
44 -- Counting_Semaphore --
45 ------------------------
47 protected type Counting_Semaphore
48 (Initial_Value : Natural;
49 -- A counting semaphore contains an internal counter. The initial
50 -- value of this counter is set by clients via the discriminant.
52 Ceiling : System.Priority)
53 -- Users must specify the ceiling priority for the object. If the
54 -- Real-Time Systems Annex is not in use this value is not important.
56 pragma Priority (Ceiling);
59 -- Blocks caller until/unless the semaphore's internal counter is
60 -- greater than zero. Decrements the semaphore's internal counter when
64 -- Increments the semaphore's internal counter
67 Count : Natural := Initial_Value;
68 end Counting_Semaphore;
70 ----------------------
71 -- Binary_Semaphore --
72 ----------------------
74 protected type Binary_Semaphore
75 (Initially_Available : Boolean;
76 -- Binary semaphores are either available or not; there is no internal
77 -- count involved. The discriminant value determines whether the
78 -- individual object is initially available.
80 Ceiling : System.Priority)
81 -- Users must specify the ceiling priority for the object. If the
82 -- Real-Time Systems Annex is not in use this value is not important.
84 pragma Priority (Ceiling);
87 -- Blocks the caller unless/until semaphore is available. After
88 -- execution the semaphore is no longer available.
91 -- Makes the semaphore available
94 Available : Boolean := Initially_Available;