source: rtems/doc/user/sem.t @ 20515fc

4.104.114.84.95
Last change on this file since 20515fc was 20515fc, checked in by Joel Sherrill <joel.sherrill@…>, on 03/27/98 at 18:53:17

Nodes, menus, etc are automatically generated now

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