1 | /* semaphore.h |
---|
2 | * |
---|
3 | * This include file contains all the constants and structures associated |
---|
4 | * with the Semaphore Manager. This manager utilizes standard Dijkstra |
---|
5 | * counting semaphores to provide synchronization and mutual exclusion |
---|
6 | * capabilities. |
---|
7 | * |
---|
8 | * Directives provided are: |
---|
9 | * |
---|
10 | * + create a semaphore |
---|
11 | * + get an ID of a semaphore |
---|
12 | * + delete a semaphore |
---|
13 | * + acquire a semaphore |
---|
14 | * + release a semaphore |
---|
15 | * |
---|
16 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
17 | * On-Line Applications Research Corporation (OAR). |
---|
18 | * All rights assigned to U.S. Government, 1994. |
---|
19 | * |
---|
20 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
21 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
22 | * notice must appear in all copies of this file and its derivatives. |
---|
23 | * |
---|
24 | * $Id$ |
---|
25 | */ |
---|
26 | |
---|
27 | #ifndef __RTEMS_SEMAPHORE_h |
---|
28 | #define __RTEMS_SEMAPHORE_h |
---|
29 | |
---|
30 | #ifdef __cplusplus |
---|
31 | extern "C" { |
---|
32 | #endif |
---|
33 | |
---|
34 | #include <rtems.h> |
---|
35 | #include <rtems/attr.h> |
---|
36 | #include <rtems/object.h> |
---|
37 | #include <rtems/threadq.h> |
---|
38 | |
---|
39 | /* |
---|
40 | * The following defines the control block used to manage each semaphore. |
---|
41 | */ |
---|
42 | |
---|
43 | typedef struct { |
---|
44 | Objects_Control Object; |
---|
45 | Thread_queue_Control Wait_queue; |
---|
46 | rtems_attribute attribute_set; |
---|
47 | unsigned32 count; |
---|
48 | unsigned32 nest_count; |
---|
49 | Thread_Control *holder; |
---|
50 | Objects_Id holder_id; |
---|
51 | } Semaphore_Control; |
---|
52 | |
---|
53 | /* |
---|
54 | * The following defines the information control block used to manage |
---|
55 | * this class of objects. |
---|
56 | */ |
---|
57 | |
---|
58 | EXTERN Objects_Information _Semaphore_Information; |
---|
59 | |
---|
60 | /* |
---|
61 | * _Semaphore_Manager_initialization |
---|
62 | * |
---|
63 | * DESCRIPTION: |
---|
64 | * |
---|
65 | * This routine performs the initialization necessary for this manager. |
---|
66 | */ |
---|
67 | |
---|
68 | void _Semaphore_Manager_initialization( |
---|
69 | unsigned32 maximum_semaphores |
---|
70 | ); |
---|
71 | |
---|
72 | /* |
---|
73 | * rtems_semaphore_create |
---|
74 | * |
---|
75 | * DESCRIPTION: |
---|
76 | * |
---|
77 | * This routine implements the rtems_semaphore_create directive. The |
---|
78 | * semaphore will have the name name. The starting count for |
---|
79 | * the semaphore is count. The attribute_set determines if |
---|
80 | * the semaphore is global or local and the thread queue |
---|
81 | * discipline. It returns the id of the created semaphore in ID. |
---|
82 | */ |
---|
83 | |
---|
84 | rtems_status_code rtems_semaphore_create( |
---|
85 | rtems_name name, |
---|
86 | unsigned32 count, |
---|
87 | rtems_attribute attribute_set, |
---|
88 | Objects_Id *id |
---|
89 | ); |
---|
90 | |
---|
91 | /* |
---|
92 | * rtems_semaphore_ident |
---|
93 | * |
---|
94 | * DESCRIPTION: |
---|
95 | * |
---|
96 | * This routine implements the rtems_semaphore_ident directive. |
---|
97 | * This directive returns the semaphore ID associated with name. |
---|
98 | * If more than one semaphore is named name, then the semaphore |
---|
99 | * to which the ID belongs is arbitrary. node indicates the |
---|
100 | * extent of the search for the ID of the semaphore named name. |
---|
101 | * The search can be limited to a particular node or allowed to |
---|
102 | * encompass all nodes. |
---|
103 | */ |
---|
104 | |
---|
105 | rtems_status_code rtems_semaphore_ident( |
---|
106 | rtems_name name, |
---|
107 | unsigned32 node, |
---|
108 | Objects_Id *id |
---|
109 | ); |
---|
110 | |
---|
111 | /* |
---|
112 | * rtems_semaphore_delete |
---|
113 | * |
---|
114 | * DESCRIPTION: |
---|
115 | * |
---|
116 | * This routine implements the rtems_semaphore_delete directive. The |
---|
117 | * semaphore indicated by ID is deleted. |
---|
118 | */ |
---|
119 | |
---|
120 | rtems_status_code rtems_semaphore_delete( |
---|
121 | Objects_Id id |
---|
122 | ); |
---|
123 | |
---|
124 | /* |
---|
125 | * rtems_semaphore_obtain |
---|
126 | * |
---|
127 | * DESCRIPTION: |
---|
128 | * |
---|
129 | * This routine implements the rtems_semaphore_obtain directive. It |
---|
130 | * attempts to obtain a unit from the semaphore associated with ID. |
---|
131 | * If a unit can be allocated, the calling task will return immediately. |
---|
132 | * If no unit is available, then the task may return immediately or |
---|
133 | * block waiting for a unit with an optional timeout of timeout |
---|
134 | * clock ticks. Whether the task blocks or returns immediately |
---|
135 | * is based on the RTEMS_NO_WAIT option in the option_set. |
---|
136 | */ |
---|
137 | |
---|
138 | rtems_status_code rtems_semaphore_obtain( |
---|
139 | Objects_Id id, |
---|
140 | unsigned32 option_set, |
---|
141 | rtems_interval timeout |
---|
142 | ); |
---|
143 | |
---|
144 | /* |
---|
145 | * rtems_semaphore_release |
---|
146 | * |
---|
147 | * DESCRIPTION: |
---|
148 | * |
---|
149 | * This routine implements the rtems_semaphore_release directive. It |
---|
150 | * frees a unit to the semaphore associated with ID. If a task was |
---|
151 | * blocked waiting for a unit from this semaphore, then that task will |
---|
152 | * be readied and the unit given to that task. Otherwise, the unit |
---|
153 | * will be returned to the semaphore. |
---|
154 | */ |
---|
155 | |
---|
156 | rtems_status_code rtems_semaphore_release( |
---|
157 | Objects_Id id |
---|
158 | ); |
---|
159 | |
---|
160 | /* |
---|
161 | * _Semaphore_Seize |
---|
162 | * |
---|
163 | * DESCRIPTION: |
---|
164 | * |
---|
165 | * This routine attempts to receive a unit from the_semaphore. |
---|
166 | * If a unit is available or if the RTEMS_NO_WAIT option is enabled in |
---|
167 | * option_set, then the routine returns. Otherwise, the calling task |
---|
168 | * is blocked until a unit becomes available. |
---|
169 | */ |
---|
170 | |
---|
171 | boolean _Semaphore_Seize( |
---|
172 | Semaphore_Control *the_semaphore, |
---|
173 | unsigned32 option_set |
---|
174 | ); |
---|
175 | |
---|
176 | /* |
---|
177 | * _Semaphore_Allocate |
---|
178 | * |
---|
179 | * DESCRIPTION: |
---|
180 | * |
---|
181 | * This function allocates a semaphore control block from |
---|
182 | * the inactive chain of free semaphore control blocks. |
---|
183 | */ |
---|
184 | |
---|
185 | STATIC INLINE Semaphore_Control *_Semaphore_Allocate( void ); |
---|
186 | |
---|
187 | /* |
---|
188 | * _Semaphore_Free |
---|
189 | * |
---|
190 | * DESCRIPTION: |
---|
191 | * |
---|
192 | * This routine frees a semaphore control block to the |
---|
193 | * inactive chain of free semaphore control blocks. |
---|
194 | */ |
---|
195 | |
---|
196 | STATIC INLINE void _Semaphore_Free ( |
---|
197 | Semaphore_Control *the_semaphore |
---|
198 | ); |
---|
199 | |
---|
200 | /* |
---|
201 | * _Semaphore_Get |
---|
202 | * |
---|
203 | * DESCRIPTION: |
---|
204 | * |
---|
205 | * This function maps semaphore IDs to semaphore control blocks. |
---|
206 | * If ID corresponds to a local semaphore, then it returns |
---|
207 | * the_semaphore control pointer which maps to ID and location |
---|
208 | * is set to OBJECTS_LOCAL. if the semaphore ID is global and |
---|
209 | * resides on a remote node, then location is set to OBJECTS_REMOTE, |
---|
210 | * and the_semaphore is undefined. Otherwise, location is set |
---|
211 | * to OBJECTS_ERROR and the_semaphore is undefined. |
---|
212 | */ |
---|
213 | |
---|
214 | STATIC INLINE Semaphore_Control *_Semaphore_Get ( |
---|
215 | Objects_Id id, |
---|
216 | Objects_Locations *location |
---|
217 | ); |
---|
218 | |
---|
219 | /* |
---|
220 | * _Semaphore_Is_null |
---|
221 | * |
---|
222 | * DESCRIPTION: |
---|
223 | * |
---|
224 | * This function returns TRUE if the_semaphore is NULL and FALSE otherwise. |
---|
225 | */ |
---|
226 | |
---|
227 | STATIC INLINE boolean _Semaphore_Is_null ( |
---|
228 | Semaphore_Control *the_semaphore |
---|
229 | ); |
---|
230 | |
---|
231 | #include <rtems/sem.inl> |
---|
232 | #include <rtems/semmp.h> |
---|
233 | |
---|
234 | #ifdef __cplusplus |
---|
235 | } |
---|
236 | #endif |
---|
237 | |
---|
238 | #endif |
---|
239 | /* end of include file */ |
---|