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 | * sem.h,v 1.2 1995/05/31 16:47:13 joel Exp |
---|
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/attr.h> |
---|
35 | #include <rtems/object.h> |
---|
36 | #include <rtems/threadq.h> |
---|
37 | |
---|
38 | /* |
---|
39 | * The following defines the control block used to manage each semaphore. |
---|
40 | */ |
---|
41 | |
---|
42 | typedef struct { |
---|
43 | Objects_Control Object; |
---|
44 | Thread_queue_Control Wait_queue; |
---|
45 | rtems_attribute attribute_set; |
---|
46 | unsigned32 count; |
---|
47 | unsigned32 nest_count; |
---|
48 | Thread_Control *holder; |
---|
49 | Objects_Id holder_id; |
---|
50 | } Semaphore_Control; |
---|
51 | |
---|
52 | /* |
---|
53 | * The following defines the information control block used to manage |
---|
54 | * this class of objects. |
---|
55 | */ |
---|
56 | |
---|
57 | EXTERN Objects_Information _Semaphore_Information; |
---|
58 | |
---|
59 | /* |
---|
60 | * _Semaphore_Manager_initialization |
---|
61 | * |
---|
62 | * DESCRIPTION: |
---|
63 | * |
---|
64 | * This routine performs the initialization necessary for this manager. |
---|
65 | */ |
---|
66 | |
---|
67 | void _Semaphore_Manager_initialization( |
---|
68 | unsigned32 maximum_semaphores |
---|
69 | ); |
---|
70 | |
---|
71 | /* |
---|
72 | * rtems_semaphore_create |
---|
73 | * |
---|
74 | * DESCRIPTION: |
---|
75 | * |
---|
76 | * This routine implements the rtems_semaphore_create directive. The |
---|
77 | * semaphore will have the name name. The starting count for |
---|
78 | * the semaphore is count. The attribute_set determines if |
---|
79 | * the semaphore is global or local and the thread queue |
---|
80 | * discipline. It returns the id of the created semaphore in ID. |
---|
81 | */ |
---|
82 | |
---|
83 | rtems_status_code rtems_semaphore_create( |
---|
84 | Objects_Name name, |
---|
85 | unsigned32 count, |
---|
86 | rtems_attribute attribute_set, |
---|
87 | Objects_Id *id |
---|
88 | ); |
---|
89 | |
---|
90 | /* |
---|
91 | * rtems_semaphore_ident |
---|
92 | * |
---|
93 | * DESCRIPTION: |
---|
94 | * |
---|
95 | * This routine implements the rtems_semaphore_ident directive. |
---|
96 | * This directive returns the semaphore ID associated with name. |
---|
97 | * If more than one semaphore is named name, then the semaphore |
---|
98 | * to which the ID belongs is arbitrary. node indicates the |
---|
99 | * extent of the search for the ID of the semaphore named name. |
---|
100 | * The search can be limited to a particular node or allowed to |
---|
101 | * encompass all nodes. |
---|
102 | */ |
---|
103 | |
---|
104 | rtems_status_code rtems_semaphore_ident( |
---|
105 | Objects_Name name, |
---|
106 | unsigned32 node, |
---|
107 | Objects_Id *id |
---|
108 | ); |
---|
109 | |
---|
110 | /* |
---|
111 | * rtems_semaphore_delete |
---|
112 | * |
---|
113 | * DESCRIPTION: |
---|
114 | * |
---|
115 | * This routine implements the rtems_semaphore_delete directive. The |
---|
116 | * semaphore indicated by ID is deleted. |
---|
117 | */ |
---|
118 | |
---|
119 | rtems_status_code rtems_semaphore_delete( |
---|
120 | Objects_Id id |
---|
121 | ); |
---|
122 | |
---|
123 | /* |
---|
124 | * rtems_semaphore_obtain |
---|
125 | * |
---|
126 | * DESCRIPTION: |
---|
127 | * |
---|
128 | * This routine implements the rtems_semaphore_obtain directive. It |
---|
129 | * attempts to obtain a unit from the semaphore associated with ID. |
---|
130 | * If a unit can be allocated, the calling task will return immediately. |
---|
131 | * If no unit is available, then the task may return immediately or |
---|
132 | * block waiting for a unit with an optional timeout of timeout |
---|
133 | * clock ticks. Whether the task blocks or returns immediately |
---|
134 | * is based on the RTEMS_NO_WAIT option in the option_set. |
---|
135 | */ |
---|
136 | |
---|
137 | rtems_status_code rtems_semaphore_obtain( |
---|
138 | Objects_Id id, |
---|
139 | unsigned32 option_set, |
---|
140 | rtems_interval timeout |
---|
141 | ); |
---|
142 | |
---|
143 | /* |
---|
144 | * rtems_semaphore_release |
---|
145 | * |
---|
146 | * DESCRIPTION: |
---|
147 | * |
---|
148 | * This routine implements the rtems_semaphore_release directive. It |
---|
149 | * frees a unit to the semaphore associated with ID. If a task was |
---|
150 | * blocked waiting for a unit from this semaphore, then that task will |
---|
151 | * be readied and the unit given to that task. Otherwise, the unit |
---|
152 | * will be returned to the semaphore. |
---|
153 | */ |
---|
154 | |
---|
155 | rtems_status_code rtems_semaphore_release( |
---|
156 | Objects_Id id |
---|
157 | ); |
---|
158 | |
---|
159 | /* |
---|
160 | * _Semaphore_Seize |
---|
161 | * |
---|
162 | * DESCRIPTION: |
---|
163 | * |
---|
164 | * This routine attempts to receive a unit from the_semaphore. |
---|
165 | * If a unit is available or if the RTEMS_NO_WAIT option is enabled in |
---|
166 | * option_set, then the routine returns. Otherwise, the calling task |
---|
167 | * is blocked until a unit becomes available. |
---|
168 | */ |
---|
169 | |
---|
170 | boolean _Semaphore_Seize( |
---|
171 | Semaphore_Control *the_semaphore, |
---|
172 | unsigned32 option_set |
---|
173 | ); |
---|
174 | |
---|
175 | /* |
---|
176 | * _Semaphore_Allocate |
---|
177 | * |
---|
178 | * DESCRIPTION: |
---|
179 | * |
---|
180 | * This function allocates a semaphore control block from |
---|
181 | * the inactive chain of free semaphore control blocks. |
---|
182 | */ |
---|
183 | |
---|
184 | STATIC INLINE Semaphore_Control *_Semaphore_Allocate( void ); |
---|
185 | |
---|
186 | /* |
---|
187 | * _Semaphore_Free |
---|
188 | * |
---|
189 | * DESCRIPTION: |
---|
190 | * |
---|
191 | * This routine frees a semaphore control block to the |
---|
192 | * inactive chain of free semaphore control blocks. |
---|
193 | */ |
---|
194 | |
---|
195 | STATIC INLINE void _Semaphore_Free ( |
---|
196 | Semaphore_Control *the_semaphore |
---|
197 | ); |
---|
198 | |
---|
199 | /* |
---|
200 | * _Semaphore_Get |
---|
201 | * |
---|
202 | * DESCRIPTION: |
---|
203 | * |
---|
204 | * This function maps semaphore IDs to semaphore control blocks. |
---|
205 | * If ID corresponds to a local semaphore, then it returns |
---|
206 | * the_semaphore control pointer which maps to ID and location |
---|
207 | * is set to OBJECTS_LOCAL. if the semaphore ID is global and |
---|
208 | * resides on a remote node, then location is set to OBJECTS_REMOTE, |
---|
209 | * and the_semaphore is undefined. Otherwise, location is set |
---|
210 | * to OBJECTS_ERROR and the_semaphore is undefined. |
---|
211 | */ |
---|
212 | |
---|
213 | STATIC INLINE Semaphore_Control *_Semaphore_Get ( |
---|
214 | Objects_Id id, |
---|
215 | Objects_Locations *location |
---|
216 | ); |
---|
217 | |
---|
218 | /* |
---|
219 | * _Semaphore_Is_null |
---|
220 | * |
---|
221 | * DESCRIPTION: |
---|
222 | * |
---|
223 | * This function returns TRUE if the_semaphore is NULL and FALSE otherwise. |
---|
224 | */ |
---|
225 | |
---|
226 | STATIC INLINE boolean _Semaphore_Is_null ( |
---|
227 | Semaphore_Control *the_semaphore |
---|
228 | ); |
---|
229 | |
---|
230 | #include <rtems/sem.inl> |
---|
231 | #include <rtems/semmp.h> |
---|
232 | |
---|
233 | #ifdef __cplusplus |
---|
234 | } |
---|
235 | #endif |
---|
236 | |
---|
237 | #endif |
---|
238 | /* end of include file */ |
---|