source: rtems/doc/user/sem.t @ 61389eac

4.104.114.84.95
Last change on this file since 61389eac was 61389eac, checked in by Joel Sherrill <joel.sherrill@…>, on 05/29/97 at 21:53:58

first cut at Ada bindings manual

  • Property mode set to 100644
File size: 28.6 KB
Line 
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
25The semaphore manager utilizes standard Dijkstra
26counting semaphores to provide synchronization and mutual
27exclusion capabilities.  The directives provided by the
28semaphore 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
53A semaphore can be viewed as a protected variable
54whose value can be modified only with the semaphore_create,
55semaphore_obtain, and semaphore_release directives.  RTEMS
56supports both binary and counting semaphores. A binary semaphore
57is restricted to values of zero or one, while a counting
58semaphore can assume any non-negative integer value.
59
60A binary semaphore can be used to control access to a
61single resource.  In particular, it can be used to enforce
62mutual exclusion for a critical section in user code.  In this
63instance, the semaphore would be created with an initial count
64of one to indicate that no task is executing the critical
65section of code.  Upon entry to the critical section, a task
66must issue the semaphore_obtain directive to prevent other tasks
67from entering the critical section.  Upon exit from the critical
68section, the task must issue the semaphore_release directive to
69allow another task to execute the critical section.
70
71A counting semaphore can be used to control access to
72a pool of two or more resources.  For example, access to three
73printers could be administered by a semaphore created with an
74initial count of three.  When a task requires access to one of
75the printers, it issues the semaphore_obtain directive to obtain
76access to a printer.  If a printer is not currently available,
77the task can wait for a printer to become available or return
78immediately.  When the task has completed printing, it should
79issue the semaphore_release directive to allow other tasks
80access to the printer.
81
82Task synchronization may be achieved by creating a
83semaphore with an initial count of zero.  One task waits for the
84arrival of another task by issuing a semaphore_obtain directive
85when it reaches a synchronization point.  The other task
86performs a corresponding semaphore_release operation when it
87reaches its synchronization point, thus unblocking the pending
88task.
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
95Deadlock occurs when a task owning a binary semaphore
96attempts to acquire that same semaphore and blocks as result.
97Since the semaphore is allocated to a task, it cannot be
98deleted.  Therefore, the task that currently holds the semaphore
99and is also blocked waiting for that semaphore will never
100execute again.
101
102RTEMS addresses this problem by allowing the task
103holding the binary semaphore to obtain the same binary semaphore
104multiple times in a nested manner.  Each semaphore_obtain must
105be accompanied with a semaphore_release.  The semaphore will
106only be made available for acquisition by other tasks when the
107outermost 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
115Priority inversion is a form of indefinite
116postponement which is common in multitasking, preemptive
117executives with shared resources.  Priority inversion occurs
118when a high priority tasks requests access to shared resource
119which is currently allocated to low priority task.  The high
120priority task must block until the low priority task releases
121the resource.  This problem is exacerbated when the low priority
122task is prevented from executing by one or more medium priority
123tasks.  Because the low priority task is not executing, it
124cannot complete its interaction with the resource and release
125that resource.  The high priority task is effectively prevented
126from 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
133Priority inheritance is an algorithm that calls for
134the lower priority task holding a resource to have its priority
135increased to that of the highest priority task blocked waiting
136for that resource.  Each time a task blocks attempting to obtain
137the resource, the task holding the resource may have its
138priority increased.
139
140RTEMS supports priority inheritance for local, binary
141semaphores that use the priority task wait queue blocking
142discipline.   When a task of higher priority than the task
143holding the semaphore blocks, the priority of the task holding
144the semaphore is increased to that of the blocking task.  When
145the task holding the task completely releases the binary
146semaphore (i.e. not for a nested release), the holder's priority
147is restored to the value it had before any higher priority was
148inherited.
149
150The RTEMS implementation of the priority inheritance
151algorithm takes into account the scenario in which a task holds
152more than one binary semaphore.  The holding task will execute
153at the priority of the higher of the highest ceiling priority or
154at the priority of the highest priority task blocked waiting for
155any of the semaphores the task holds.  Only when the task
156releases ALL of the binary semaphores it holds will its priority
157be 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
164Priority ceiling is an algorithm that calls for the
165lower priority task holding a resource to have its priority
166increased to that of the highest priority task which will EVER
167block waiting for that resource.  This algorithm addresses the
168problem of priority inversion although it avoids the possibility
169of changing the priority of the task holding the resource
170multiple times.  The priority ceiling algorithm will only change
171the priority of the task holding the resource a maximum of one
172time.  The ceiling priority is set at creation time and must be
173the priority of the highest priority task which will ever
174attempt to acquire that semaphore.
175
176RTEMS supports priority ceiling for local, binary
177semaphores that use the priority task wait queue blocking
178discipline.   When a task of lower priority than the ceiling
179priority successfully obtains the semaphore, its priority is
180raised to the ceiling priority.  When the task holding the task
181completely releases the binary semaphore (i.e. not for a nested
182release), the holder's priority is restored to the value it had
183before any higher priority was put into effect.
184
185The need to identify the highest priority task which
186will attempt to obtain a particular semaphore can be a difficult
187task in a large, complicated system.  Although the priority
188ceiling algorithm is more efficient than the priority
189inheritance algorithm with respect to the maximum number of task
190priority changes which may occur while a task holds a particular
191semaphore, the priority inheritance algorithm is more forgiving
192in that it does not require this apriori information.
193
194The RTEMS implementation of the priority ceiling
195algorithm takes into account the scenario in which a task holds
196more than one binary semaphore.  The holding task will execute
197at the priority of the higher of the highest ceiling priority or
198at the priority of the highest priority task blocked waiting for
199any of the semaphores the task holds.  Only when the task
200releases ALL of the binary semaphores it holds will its priority
201be 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
208In general, an attribute set is built by a bitwise OR
209of the desired attribute components.  The following table lists
210the 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
225Attribute values are specifically designed to be
226mutually exclusive, therefore bitwise OR and addition operations
227are equivalent as long as each attribute appears exactly once in
228the component list.  An attribute listed as a default is not
229required to appear in the attribute list, although it is a good
230programming practice to specify default attributes.  If all
231defaults are desired, the attribute DEFAULT_ATTRIBUTES should be
232specified on this call.
233
234This example demonstrates the attribute_set parameter
235needed to create a local semaphore with the task priority
236waiting queue discipline.  The attribute_set parameter passed to
237the semaphore_create directive could be either PRIORITY or LOCAL
238| PRIORITY.  The attribute_set parameter can be set to PRIORITY
239because LOCAL is the default for all created tasks.  If a
240similar semaphore were to be known globally, then the
241attribute_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
248In general, an option is built by a bitwise OR of the
249desired option components.  The set of valid options for the
250semaphore_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
257Option values are specifically designed to be
258mutually exclusive, therefore bitwise OR and addition operations
259are equivalent as long as each attribute appears exactly once in
260the component list.  An option listed as a default is not
261required to appear in the list, although it is a good
262programming practice to specify default options.  If all
263defaults are desired, the option DEFAULT_OPTIONS should be
264specified on this call.
265
266This example demonstrates the option parameter needed
267to poll for a semaphore.  The option parameter passed to the
268semaphore_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
289The semaphore_create directive creates a binary or
290counting semaphore with a user-specified name as well as an
291initial count.  If a binary semaphore is created with a count of
292zero (0) to indicate that it has been allocated, then the task
293creating the semaphore is considered the current holder of the
294semaphore.  At create time the method for ordering waiting tasks
295in the semaphore's task wait queue (by FIFO or task priority) is
296specified.  Additionally, the priority inheritance or priority
297ceiling algorithm may be selected for local, binary semaphores
298that use the priority task wait queue blocking discipline.  If
299the priority ceiling algorithm is selected, then the highest
300priority of any task which will attempt to obtain this semaphore
301must be specified.  RTEMS allocates a Semaphore Control Block
302(SMCB) from the SMCB free list.  This data structure is used by
303RTEMS to manage the newly created semaphore.  Also, a unique
304semaphore 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
311When a semaphore is created, RTEMS generates a unique
312semaphore ID and assigns it to the created semaphore until it is
313deleted.  The semaphore ID may be obtained by either of two
314methods.  First, as the result of an invocation of the
315semaphore_create directive, the semaphore ID is stored in a user
316provided location.  Second, the semaphore ID may be obtained
317later using the semaphore_ident directive.  The semaphore ID is
318used by other semaphore manager directives to access this
319semaphore.
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
326The semaphore_obtain directive is used to acquire the
327specified semaphore.  A simplified version of the
328semaphore_obtain directive can be described as follows:
329
330@example
331if semaphore's count is greater than zero
332   then decrement semaphore's count
333   else wait for release of semaphore
334
335return SUCCESSFUL
336@end example
337
338When the semaphore cannot be immediately acquired,
339one of the following situations applies:
340
341@itemize @bullet
342@item By default, the calling task will wait forever to
343acquire the semaphore.
344
345@item Specifying NO_WAIT forces an immediate return with an
346error status code.
347
348@item Specifying a timeout limits the interval the task will
349wait before returning with an error status code.
350@end itemize
351
352If the task waits to acquire the semaphore, then it
353is placed in the semaphore's task wait queue in either FIFO or
354task priority order.  If the task blocked waiting for a binary
355semaphore using priority inheritance and the task's priority is
356greater than that of the task currently holding the semaphore,
357then the holding task will inherit the priority of the blocking
358task.  All tasks waiting on a semaphore are returned an error
359code when the semaphore is deleted.
360
361When a task successfully obtains a semaphore using
362priority ceiling and the priority ceiling for this semaphore is
363greater than that of the holder, then the holder's priority will
364be 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
371The semaphore_release directive is used to release
372the specified semaphore.  A simplified version of the
373semaphore_release directive can be described as follows:
374
375@example
376if no tasks are waiting on this semaphore
377   then increment semaphore's count
378   else assign semaphore to a waiting task
379
380return SUCCESSFUL
381@end example
382
383If this is the outermost release of a binary
384semaphore that uses priority inheritance or priority ceiling and
385the task does not currently hold any other binary semaphores,
386then the task performing the semaphore_release will have its
387priority 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
394The semaphore_delete directive removes a semaphore
395from the system and frees its control block.  A semaphore can be
396deleted by any local task that knows the semaphore's ID.  As a
397result of this directive, all tasks blocked waiting to acquire
398the semaphore will be readied and returned a status code which
399indicates that the semaphore was deleted.  Any subsequent
400references 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
416This section details the semaphore manager's
417directives.  A subsection is dedicated to each of this manager's
418directives and describes the calling sequence, related
419constants, 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
431rtems_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
443procedure 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
464This directive creates a semaphore which resides on
465the local node. The created semaphore has the user-defined name
466specified in name and the initial count specified in count.  For
467control and maintenance of the semaphore, RTEMS allocates and
468initializes a SMCB.  The RTEMS-assigned semaphore id is returned
469in id.  This semaphore id is used with other semaphore related
470directives to access the semaphore.
471
472Specifying PRIORITY in attribute_set causes tasks
473waiting for a semaphore to be serviced according to task
474priority.  When FIFO is selected, tasks are serviced in First
475In-First Out order.
476
477@subheading NOTES:
478
479This directive will not cause the calling task to be
480preempted.
481
482The priority inheritance and priority ceiling
483algorithms are only supported for local, binary semaphores that
484use the priority task wait queue blocking discipline.
485
486The following semaphore attribute constants are
487defined 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
504Semaphores should not be made global unless remote
505tasks must interact with the created semaphore.  This is to
506avoid the system overhead incurred by the creation of a global
507semaphore.  When a global semaphore is created, the semaphore's
508name and id must be transmitted to every node in the system for
509insertion in the local copy of the global object table.
510
511The total number of global objects, including
512semaphores, is limited by the maximum_global_objects field in
513the 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
525rtems_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
535procedure 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
551This directive obtains the semaphore id associated
552with the semaphore name.  If the semaphore name is not unique,
553then the semaphore id will match one of the semaphores with that
554name.  However, this semaphore id is not guaranteed to
555correspond to the desired semaphore.  The semaphore id is used
556by other semaphore related directives to access the semaphore.
557
558@subheading NOTES:
559
560This directive will not cause the running task to be
561preempted.
562
563If node is SEARCH_ALL_NODES, all nodes are searched
564with the local node being searched first.  All other nodes are
565searched with the lowest numbered node searched first.
566
567If node is a valid node number which does not
568represent the local node, then only the semaphores exported by
569the designated node are searched.
570
571This directive does not generate activity on remote
572nodes.  It accesses only the local copy of the global object
573table.
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
585rtems_status_code rtems_semaphore_delete(
586  rtems_id id
587);
588@end example
589@end ifset
590
591@ifset is-Ada
592@example
593procedure 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
608This directive deletes the semaphore specified by id.
609All tasks blocked waiting to acquire the semaphore will be
610readied and returned a status code which indicates that the
611semaphore was deleted.  The SMCB for this semaphore is reclaimed
612by RTEMS.
613
614@subheading NOTES:
615
616The calling task will be preempted if it is enabled
617by the task's execution mode and a higher priority local task is
618waiting on the deleted semaphore.  The calling task will NOT be
619preempted if all of the tasks that are waiting on the semaphore
620are remote tasks.
621
622The calling task does not have to be the task that
623created the semaphore.  Any local task that knows the semaphore
624id can delete the semaphore.
625
626When a global semaphore is deleted, the semaphore id
627must be transmitted to every node in the system for deletion
628from the local copy of the global object table.
629
630The semaphore must reside on the local node, even if
631the semaphore was created with the GLOBAL option.
632
633Proxies, used to represent remote tasks, are
634reclaimed 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
646rtems_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
656procedure 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
674This directive acquires the semaphore specified by
675id.  The WAIT and NO_WAIT components of the options parameter
676indicate whether the calling task wants to wait for the
677semaphore to become available or return immediately if the
678semaphore is not currently available.  With either WAIT or
679NO_WAIT, if the current semaphore count is positive, then it is
680decremented by one and the semaphore is successfully acquired by
681returning immediately with a successful return code.
682
683If the calling task chooses to return immediately and
684the current semaphore count is zero or negative, then a status
685code is returned indicating that the semaphore is not available.
686If the calling task chooses to wait for a semaphore and the
687current semaphore count is zero or negative, then it is
688decremented by one and the calling task is placed on the
689semaphore's wait queue and blocked.  If the semaphore was
690created with the PRIORITY attribute, then the calling task is
691inserted into the queue according to its priority.  However, if
692the semaphore was created with the FIFO attribute, then the
693calling task is placed at the rear of the wait queue.  If the
694binary semaphore was created with the INHERIT_PRIORITY
695attribute, then the priority of the task currently holding the
696binary semaphore is guaranteed to be greater than or equal to
697that of the blocking task.  If the binary semaphore was created
698with the PRIORITY_CEILING attribute, a task successfully obtains
699the semaphore, and the priority of that task is greater than the
700ceiling priority for this semaphore, then the priority of the
701task obtaining the semaphore is elevated to that of the ceiling.
702
703The timeout parameter specifies the maximum interval
704the calling task is willing to be blocked waiting for the
705semaphore.  If it is set to NO_TIMEOUT, then the calling task
706will wait forever.  If the semaphore is available or the NO_WAIT
707option component is set, then timeout is ignored.
708
709@subheading NOTES:
710The following semaphore acquisition option constants
711are 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
718Attempting to obtain a global semaphore which does not reside on
719the local node will generate a request to the remote node to
720access the semaphore.  If the semaphore is not available and
721NO_WAIT was not specified, then the task must be blocked until
722the semaphore is released.  A proxy is allocated on the remote
723node 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
735rtems_status_code rtems_semaphore_release(
736  rtems_id id
737);
738@end example
739@end ifset
740
741@ifset is-Ada
742@example
743procedure 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
757This directive releases the semaphore specified by
758id.  The semaphore count is incremented by one.  If the count is
759zero or negative, then the first task on this semaphore's wait
760queue is removed and unblocked.  The unblocked task may preempt
761the running task if the running task's preemption mode is
762enabled and the unblocked task has a higher priority than the
763running task.
764
765@subheading NOTES:
766
767The calling task may be preempted if it causes a
768higher priority task to be made ready for execution.
769
770Releasing a global semaphore which does not reside on
771the local node will generate a request telling the remote node
772to release the semaphore.
773
774If the task to be unblocked resides on a different
775node from the semaphore, then the semaphore allocation is
776forwarded to the appropriate node, the waiting task is
777unblocked, and the proxy used to represent the task is reclaimed.
778
779The outermost release of a local, binary, priority
780inheritance or priority ceiling semaphore may result in the
781calling task having its priority lowered.  This will occur if
782the calling task holds no other binary semaphores and it has
783inherited a higher priority.
784
Note: See TracBrowser for help on using the repository browser.