1 | @c |
---|
2 | @c COPYRIGHT (c) 1996. |
---|
3 | @c On-Line Applications Research Corporation (OAR). |
---|
4 | @c All rights reserved. |
---|
5 | @c |
---|
6 | |
---|
7 | @ifinfo |
---|
8 | @node Semaphore Manager, Semaphore Manager Introduction, TIMER_RESET - Reset an interval timer, Top |
---|
9 | @end ifinfo |
---|
10 | @chapter Semaphore Manager |
---|
11 | @ifinfo |
---|
12 | @menu |
---|
13 | * Semaphore Manager Introduction:: |
---|
14 | * Semaphore Manager Background:: |
---|
15 | * Semaphore Manager Operations:: |
---|
16 | * Semaphore Manager Directives:: |
---|
17 | @end menu |
---|
18 | @end ifinfo |
---|
19 | |
---|
20 | @ifinfo |
---|
21 | @node Semaphore Manager Introduction, Semaphore Manager Background, Semaphore Manager, Semaphore Manager |
---|
22 | @end ifinfo |
---|
23 | @section Introduction |
---|
24 | |
---|
25 | The semaphore manager utilizes standard Dijkstra |
---|
26 | counting semaphores to provide synchronization and mutual |
---|
27 | exclusion capabilities. The directives provided by the |
---|
28 | semaphore manager are: |
---|
29 | |
---|
30 | @itemize @bullet |
---|
31 | @item @code{semaphore_create} - Create a semaphore |
---|
32 | @item @code{semaphore_ident} - Get ID of a semaphore |
---|
33 | @item @code{semaphore_delete} - Delete a semaphore |
---|
34 | @item @code{semaphore_obtain} - Acquire a semaphore |
---|
35 | @item @code{semaphore_release} - Release a semaphore |
---|
36 | @end itemize |
---|
37 | |
---|
38 | @ifinfo |
---|
39 | @node Semaphore Manager Background, Nested Resource Access, Semaphore Manager Introduction, Semaphore Manager |
---|
40 | @end ifinfo |
---|
41 | @section Background |
---|
42 | @ifinfo |
---|
43 | @menu |
---|
44 | * Nested Resource Access:: |
---|
45 | * Priority Inversion:: |
---|
46 | * Priority Inheritance:: |
---|
47 | * Priority Ceiling:: |
---|
48 | * Building a Semaphore's Attribute Set:: |
---|
49 | * Building a SEMAPHORE_OBTAIN Option Set:: |
---|
50 | @end menu |
---|
51 | @end ifinfo |
---|
52 | |
---|
53 | A semaphore can be viewed as a protected variable |
---|
54 | whose value can be modified only with the semaphore_create, |
---|
55 | semaphore_obtain, and semaphore_release directives. RTEMS |
---|
56 | supports both binary and counting semaphores. A binary semaphore |
---|
57 | is restricted to values of zero or one, while a counting |
---|
58 | semaphore can assume any non-negative integer value. |
---|
59 | |
---|
60 | A binary semaphore can be used to control access to a |
---|
61 | single resource. In particular, it can be used to enforce |
---|
62 | mutual exclusion for a critical section in user code. In this |
---|
63 | instance, the semaphore would be created with an initial count |
---|
64 | of one to indicate that no task is executing the critical |
---|
65 | section of code. Upon entry to the critical section, a task |
---|
66 | must issue the semaphore_obtain directive to prevent other tasks |
---|
67 | from entering the critical section. Upon exit from the critical |
---|
68 | section, the task must issue the semaphore_release directive to |
---|
69 | allow another task to execute the critical section. |
---|
70 | |
---|
71 | A counting semaphore can be used to control access to |
---|
72 | a pool of two or more resources. For example, access to three |
---|
73 | printers could be administered by a semaphore created with an |
---|
74 | initial count of three. When a task requires access to one of |
---|
75 | the printers, it issues the semaphore_obtain directive to obtain |
---|
76 | access to a printer. If a printer is not currently available, |
---|
77 | the task can wait for a printer to become available or return |
---|
78 | immediately. When the task has completed printing, it should |
---|
79 | issue the semaphore_release directive to allow other tasks |
---|
80 | access to the printer. |
---|
81 | |
---|
82 | Task synchronization may be achieved by creating a |
---|
83 | semaphore with an initial count of zero. One task waits for the |
---|
84 | arrival of another task by issuing a semaphore_obtain directive |
---|
85 | when it reaches a synchronization point. The other task |
---|
86 | performs a corresponding semaphore_release operation when it |
---|
87 | reaches its synchronization point, thus unblocking the pending |
---|
88 | task. |
---|
89 | |
---|
90 | @ifinfo |
---|
91 | @node Nested Resource Access, Priority Inversion, Semaphore Manager Background, Semaphore Manager Background |
---|
92 | @end ifinfo |
---|
93 | @subsection Nested Resource Access |
---|
94 | |
---|
95 | Deadlock occurs when a task owning a binary semaphore |
---|
96 | attempts to acquire that same semaphore and blocks as result. |
---|
97 | Since the semaphore is allocated to a task, it cannot be |
---|
98 | deleted. Therefore, the task that currently holds the semaphore |
---|
99 | and is also blocked waiting for that semaphore will never |
---|
100 | execute again. |
---|
101 | |
---|
102 | RTEMS addresses this problem by allowing the task |
---|
103 | holding the binary semaphore to obtain the same binary semaphore |
---|
104 | multiple times in a nested manner. Each semaphore_obtain must |
---|
105 | be accompanied with a semaphore_release. The semaphore will |
---|
106 | only be made available for acquisition by other tasks when the |
---|
107 | outermost semaphore_obtain is matched with a semaphore_release. |
---|
108 | |
---|
109 | |
---|
110 | @ifinfo |
---|
111 | @node Priority Inversion, Priority Inheritance, Nested Resource Access, Semaphore Manager Background |
---|
112 | @end ifinfo |
---|
113 | @subsection Priority Inversion |
---|
114 | |
---|
115 | Priority inversion is a form of indefinite |
---|
116 | postponement which is common in multitasking, preemptive |
---|
117 | executives with shared resources. Priority inversion occurs |
---|
118 | when a high priority tasks requests access to shared resource |
---|
119 | which is currently allocated to low priority task. The high |
---|
120 | priority task must block until the low priority task releases |
---|
121 | the resource. This problem is exacerbated when the low priority |
---|
122 | task is prevented from executing by one or more medium priority |
---|
123 | tasks. Because the low priority task is not executing, it |
---|
124 | cannot complete its interaction with the resource and release |
---|
125 | that resource. The high priority task is effectively prevented |
---|
126 | from executing by lower priority tasks. |
---|
127 | |
---|
128 | @ifinfo |
---|
129 | @node Priority Inheritance, Priority Ceiling, Priority Inversion, Semaphore Manager Background |
---|
130 | @end ifinfo |
---|
131 | @subsection Priority Inheritance |
---|
132 | |
---|
133 | Priority inheritance is an algorithm that calls for |
---|
134 | the lower priority task holding a resource to have its priority |
---|
135 | increased to that of the highest priority task blocked waiting |
---|
136 | for that resource. Each time a task blocks attempting to obtain |
---|
137 | the resource, the task holding the resource may have its |
---|
138 | priority increased. |
---|
139 | |
---|
140 | RTEMS supports priority inheritance for local, binary |
---|
141 | semaphores that use the priority task wait queue blocking |
---|
142 | discipline. When a task of higher priority than the task |
---|
143 | holding the semaphore blocks, the priority of the task holding |
---|
144 | the semaphore is increased to that of the blocking task. When |
---|
145 | the task holding the task completely releases the binary |
---|
146 | semaphore (i.e. not for a nested release), the holder's priority |
---|
147 | is restored to the value it had before any higher priority was |
---|
148 | inherited. |
---|
149 | |
---|
150 | The RTEMS implementation of the priority inheritance |
---|
151 | algorithm takes into account the scenario in which a task holds |
---|
152 | more than one binary semaphore. The holding task will execute |
---|
153 | at the priority of the higher of the highest ceiling priority or |
---|
154 | at the priority of the highest priority task blocked waiting for |
---|
155 | any of the semaphores the task holds. Only when the task |
---|
156 | releases ALL of the binary semaphores it holds will its priority |
---|
157 | be restored to the normal value. |
---|
158 | |
---|
159 | @ifinfo |
---|
160 | @node Priority Ceiling, Building a Semaphore's Attribute Set, Priority Inheritance, Semaphore Manager Background |
---|
161 | @end ifinfo |
---|
162 | @subsection Priority Ceiling |
---|
163 | |
---|
164 | Priority ceiling is an algorithm that calls for the |
---|
165 | lower priority task holding a resource to have its priority |
---|
166 | increased to that of the highest priority task which will EVER |
---|
167 | block waiting for that resource. This algorithm addresses the |
---|
168 | problem of priority inversion although it avoids the possibility |
---|
169 | of changing the priority of the task holding the resource |
---|
170 | multiple times. The priority ceiling algorithm will only change |
---|
171 | the priority of the task holding the resource a maximum of one |
---|
172 | time. The ceiling priority is set at creation time and must be |
---|
173 | the priority of the highest priority task which will ever |
---|
174 | attempt to acquire that semaphore. |
---|
175 | |
---|
176 | RTEMS supports priority ceiling for local, binary |
---|
177 | semaphores that use the priority task wait queue blocking |
---|
178 | discipline. When a task of lower priority than the ceiling |
---|
179 | priority successfully obtains the semaphore, its priority is |
---|
180 | raised to the ceiling priority. When the task holding the task |
---|
181 | completely releases the binary semaphore (i.e. not for a nested |
---|
182 | release), the holder's priority is restored to the value it had |
---|
183 | before any higher priority was put into effect. |
---|
184 | |
---|
185 | The need to identify the highest priority task which |
---|
186 | will attempt to obtain a particular semaphore can be a difficult |
---|
187 | task in a large, complicated system. Although the priority |
---|
188 | ceiling algorithm is more efficient than the priority |
---|
189 | inheritance algorithm with respect to the maximum number of task |
---|
190 | priority changes which may occur while a task holds a particular |
---|
191 | semaphore, the priority inheritance algorithm is more forgiving |
---|
192 | in that it does not require this apriori information. |
---|
193 | |
---|
194 | The RTEMS implementation of the priority ceiling |
---|
195 | algorithm takes into account the scenario in which a task holds |
---|
196 | more than one binary semaphore. The holding task will execute |
---|
197 | at the priority of the higher of the highest ceiling priority or |
---|
198 | at the priority of the highest priority task blocked waiting for |
---|
199 | any of the semaphores the task holds. Only when the task |
---|
200 | releases ALL of the binary semaphores it holds will its priority |
---|
201 | be restored to the normal value. |
---|
202 | |
---|
203 | @ifinfo |
---|
204 | @node Building a Semaphore's Attribute Set, Building a SEMAPHORE_OBTAIN Option Set, Priority Ceiling, Semaphore Manager Background |
---|
205 | @end ifinfo |
---|
206 | @subsection Building a Semaphore's Attribute Set |
---|
207 | |
---|
208 | In general, an attribute set is built by a bitwise OR |
---|
209 | of the desired attribute components. The following table lists |
---|
210 | the set of valid semaphore attributes: |
---|
211 | |
---|
212 | @itemize @bullet |
---|
213 | @item FIFO - tasks wait by FIFO (default) |
---|
214 | @item PRIORITY - tasks wait by priority |
---|
215 | @item BINARY_SEMAPHORE - restrict values to 0 and 1 (default) |
---|
216 | @item COUNTING_SEMAPHORE - no restriction on values |
---|
217 | @item NO_INHERIT_PRIORITY - do not use priority inheritance (default) |
---|
218 | @item INHERIT_PRIORITY - use priority inheritance |
---|
219 | @item PRIORITY_CEILING - use priority ceiling |
---|
220 | @item NO_PRIORITY_CEILING - do not use priority ceiling (default) |
---|
221 | @item LOCAL - local task (default) |
---|
222 | @item GLOBAL - global task |
---|
223 | @end itemize |
---|
224 | |
---|
225 | Attribute values are specifically designed to be |
---|
226 | mutually exclusive, therefore bitwise OR and addition operations |
---|
227 | are equivalent as long as each attribute appears exactly once in |
---|
228 | the component list. An attribute listed as a default is not |
---|
229 | required to appear in the attribute list, although it is a good |
---|
230 | programming practice to specify default attributes. If all |
---|
231 | defaults are desired, the attribute DEFAULT_ATTRIBUTES should be |
---|
232 | specified on this call. |
---|
233 | |
---|
234 | This example demonstrates the attribute_set parameter |
---|
235 | needed to create a local semaphore with the task priority |
---|
236 | waiting queue discipline. The attribute_set parameter passed to |
---|
237 | the semaphore_create directive could be either PRIORITY or LOCAL |
---|
238 | | PRIORITY. The attribute_set parameter can be set to PRIORITY |
---|
239 | because LOCAL is the default for all created tasks. If a |
---|
240 | similar semaphore were to be known globally, then the |
---|
241 | attribute_set parameter would be GLOBAL | PRIORITY. |
---|
242 | |
---|
243 | @ifinfo |
---|
244 | @node Building a SEMAPHORE_OBTAIN Option Set, Semaphore Manager Operations, Building a Semaphore's Attribute Set, Semaphore Manager Background |
---|
245 | @end ifinfo |
---|
246 | @subsection Building a SEMAPHORE_OBTAIN Option Set |
---|
247 | |
---|
248 | In general, an option is built by a bitwise OR of the |
---|
249 | desired option components. The set of valid options for the |
---|
250 | semaphore_obtain directive are listed in the following table: |
---|
251 | |
---|
252 | @itemize @bullet |
---|
253 | @item WAIT - task will wait for semaphore (default) |
---|
254 | @item NO_WAIT - task should not wait |
---|
255 | @end itemize |
---|
256 | |
---|
257 | Option values are specifically designed to be |
---|
258 | mutually exclusive, therefore bitwise OR and addition operations |
---|
259 | are equivalent as long as each attribute appears exactly once in |
---|
260 | the component list. An option listed as a default is not |
---|
261 | required to appear in the list, although it is a good |
---|
262 | programming practice to specify default options. If all |
---|
263 | defaults are desired, the option DEFAULT_OPTIONS should be |
---|
264 | specified on this call. |
---|
265 | |
---|
266 | This example demonstrates the option parameter needed |
---|
267 | to poll for a semaphore. The option parameter passed to the |
---|
268 | semaphore_obtain directive should be NO_WAIT. |
---|
269 | |
---|
270 | @ifinfo |
---|
271 | @node Semaphore Manager Operations, Creating a Semaphore, Building a SEMAPHORE_OBTAIN Option Set, Semaphore Manager |
---|
272 | @end ifinfo |
---|
273 | @section Operations |
---|
274 | @ifinfo |
---|
275 | @menu |
---|
276 | * Creating a Semaphore:: |
---|
277 | * Obtaining Semaphore IDs:: |
---|
278 | * Acquiring a Semaphore:: |
---|
279 | * Releasing a Semaphore:: |
---|
280 | * Deleting a Semaphore:: |
---|
281 | @end menu |
---|
282 | @end ifinfo |
---|
283 | |
---|
284 | @ifinfo |
---|
285 | @node Creating a Semaphore, Obtaining Semaphore IDs, Semaphore Manager Operations, Semaphore Manager Operations |
---|
286 | @end ifinfo |
---|
287 | @subsection Creating a Semaphore |
---|
288 | |
---|
289 | The semaphore_create directive creates a binary or |
---|
290 | counting semaphore with a user-specified name as well as an |
---|
291 | initial count. If a binary semaphore is created with a count of |
---|
292 | zero (0) to indicate that it has been allocated, then the task |
---|
293 | creating the semaphore is considered the current holder of the |
---|
294 | semaphore. At create time the method for ordering waiting tasks |
---|
295 | in the semaphore's task wait queue (by FIFO or task priority) is |
---|
296 | specified. Additionally, the priority inheritance or priority |
---|
297 | ceiling algorithm may be selected for local, binary semaphores |
---|
298 | that use the priority task wait queue blocking discipline. If |
---|
299 | the priority ceiling algorithm is selected, then the highest |
---|
300 | priority of any task which will attempt to obtain this semaphore |
---|
301 | must be specified. RTEMS allocates a Semaphore Control Block |
---|
302 | (SMCB) from the SMCB free list. This data structure is used by |
---|
303 | RTEMS to manage the newly created semaphore. Also, a unique |
---|
304 | semaphore ID is generated and returned to the calling task. |
---|
305 | |
---|
306 | @ifinfo |
---|
307 | @node Obtaining Semaphore IDs, Acquiring a Semaphore, Creating a Semaphore, Semaphore Manager Operations |
---|
308 | @end ifinfo |
---|
309 | @subsection Obtaining Semaphore IDs |
---|
310 | |
---|
311 | When a semaphore is created, RTEMS generates a unique |
---|
312 | semaphore ID and assigns it to the created semaphore until it is |
---|
313 | deleted. The semaphore ID may be obtained by either of two |
---|
314 | methods. First, as the result of an invocation of the |
---|
315 | semaphore_create directive, the semaphore ID is stored in a user |
---|
316 | provided location. Second, the semaphore ID may be obtained |
---|
317 | later using the semaphore_ident directive. The semaphore ID is |
---|
318 | used by other semaphore manager directives to access this |
---|
319 | semaphore. |
---|
320 | |
---|
321 | @ifinfo |
---|
322 | @node Acquiring a Semaphore, Releasing a Semaphore, Obtaining Semaphore IDs, Semaphore Manager Operations |
---|
323 | @end ifinfo |
---|
324 | @subsection Acquiring a Semaphore |
---|
325 | |
---|
326 | The semaphore_obtain directive is used to acquire the |
---|
327 | specified semaphore. A simplified version of the |
---|
328 | semaphore_obtain directive can be described as follows: |
---|
329 | |
---|
330 | @example |
---|
331 | if semaphore's count is greater than zero |
---|
332 | then decrement semaphore's count |
---|
333 | else wait for release of semaphore |
---|
334 | |
---|
335 | return SUCCESSFUL |
---|
336 | @end example |
---|
337 | |
---|
338 | When the semaphore cannot be immediately acquired, |
---|
339 | one of the following situations applies: |
---|
340 | |
---|
341 | @itemize @bullet |
---|
342 | @item By default, the calling task will wait forever to |
---|
343 | acquire the semaphore. |
---|
344 | |
---|
345 | @item Specifying NO_WAIT forces an immediate return with an |
---|
346 | error status code. |
---|
347 | |
---|
348 | @item Specifying a timeout limits the interval the task will |
---|
349 | wait before returning with an error status code. |
---|
350 | @end itemize |
---|
351 | |
---|
352 | If the task waits to acquire the semaphore, then it |
---|
353 | is placed in the semaphore's task wait queue in either FIFO or |
---|
354 | task priority order. If the task blocked waiting for a binary |
---|
355 | semaphore using priority inheritance and the task's priority is |
---|
356 | greater than that of the task currently holding the semaphore, |
---|
357 | then the holding task will inherit the priority of the blocking |
---|
358 | task. All tasks waiting on a semaphore are returned an error |
---|
359 | code when the semaphore is deleted. |
---|
360 | |
---|
361 | When a task successfully obtains a semaphore using |
---|
362 | priority ceiling and the priority ceiling for this semaphore is |
---|
363 | greater than that of the holder, then the holder's priority will |
---|
364 | be elevated. |
---|
365 | |
---|
366 | @ifinfo |
---|
367 | @node Releasing a Semaphore, Deleting a Semaphore, Acquiring a Semaphore, Semaphore Manager Operations |
---|
368 | @end ifinfo |
---|
369 | @subsection Releasing a Semaphore |
---|
370 | |
---|
371 | The semaphore_release directive is used to release |
---|
372 | the specified semaphore. A simplified version of the |
---|
373 | semaphore_release directive can be described as follows: |
---|
374 | |
---|
375 | @example |
---|
376 | if no tasks are waiting on this semaphore |
---|
377 | then increment semaphore's count |
---|
378 | else assign semaphore to a waiting task |
---|
379 | |
---|
380 | return SUCCESSFUL |
---|
381 | @end example |
---|
382 | |
---|
383 | If this is the outermost release of a binary |
---|
384 | semaphore that uses priority inheritance or priority ceiling and |
---|
385 | the task does not currently hold any other binary semaphores, |
---|
386 | then the task performing the semaphore_release will have its |
---|
387 | priority restored to its normal value. |
---|
388 | |
---|
389 | @ifinfo |
---|
390 | @node Deleting a Semaphore, Semaphore Manager Directives, Releasing a Semaphore, Semaphore Manager Operations |
---|
391 | @end ifinfo |
---|
392 | @subsection Deleting a Semaphore |
---|
393 | |
---|
394 | The semaphore_delete directive removes a semaphore |
---|
395 | from the system and frees its control block. A semaphore can be |
---|
396 | deleted by any local task that knows the semaphore's ID. As a |
---|
397 | result of this directive, all tasks blocked waiting to acquire |
---|
398 | the semaphore will be readied and returned a status code which |
---|
399 | indicates that the semaphore was deleted. Any subsequent |
---|
400 | references to the semaphore's name and ID are invalid. |
---|
401 | |
---|
402 | @ifinfo |
---|
403 | @node Semaphore Manager Directives, SEMAPHORE_CREATE - Create a semaphore, Deleting a Semaphore, Semaphore Manager |
---|
404 | @end ifinfo |
---|
405 | @section Directives |
---|
406 | @ifinfo |
---|
407 | @menu |
---|
408 | * SEMAPHORE_CREATE - Create a semaphore:: |
---|
409 | * SEMAPHORE_IDENT - Get ID of a semaphore:: |
---|
410 | * SEMAPHORE_DELETE - Delete a semaphore:: |
---|
411 | * SEMAPHORE_OBTAIN - Acquire a semaphore:: |
---|
412 | * SEMAPHORE_RELEASE - Release a semaphore:: |
---|
413 | @end menu |
---|
414 | @end ifinfo |
---|
415 | |
---|
416 | This section details the semaphore manager's |
---|
417 | directives. A subsection is dedicated to each of this manager's |
---|
418 | directives and describes the calling sequence, related |
---|
419 | constants, usage, and status codes. |
---|
420 | |
---|
421 | @page |
---|
422 | @ifinfo |
---|
423 | @node SEMAPHORE_CREATE - Create a semaphore, SEMAPHORE_IDENT - Get ID of a semaphore, Semaphore Manager Directives, Semaphore Manager Directives |
---|
424 | @end ifinfo |
---|
425 | @subsection SEMAPHORE_CREATE - Create a semaphore |
---|
426 | |
---|
427 | @subheading CALLING SEQUENCE: |
---|
428 | |
---|
429 | @ifset is-C |
---|
430 | @example |
---|
431 | rtems_status_code rtems_semaphore_create( |
---|
432 | rtems_name name, |
---|
433 | rtems_unsigned32 count, |
---|
434 | rtems_attribute attribute_set, |
---|
435 | rtems_task_priority priority_ceiling, |
---|
436 | rtems_id *id |
---|
437 | ); |
---|
438 | @end example |
---|
439 | @end ifset |
---|
440 | |
---|
441 | @ifset is-Ada |
---|
442 | @example |
---|
443 | procedure Semaphore_Create ( |
---|
444 | Name : in RTEMS.Name; |
---|
445 | Count : in RTEMS.Unsigned32; |
---|
446 | Attribute_Set : in RTEMS.Attribute; |
---|
447 | ID : out RTEMS.ID; |
---|
448 | Result : out RTEMS.Status_Codes |
---|
449 | ); |
---|
450 | @end example |
---|
451 | @end ifset |
---|
452 | |
---|
453 | @subheading DIRECTIVE STATUS CODES: |
---|
454 | @code{SUCCESSFUL} - semaphore created successfully@* |
---|
455 | @code{INVALID_NAME} - invalid task name@* |
---|
456 | @code{TOO_MANY} - too many semaphores created@* |
---|
457 | @code{NOT_DEFINED} - invalid attribute set@* |
---|
458 | @code{INVALID_NUMBER} - invalid starting count for binary semaphore@* |
---|
459 | @code{MP_NOT_CONFIGURED} - multiprocessing not configured@* |
---|
460 | @code{TOO_MANY} - too many global objects |
---|
461 | |
---|
462 | @subheading DESCRIPTION: |
---|
463 | |
---|
464 | This directive creates a semaphore which resides on |
---|
465 | the local node. The created semaphore has the user-defined name |
---|
466 | specified in name and the initial count specified in count. For |
---|
467 | control and maintenance of the semaphore, RTEMS allocates and |
---|
468 | initializes a SMCB. The RTEMS-assigned semaphore id is returned |
---|
469 | in id. This semaphore id is used with other semaphore related |
---|
470 | directives to access the semaphore. |
---|
471 | |
---|
472 | Specifying PRIORITY in attribute_set causes tasks |
---|
473 | waiting for a semaphore to be serviced according to task |
---|
474 | priority. When FIFO is selected, tasks are serviced in First |
---|
475 | In-First Out order. |
---|
476 | |
---|
477 | @subheading NOTES: |
---|
478 | |
---|
479 | This directive will not cause the calling task to be |
---|
480 | preempted. |
---|
481 | |
---|
482 | The priority inheritance and priority ceiling |
---|
483 | algorithms are only supported for local, binary semaphores that |
---|
484 | use the priority task wait queue blocking discipline. |
---|
485 | |
---|
486 | The following semaphore attribute constants are |
---|
487 | defined by RTEMS: |
---|
488 | |
---|
489 | @itemize @bullet |
---|
490 | @item FIFO - tasks wait by FIFO (default) |
---|
491 | @item PRIORITY - tasks wait by priority |
---|
492 | @item BINARY_SEMAPHORE - restrict values to 0 and 1 (default) |
---|
493 | @item COUNTING_SEMAPHORE - no restriction on values |
---|
494 | @item NO_INHERIT_PRIORITY - do not use priority inheritance (default) |
---|
495 | @item INHERIT_PRIORITY - use priority inheritance |
---|
496 | @item PRIORITY_CEILING - use priority ceiling |
---|
497 | @item NO_PRIORITY_CEILING - do not use priority ceiling (default) |
---|
498 | @item LOCAL - local task (default) |
---|
499 | @item GLOBAL - global task |
---|
500 | @end itemize |
---|
501 | |
---|
502 | |
---|
503 | |
---|
504 | Semaphores should not be made global unless remote |
---|
505 | tasks must interact with the created semaphore. This is to |
---|
506 | avoid the system overhead incurred by the creation of a global |
---|
507 | semaphore. When a global semaphore is created, the semaphore's |
---|
508 | name and id must be transmitted to every node in the system for |
---|
509 | insertion in the local copy of the global object table. |
---|
510 | |
---|
511 | The total number of global objects, including |
---|
512 | semaphores, is limited by the maximum_global_objects field in |
---|
513 | the Configuration Table. |
---|
514 | |
---|
515 | @page |
---|
516 | @ifinfo |
---|
517 | @node SEMAPHORE_IDENT - Get ID of a semaphore, SEMAPHORE_DELETE - Delete a semaphore, SEMAPHORE_CREATE - Create a semaphore, Semaphore Manager Directives |
---|
518 | @end ifinfo |
---|
519 | @subsection SEMAPHORE_IDENT - Get ID of a semaphore |
---|
520 | |
---|
521 | @subheading CALLING SEQUENCE: |
---|
522 | |
---|
523 | @ifset is-C |
---|
524 | @example |
---|
525 | rtems_status_code rtems_semaphore_ident( |
---|
526 | rtems_name name, |
---|
527 | rtems_unsigned32 node, |
---|
528 | rtems_id *id |
---|
529 | ); |
---|
530 | @end example |
---|
531 | @end ifset |
---|
532 | |
---|
533 | @ifset is-Ada |
---|
534 | @example |
---|
535 | procedure Semaphore_Ident ( |
---|
536 | Name : in RTEMS.Name; |
---|
537 | Node : in RTEMS.Unsigned32; |
---|
538 | ID : out RTEMS.ID; |
---|
539 | Result : out RTEMS.Status_Codes |
---|
540 | ); |
---|
541 | @end example |
---|
542 | @end ifset |
---|
543 | |
---|
544 | @subheading DIRECTIVE STATUS CODES: |
---|
545 | @code{SUCCESSFUL} - semaphore identified successfully@* |
---|
546 | @code{INVALID_NAME} - semaphore name not found@* |
---|
547 | @code{INVALID_NODE} - invalid node id |
---|
548 | |
---|
549 | @subheading DESCRIPTION: |
---|
550 | |
---|
551 | This directive obtains the semaphore id associated |
---|
552 | with the semaphore name. If the semaphore name is not unique, |
---|
553 | then the semaphore id will match one of the semaphores with that |
---|
554 | name. However, this semaphore id is not guaranteed to |
---|
555 | correspond to the desired semaphore. The semaphore id is used |
---|
556 | by other semaphore related directives to access the semaphore. |
---|
557 | |
---|
558 | @subheading NOTES: |
---|
559 | |
---|
560 | This directive will not cause the running task to be |
---|
561 | preempted. |
---|
562 | |
---|
563 | If node is SEARCH_ALL_NODES, all nodes are searched |
---|
564 | with the local node being searched first. All other nodes are |
---|
565 | searched with the lowest numbered node searched first. |
---|
566 | |
---|
567 | If node is a valid node number which does not |
---|
568 | represent the local node, then only the semaphores exported by |
---|
569 | the designated node are searched. |
---|
570 | |
---|
571 | This directive does not generate activity on remote |
---|
572 | nodes. It accesses only the local copy of the global object |
---|
573 | table. |
---|
574 | |
---|
575 | @page |
---|
576 | @ifinfo |
---|
577 | @node SEMAPHORE_DELETE - Delete a semaphore, SEMAPHORE_OBTAIN - Acquire a semaphore, SEMAPHORE_IDENT - Get ID of a semaphore, Semaphore Manager Directives |
---|
578 | @end ifinfo |
---|
579 | @subsection SEMAPHORE_DELETE - Delete a semaphore |
---|
580 | |
---|
581 | @subheading CALLING SEQUENCE: |
---|
582 | |
---|
583 | @ifset is-C |
---|
584 | @example |
---|
585 | rtems_status_code rtems_semaphore_delete( |
---|
586 | rtems_id id |
---|
587 | ); |
---|
588 | @end example |
---|
589 | @end ifset |
---|
590 | |
---|
591 | @ifset is-Ada |
---|
592 | @example |
---|
593 | procedure Semaphore_Delete ( |
---|
594 | ID : in RTEMS.ID; |
---|
595 | Result : out RTEMS.Status_Codes |
---|
596 | ); |
---|
597 | @end example |
---|
598 | @end ifset |
---|
599 | |
---|
600 | @subheading DIRECTIVE STATUS CODES: |
---|
601 | @code{SUCCESSFUL} - semaphore deleted successfully@* |
---|
602 | @code{INVALID_ID} - invalid semaphore id@* |
---|
603 | @code{ILLEGAL_ON_REMOTE_OBJECT} - cannot delete remote semaphore@* |
---|
604 | @code{RESOURCE_IN_USE} - binary semaphore is in use |
---|
605 | |
---|
606 | @subheading DESCRIPTION: |
---|
607 | |
---|
608 | This directive deletes the semaphore specified by id. |
---|
609 | All tasks blocked waiting to acquire the semaphore will be |
---|
610 | readied and returned a status code which indicates that the |
---|
611 | semaphore was deleted. The SMCB for this semaphore is reclaimed |
---|
612 | by RTEMS. |
---|
613 | |
---|
614 | @subheading NOTES: |
---|
615 | |
---|
616 | The calling task will be preempted if it is enabled |
---|
617 | by the task's execution mode and a higher priority local task is |
---|
618 | waiting on the deleted semaphore. The calling task will NOT be |
---|
619 | preempted if all of the tasks that are waiting on the semaphore |
---|
620 | are remote tasks. |
---|
621 | |
---|
622 | The calling task does not have to be the task that |
---|
623 | created the semaphore. Any local task that knows the semaphore |
---|
624 | id can delete the semaphore. |
---|
625 | |
---|
626 | When a global semaphore is deleted, the semaphore id |
---|
627 | must be transmitted to every node in the system for deletion |
---|
628 | from the local copy of the global object table. |
---|
629 | |
---|
630 | The semaphore must reside on the local node, even if |
---|
631 | the semaphore was created with the GLOBAL option. |
---|
632 | |
---|
633 | Proxies, used to represent remote tasks, are |
---|
634 | reclaimed when the semaphore is deleted. |
---|
635 | |
---|
636 | @page |
---|
637 | @ifinfo |
---|
638 | @node SEMAPHORE_OBTAIN - Acquire a semaphore, SEMAPHORE_RELEASE - Release a semaphore, SEMAPHORE_DELETE - Delete a semaphore, Semaphore Manager Directives |
---|
639 | @end ifinfo |
---|
640 | @subsection SEMAPHORE_OBTAIN - Acquire a semaphore |
---|
641 | |
---|
642 | @subheading CALLING SEQUENCE: |
---|
643 | |
---|
644 | @ifset is-C |
---|
645 | @example |
---|
646 | rtems_status_code rtems_semaphore_obtain( |
---|
647 | rtems_id id, |
---|
648 | rtems_unsigned32 option_set, |
---|
649 | rtems_interval timeout |
---|
650 | ); |
---|
651 | @end example |
---|
652 | @end ifset |
---|
653 | |
---|
654 | @ifset is-Ada |
---|
655 | @example |
---|
656 | procedure Semaphore_Obtain ( |
---|
657 | ID : in RTEMS.ID; |
---|
658 | Option_Set : in RTEMS.Option; |
---|
659 | Timeout : in RTEMS.Interval; |
---|
660 | Result : out RTEMS.Status_Codes |
---|
661 | ); |
---|
662 | @end example |
---|
663 | @end ifset |
---|
664 | |
---|
665 | @subheading DIRECTIVE STATUS CODES: |
---|
666 | @code{SUCCESSFUL} - semaphore obtained successfully@* |
---|
667 | @code{UNSATISFIED} - semaphore not available@* |
---|
668 | @code{TIMEOUT} - timed out waiting for semaphore@* |
---|
669 | @code{OBJECT_WAS_DELETED} - semaphore deleted while waiting@* |
---|
670 | @code{INVALID_ID} - invalid semaphore id |
---|
671 | |
---|
672 | @subheading DESCRIPTION: |
---|
673 | |
---|
674 | This directive acquires the semaphore specified by |
---|
675 | id. The WAIT and NO_WAIT components of the options parameter |
---|
676 | indicate whether the calling task wants to wait for the |
---|
677 | semaphore to become available or return immediately if the |
---|
678 | semaphore is not currently available. With either WAIT or |
---|
679 | NO_WAIT, if the current semaphore count is positive, then it is |
---|
680 | decremented by one and the semaphore is successfully acquired by |
---|
681 | returning immediately with a successful return code. |
---|
682 | |
---|
683 | If the calling task chooses to return immediately and |
---|
684 | the current semaphore count is zero or negative, then a status |
---|
685 | code is returned indicating that the semaphore is not available. |
---|
686 | If the calling task chooses to wait for a semaphore and the |
---|
687 | current semaphore count is zero or negative, then it is |
---|
688 | decremented by one and the calling task is placed on the |
---|
689 | semaphore's wait queue and blocked. If the semaphore was |
---|
690 | created with the PRIORITY attribute, then the calling task is |
---|
691 | inserted into the queue according to its priority. However, if |
---|
692 | the semaphore was created with the FIFO attribute, then the |
---|
693 | calling task is placed at the rear of the wait queue. If the |
---|
694 | binary semaphore was created with the INHERIT_PRIORITY |
---|
695 | attribute, then the priority of the task currently holding the |
---|
696 | binary semaphore is guaranteed to be greater than or equal to |
---|
697 | that of the blocking task. If the binary semaphore was created |
---|
698 | with the PRIORITY_CEILING attribute, a task successfully obtains |
---|
699 | the semaphore, and the priority of that task is greater than the |
---|
700 | ceiling priority for this semaphore, then the priority of the |
---|
701 | task obtaining the semaphore is elevated to that of the ceiling. |
---|
702 | |
---|
703 | The timeout parameter specifies the maximum interval |
---|
704 | the calling task is willing to be blocked waiting for the |
---|
705 | semaphore. If it is set to NO_TIMEOUT, then the calling task |
---|
706 | will wait forever. If the semaphore is available or the NO_WAIT |
---|
707 | option component is set, then timeout is ignored. |
---|
708 | |
---|
709 | @subheading NOTES: |
---|
710 | The following semaphore acquisition option constants |
---|
711 | are defined by RTEMS: |
---|
712 | |
---|
713 | @itemize @bullet |
---|
714 | @item WAIT - task will wait for semaphore (default) |
---|
715 | @item NO_WAIT - task should not wait |
---|
716 | @end itemize |
---|
717 | |
---|
718 | Attempting to obtain a global semaphore which does not reside on |
---|
719 | the local node will generate a request to the remote node to |
---|
720 | access the semaphore. If the semaphore is not available and |
---|
721 | NO_WAIT was not specified, then the task must be blocked until |
---|
722 | the semaphore is released. A proxy is allocated on the remote |
---|
723 | node to represent the task until the semaphore is released. |
---|
724 | |
---|
725 | @page |
---|
726 | @ifinfo |
---|
727 | @node SEMAPHORE_RELEASE - Release a semaphore, Message Manager, SEMAPHORE_OBTAIN - Acquire a semaphore, Semaphore Manager Directives |
---|
728 | @end ifinfo |
---|
729 | @subsection SEMAPHORE_RELEASE - Release a semaphore |
---|
730 | |
---|
731 | @subheading CALLING SEQUENCE: |
---|
732 | |
---|
733 | @ifset is-C |
---|
734 | @example |
---|
735 | rtems_status_code rtems_semaphore_release( |
---|
736 | rtems_id id |
---|
737 | ); |
---|
738 | @end example |
---|
739 | @end ifset |
---|
740 | |
---|
741 | @ifset is-Ada |
---|
742 | @example |
---|
743 | procedure Semaphore_Release ( |
---|
744 | ID : in RTEMS.ID; |
---|
745 | Result : out RTEMS.Status_Codes |
---|
746 | ); |
---|
747 | @end example |
---|
748 | @end ifset |
---|
749 | |
---|
750 | @subheading DIRECTIVE STATUS CODES: |
---|
751 | @code{SUCCESSFUL} - semaphore released successfully@* |
---|
752 | @code{INVALID_ID} - invalid semaphore id@* |
---|
753 | @code{NOT_OWNER_OF_RESOURCE} - calling task does not own semaphore |
---|
754 | |
---|
755 | @subheading DESCRIPTION: |
---|
756 | |
---|
757 | This directive releases the semaphore specified by |
---|
758 | id. The semaphore count is incremented by one. If the count is |
---|
759 | zero or negative, then the first task on this semaphore's wait |
---|
760 | queue is removed and unblocked. The unblocked task may preempt |
---|
761 | the running task if the running task's preemption mode is |
---|
762 | enabled and the unblocked task has a higher priority than the |
---|
763 | running task. |
---|
764 | |
---|
765 | @subheading NOTES: |
---|
766 | |
---|
767 | The calling task may be preempted if it causes a |
---|
768 | higher priority task to be made ready for execution. |
---|
769 | |
---|
770 | Releasing a global semaphore which does not reside on |
---|
771 | the local node will generate a request telling the remote node |
---|
772 | to release the semaphore. |
---|
773 | |
---|
774 | If the task to be unblocked resides on a different |
---|
775 | node from the semaphore, then the semaphore allocation is |
---|
776 | forwarded to the appropriate node, the waiting task is |
---|
777 | unblocked, and the proxy used to represent the task is reclaimed. |
---|
778 | |
---|
779 | The outermost release of a local, binary, priority |
---|
780 | inheritance or priority ceiling semaphore may result in the |
---|
781 | calling task having its priority lowered. This will occur if |
---|
782 | the calling task holds no other binary semaphores and it has |
---|
783 | inherited a higher priority. |
---|
784 | |
---|