source: rtems/doc/user/sem.t @ 139b2e4a

4.104.114.84.95
Last change on this file since 139b2e4a was 139b2e4a, checked in by Joel Sherrill <joel.sherrill@…>, on 06/04/97 at 18:32:07

added CVS Id string

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