]>
Commit | Line | Data |
---|---|---|
fbf5a39b AC |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT LIBRARY COMPONENTS -- | |
4 | -- -- | |
5 | -- G N A T . S E M A P H O R E S -- | |
6 | -- -- | |
7 | -- S p e c -- | |
8 | -- -- | |
4b490c1e | 9 | -- Copyright (C) 2003-2020, AdaCore -- |
fbf5a39b AC |
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- -- | |
607d0635 | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
fbf5a39b AC |
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 -- | |
607d0635 AC |
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/>. -- | |
fbf5a39b AC |
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 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. | |
35 | ||
36 | with System; | |
37 | ||
38 | package GNAT.Semaphores is | |
39 | ||
40 | Default_Ceiling : constant System.Priority := System.Default_Priority; | |
a2cb348e | 41 | -- A convenient value for the priority discriminants that follow |
fbf5a39b AC |
42 | |
43 | ------------------------ | |
44 | -- Counting_Semaphore -- | |
45 | ------------------------ | |
46 | ||
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. | |
51 | ||
52 | Ceiling : System.Priority) | |
a2cb348e RD |
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. | |
fbf5a39b AC |
55 | is |
56 | pragma Priority (Ceiling); | |
57 | ||
58 | entry Seize; | |
a2cb348e RD |
59 | -- Blocks caller until/unless the semaphore's internal counter is |
60 | -- greater than zero. Decrements the semaphore's internal counter when | |
61 | -- executed. | |
fbf5a39b AC |
62 | |
63 | procedure Release; | |
a2cb348e | 64 | -- Increments the semaphore's internal counter |
fbf5a39b AC |
65 | |
66 | private | |
67 | Count : Natural := Initial_Value; | |
68 | end Counting_Semaphore; | |
69 | ||
70 | ---------------------- | |
71 | -- Binary_Semaphore -- | |
72 | ---------------------- | |
73 | ||
74 | protected type Binary_Semaphore | |
a2cb348e RD |
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. | |
79 | ||
fbf5a39b | 80 | Ceiling : System.Priority) |
a2cb348e RD |
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. | |
fbf5a39b AC |
83 | is |
84 | pragma Priority (Ceiling); | |
85 | ||
86 | entry Seize; | |
a2cb348e RD |
87 | -- Blocks the caller unless/until semaphore is available. After |
88 | -- execution the semaphore is no longer available. | |
fbf5a39b AC |
89 | |
90 | procedure Release; | |
a2cb348e | 91 | -- Makes the semaphore available |
fbf5a39b AC |
92 | |
93 | private | |
94 | Available : Boolean := Initially_Available; | |
95 | end Binary_Semaphore; | |
96 | ||
97 | end GNAT.Semaphores; |