1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup ClassicSem |
---|
5 | * |
---|
6 | * @brief Classic Semaphores API |
---|
7 | * |
---|
8 | * This include file contains all the constants and structures associated |
---|
9 | * with the Semaphore Manager. This manager utilizes standard Dijkstra |
---|
10 | * counting semaphores to provide synchronization and mutual exclusion |
---|
11 | * capabilities. |
---|
12 | * |
---|
13 | * Directives provided are: |
---|
14 | * |
---|
15 | * - create a semaphore |
---|
16 | * - get an ID of a semaphore |
---|
17 | * - delete a semaphore |
---|
18 | * - acquire a semaphore |
---|
19 | * - release a semaphore |
---|
20 | * - flush a semaphore |
---|
21 | * - set ceiling priority for a semaphore |
---|
22 | */ |
---|
23 | |
---|
24 | /* |
---|
25 | * COPYRIGHT (c) 1989-2008, 2016. |
---|
26 | * On-Line Applications Research Corporation (OAR). |
---|
27 | * |
---|
28 | * The license and distribution terms for this file may be |
---|
29 | * found in the file LICENSE in this distribution or at |
---|
30 | * http://www.rtems.org/license/LICENSE. |
---|
31 | */ |
---|
32 | |
---|
33 | #ifndef _RTEMS_RTEMS_SEM_H |
---|
34 | #define _RTEMS_RTEMS_SEM_H |
---|
35 | |
---|
36 | #include <rtems/rtems/types.h> |
---|
37 | #include <rtems/rtems/options.h> |
---|
38 | #include <rtems/rtems/support.h> |
---|
39 | #include <rtems/rtems/tasks.h> |
---|
40 | #include <rtems/rtems/attr.h> |
---|
41 | #include <rtems/score/coremutex.h> |
---|
42 | #include <rtems/score/object.h> |
---|
43 | #include <rtems/score/coresem.h> |
---|
44 | #include <rtems/score/mrsp.h> |
---|
45 | |
---|
46 | #ifdef __cplusplus |
---|
47 | extern "C" { |
---|
48 | #endif |
---|
49 | |
---|
50 | /** |
---|
51 | * @defgroup ClassicSem Semaphores |
---|
52 | * |
---|
53 | * @ingroup ClassicRTEMS |
---|
54 | * |
---|
55 | * This encapsulates functionality related to the Classic API |
---|
56 | * Semaphore Manager. |
---|
57 | */ |
---|
58 | /**@{*/ |
---|
59 | |
---|
60 | /** |
---|
61 | * The following defines the control block used to manage each semaphore. |
---|
62 | */ |
---|
63 | typedef struct { |
---|
64 | /** This field is the object management portion of a Semaphore instance. */ |
---|
65 | Objects_Control Object; |
---|
66 | |
---|
67 | /** |
---|
68 | * This contains the memory associated with the SuperCore Semaphore or |
---|
69 | * Mutex instance that provides the primary functionality of each |
---|
70 | * Classic API Semaphore instance. The structure used is dependent |
---|
71 | * on the attributes specified by the user on the create directive. |
---|
72 | * |
---|
73 | * @note Only one of these has meaning in a particular Classic API |
---|
74 | * Semaphore instance. |
---|
75 | */ |
---|
76 | union { |
---|
77 | /** |
---|
78 | * @brief The thread queue present in all other variants. |
---|
79 | */ |
---|
80 | Thread_queue_Control Wait_queue; |
---|
81 | |
---|
82 | /** |
---|
83 | * This is the SuperCore Mutex instance associated with this Classic |
---|
84 | * API Semaphore instance. |
---|
85 | */ |
---|
86 | CORE_ceiling_mutex_Control Mutex; |
---|
87 | |
---|
88 | /** |
---|
89 | * This is the SuperCore Semaphore instance associated with this Classic |
---|
90 | * API Semaphore instance. |
---|
91 | */ |
---|
92 | CORE_semaphore_Control semaphore; |
---|
93 | |
---|
94 | #if defined(RTEMS_SMP) |
---|
95 | MRSP_Control mrsp; |
---|
96 | #endif |
---|
97 | } Core_control; |
---|
98 | |
---|
99 | /** |
---|
100 | * @brief The semaphore variant. |
---|
101 | * |
---|
102 | * @see Semaphore_Variant. |
---|
103 | */ |
---|
104 | unsigned int variant : 3; |
---|
105 | |
---|
106 | /** |
---|
107 | * @brief The semaphore thread queue discipline. |
---|
108 | * |
---|
109 | * @see Semaphore_Discipline. |
---|
110 | */ |
---|
111 | unsigned int discipline : 1; |
---|
112 | |
---|
113 | #if defined(RTEMS_MULTIPROCESSING) |
---|
114 | unsigned int is_global : 1; |
---|
115 | #endif |
---|
116 | } Semaphore_Control; |
---|
117 | |
---|
118 | /** |
---|
119 | * @brief rtems_semaphore_create |
---|
120 | * |
---|
121 | * This routine implements the rtems_semaphore_create directive. The |
---|
122 | * semaphore will have the name name. The starting count for |
---|
123 | * the semaphore is count. The attribute_set determines if |
---|
124 | * the semaphore is global or local and the thread queue |
---|
125 | * discipline. It returns the id of the created semaphore in ID. |
---|
126 | */ |
---|
127 | rtems_status_code rtems_semaphore_create( |
---|
128 | rtems_name name, |
---|
129 | uint32_t count, |
---|
130 | rtems_attribute attribute_set, |
---|
131 | rtems_task_priority priority_ceiling, |
---|
132 | rtems_id *id |
---|
133 | ); |
---|
134 | |
---|
135 | /** |
---|
136 | * @brief RTEMS Semaphore Name to Id |
---|
137 | * |
---|
138 | * This routine implements the rtems_semaphore_ident directive. |
---|
139 | * This directive returns the semaphore ID associated with name. |
---|
140 | * If more than one semaphore is named name, then the semaphore |
---|
141 | * to which the ID belongs is arbitrary. node indicates the |
---|
142 | * extent of the search for the ID of the semaphore named name. |
---|
143 | * The search can be limited to a particular node or allowed to |
---|
144 | * encompass all nodes. |
---|
145 | * |
---|
146 | * @param[in] name is the user defined semaphore name |
---|
147 | * @param[in] node is(are) the node(s) to be searched |
---|
148 | * @param[in] id is the pointer to semaphore id |
---|
149 | * |
---|
150 | * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful and |
---|
151 | * *id filled in with the semaphore id |
---|
152 | */ |
---|
153 | rtems_status_code rtems_semaphore_ident( |
---|
154 | rtems_name name, |
---|
155 | uint32_t node, |
---|
156 | rtems_id *id |
---|
157 | ); |
---|
158 | |
---|
159 | /** |
---|
160 | * @brief RTEMS Delete Semaphore |
---|
161 | * |
---|
162 | * This routine implements the rtems_semaphore_delete directive. The |
---|
163 | * semaphore indicated by ID is deleted. |
---|
164 | * |
---|
165 | * @param[in] id is the semaphore id |
---|
166 | * |
---|
167 | * @retval This method returns RTEMS_SUCCESSFUL if there was not an |
---|
168 | * error. Otherwise, a status code is returned indicating the |
---|
169 | * source of the error. |
---|
170 | */ |
---|
171 | rtems_status_code rtems_semaphore_delete( |
---|
172 | rtems_id id |
---|
173 | ); |
---|
174 | |
---|
175 | /** |
---|
176 | * @brief RTEMS Obtain Semaphore |
---|
177 | * |
---|
178 | * This routine implements the rtems_semaphore_obtain directive. It |
---|
179 | * attempts to obtain a unit from the semaphore associated with ID. |
---|
180 | * If a unit can be allocated, the calling task will return immediately. |
---|
181 | * If no unit is available, then the task may return immediately or |
---|
182 | * block waiting for a unit with an optional timeout of timeout |
---|
183 | * clock ticks. Whether the task blocks or returns immediately |
---|
184 | * is based on the RTEMS_NO_WAIT option in the option_set. |
---|
185 | * |
---|
186 | * @param[in] id is the semaphore id |
---|
187 | * @param[in] option_set is the wait option |
---|
188 | * @param[in] timeout is the number of ticks to wait (0 means wait forever) |
---|
189 | * |
---|
190 | * @retval This method returns RTEMS_SUCCESSFUL if there was not an |
---|
191 | * error. Otherwise, a status code is returned indicating the |
---|
192 | * source of the error. |
---|
193 | */ |
---|
194 | rtems_status_code rtems_semaphore_obtain( |
---|
195 | rtems_id id, |
---|
196 | rtems_option option_set, |
---|
197 | rtems_interval timeout |
---|
198 | ); |
---|
199 | |
---|
200 | /** |
---|
201 | * @brief RTEMS Semaphore Release |
---|
202 | * |
---|
203 | * This routine implements the rtems_semaphore_release directive. It |
---|
204 | * frees a unit to the semaphore associated with ID. If a task was |
---|
205 | * blocked waiting for a unit from this semaphore, then that task will |
---|
206 | * be readied and the unit given to that task. Otherwise, the unit |
---|
207 | * will be returned to the semaphore. |
---|
208 | */ |
---|
209 | rtems_status_code rtems_semaphore_release( |
---|
210 | rtems_id id |
---|
211 | ); |
---|
212 | |
---|
213 | /** |
---|
214 | * @brief RTEMS Semaphore Flush |
---|
215 | * |
---|
216 | * This method is the implementation of the flush directive |
---|
217 | * of the Semaphore Manager. |
---|
218 | * |
---|
219 | * This directive allows a thread to flush the threads |
---|
220 | * pending on the semaphore. |
---|
221 | * |
---|
222 | * @param[in] id is the semaphore id |
---|
223 | * |
---|
224 | * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful |
---|
225 | */ |
---|
226 | rtems_status_code rtems_semaphore_flush( |
---|
227 | rtems_id id |
---|
228 | ); |
---|
229 | |
---|
230 | /** |
---|
231 | * @brief Sets the priority value with respect to the specified scheduler of a |
---|
232 | * semaphore. |
---|
233 | * |
---|
234 | * The special priority value @ref RTEMS_CURRENT_PRIORITY can be used to get |
---|
235 | * the current priority value without changing it. |
---|
236 | * |
---|
237 | * The interpretation of the priority value depends on the protocol of the |
---|
238 | * semaphore object. |
---|
239 | * |
---|
240 | * - The Multiprocessor Resource Sharing Protocol needs a ceiling priority per |
---|
241 | * scheduler instance. This operation can be used to specify these priority |
---|
242 | * values. |
---|
243 | * - For the Priority Ceiling Protocol the ceiling priority is used with this |
---|
244 | * operation. |
---|
245 | * - For other protocols this operation is not defined. |
---|
246 | * |
---|
247 | * @param[in] semaphore_id Identifier of the semaphore. |
---|
248 | * @param[in] scheduler_id Identifier of the scheduler. |
---|
249 | * @param[in] new_priority The new priority value. Use |
---|
250 | * @ref RTEMS_CURRENT_PRIORITY to not set a new priority and only get the |
---|
251 | * current priority. |
---|
252 | * @param[out] old_priority Reference to store the old priority value. |
---|
253 | * |
---|
254 | * @retval RTEMS_SUCCESSFUL Successful operation. |
---|
255 | * @retval RTEMS_INVALID_ID Invalid semaphore or scheduler identifier. |
---|
256 | * @retval RTEMS_INVALID_ADDRESS The old priority reference is @c NULL. |
---|
257 | * @retval RTEMS_INVALID_PRIORITY The new priority value is invalid. |
---|
258 | * @retval RTEMS_NOT_DEFINED The set priority operation is not defined for the |
---|
259 | * protocol of this semaphore object. |
---|
260 | * @retval RTEMS_ILLEGAL_ON_REMOTE_OBJECT Not supported for remote semaphores. |
---|
261 | * |
---|
262 | * @see rtems_scheduler_ident() and rtems_task_set_priority(). |
---|
263 | */ |
---|
264 | rtems_status_code rtems_semaphore_set_priority( |
---|
265 | rtems_id semaphore_id, |
---|
266 | rtems_id scheduler_id, |
---|
267 | rtems_task_priority new_priority, |
---|
268 | rtems_task_priority *old_priority |
---|
269 | ); |
---|
270 | |
---|
271 | /**@}*/ |
---|
272 | |
---|
273 | #ifdef __cplusplus |
---|
274 | } |
---|
275 | #endif |
---|
276 | |
---|
277 | #endif |
---|
278 | /* end of include file */ |
---|