source: rtems/doc/user/barrier.t @ 880e2f37

4.115
Last change on this file since 880e2f37 was 880e2f37, checked in by Joel Sherrill <joel.sherrill@…>, on 10/02/12 at 16:45:09

User's Guide: Correct typos in return status bullets

  • Property mode set to 100644
File size: 14.9 KB
Line 
1@c
2@c  COPYRIGHT (c) 1988-2007.
3@c  On-Line Applications Research Corporation (OAR).
4@c  All rights reserved.
5
6@chapter Barrier Manager
7
8@cindex barrier
9
10@section Introduction
11
12The barrier manager provides a unique synchronization
13capability which can be used to have a set of tasks block
14and be unblocked as a set.  The directives provided by the
15barrier manager are:
16
17@itemize @bullet
18@item @code{@value{DIRPREFIX}barrier_create} - Create a barrier
19@item @code{@value{DIRPREFIX}barrier_ident} - Get ID of a barrier
20@item @code{@value{DIRPREFIX}barrier_delete} - Delete a barrier
21@item @code{@value{DIRPREFIX}barrier_wait} - Wait at a barrier
22@item @code{@value{DIRPREFIX}barrier_release} - Release a barrier
23@end itemize
24
25@section Background
26
27A barrier can be viewed as a gate at which tasks wait until
28the gate is opened.  This has many analogies in the real world.
29Horses and other farm animals may approach a closed gate and
30gather in front of it, waiting for someone to open the gate so
31they may proceed.  Similarly, cticket holders gather at the gates
32of arenas before concerts or sporting events waiting for the
33arena personnel to open the gates so they may enter.
34
35Barriers are useful during application initialization.  Each
36application task can perform its local initialization before
37waiting for the application as a whole to be initialized.  Once
38all tasks have completed their independent initializations,
39the "application ready" barrier can be released.
40
41@subsection Automatic Versus Manual Barriers
42
43Just as with a real-world gate, barriers may be configured to
44be manually opened or automatically opened.  All tasks
45calling the @code{@value{DIRPREFIX}barrier_wait} directive
46will block until a controlling task invokes the
47@code{@value{DIRPREFIX}barrier_release} directive.
48
49Automatic barriers are created with a limit to the number of
50tasks which may simultaneously block at the barrier.  Once
51this limit is reached, all of the tasks are released.  For
52example, if the automatic limit is ten tasks, then the first
53nine tasks calling the @code{@value{DIRPREFIX}barrier_wait} directive
54will block.  When the tenth task calls the
55@code{@value{DIRPREFIX}barrier_wait} directive, the nine
56blocked tasks will be released and the tenth task returns
57to the caller without blocking.
58
59@subsection Building a Barrier Attribute Set
60
61In general, an attribute set is built by a bitwise OR
62of the desired attribute components.  The following table lists
63the set of valid barrier attributes:
64
65@itemize @bullet
66
67@item @code{@value{RPREFIX}BARRIER_AUTOMATIC_RELEASE} - automatically
68release the barrier when the configured number of tasks are blocked
69
70@item @code{@value{RPREFIX}BARRIER_MANUAL_RELEASE} - only release
71the barrier when the application invokes the
72@code{@value{DIRPREFIX}barrier_release} directive.  (default)
73
74@end itemize
75
76@b{NOTE}: Barriers only support FIFO blocking order because all
77waiting tasks are released as a set.  Thus the released tasks
78will all become ready to execute at the same time and compete
79for the processor based upon their priority.
80
81Attribute values are specifically designed to be
82mutually exclusive, therefore bitwise OR and addition operations
83are equivalent as long as each attribute appears exactly once in
84the component list.  An attribute listed as a default is not
85required to appear in the attribute list, although it is a good
86programming practice to specify default attributes.  If all
87defaults are desired, the attribute
88@code{@value{RPREFIX}DEFAULT_ATTRIBUTES} should be
89specified on this call.
90
91This example demonstrates the attribute_set parameter needed to create a
92barrier with the automatic release policy.  The
93@code{attribute_set} parameter passed to the
94@code{@value{DIRPREFIX}barrier_create} directive will be
95@code{@value{RPREFIX}BARRIER_AUTOMATIC_RELEASE}.  In this case, the
96user must also specify the @i{maximum_waiters} parameter.
97
98@section Operations
99
100@subsection Creating a Barrier
101
102The @code{@value{DIRPREFIX}barrier_create} directive creates
103a barrier with a user-specified name and the desired attributes.
104RTEMS allocates a Barrier Control Block (BCB) from the BCB free list.
105This data structure is used by RTEMS to manage the newly created
106barrier.  Also, a unique barrier ID is generated and returned to
107the calling task.
108
109@subsection Obtaining Barrier IDs
110
111When a barrier is created, RTEMS generates a unique
112barrier ID and assigns it to the created barrier until it is
113deleted.  The barrier ID may be obtained by either of two
114methods.  First, as the result of an invocation of the
115@code{@value{DIRPREFIX}barrier_create} directive, the
116barrier ID is stored in a user provided location.  Second,
117the barrier ID may be obtained later using the
118@code{@value{DIRPREFIX}barrier_ident} directive.  The barrier ID is
119used by other barrier manager directives to access this
120barrier.
121
122@subsection Waiting at a Barrier
123
124The @code{@value{DIRPREFIX}barrier_wait} directive is used to wait at
125the specified barrier.  Since a barrier is, by definition, never immediately,
126the task may wait forever for the barrier to be released or it may
127specify a timeout.  Specifying a timeout limits the interval the task will
128wait before returning with an error status code.
129
130If the barrier is configured as automatic and there are already
131one less then the maximum number of waiters, then the call will
132unblock all tasks waiting at the barrier and the caller will
133return immediately.
134
135When the task does wait to acquire the barrier, then it
136is placed in the barrier's task wait queue in FIFO order.
137All tasks waiting on a barrier are returned an error
138code when the barrier is deleted.
139
140@subsection Releasing a Barrier
141
142The @code{@value{DIRPREFIX}barrier_release} directive is used to release
143the specified barrier.  When the @code{@value{DIRPREFIX}barrier_release}
144is invoked, all tasks waiting at the barrier are immediately made ready
145to execute and begin to compete for the processor to execute.
146
147@subsection Deleting a Barrier
148
149The @code{@value{DIRPREFIX}barrier_delete} directive removes a barrier
150from the system and frees its control block.  A barrier can be
151deleted by any local task that knows the barrier's ID.  As a
152result of this directive, all tasks blocked waiting for the
153barrier to be released, will be readied and returned a status code which
154indicates that the barrier was deleted.  Any subsequent
155references to the barrier's name and ID are invalid.
156
157@section Directives
158
159This section details the barrier manager's
160directives.  A subsection is dedicated to each of this manager's
161directives and describes the calling sequence, related
162constants, usage, and status codes.
163
164@c
165@c
166@c
167@page
168@subsection BARRIER_CREATE - Create a barrier
169
170@cindex create a barrier
171
172@subheading CALLING SEQUENCE:
173
174@ifset is-C
175@findex rtems_barrier_create
176@example
177rtems_status_code rtems_barrier_create(
178  rtems_name           name,
179  rtems_attribute      attribute_set,
180  uint32_t             maximum_waiters,
181  rtems_id            *id
182);
183@end example
184@end ifset
185
186@ifset is-Ada
187@example
188procedure Barrier_Create (
189   Name            : in     RTEMS.Name;
190   Attribute_Set   : in     RTEMS.Attribute;
191   Maximum_Waiters : in     RTEMS.Unsigned32;
192   ID              :    out RTEMS.ID;
193   Result          :    out RTEMS.Status_Codes
194);
195@end example
196@end ifset
197
198@subheading DIRECTIVE STATUS CODES:
199@code{@value{RPREFIX}SUCCESSFUL} - barrier created successfully@*
200@code{@value{RPREFIX}INVALID_NAME} - invalid barrier name@*
201@code{@value{RPREFIX}INVALID_ADDRESS} - @code{id} is NULL@*
202@code{@value{RPREFIX}TOO_MANY} - too many barriers created@
203
204@subheading DESCRIPTION:
205
206This directive creates a barrier which resides on
207the local node. The created barrier has the user-defined name
208specified in @code{name} and the initial count specified in @code{count}.  For
209control and maintenance of the barrier, RTEMS allocates and
210initializes a BCB.  The RTEMS-assigned barrier id is returned
211in @code{id}.  This barrier id is used with other barrier related
212directives to access the barrier.
213
214@code{@value{RPREFIX}BARRIER_MANUAL_RELEASE} - only release
215
216Specifying @code{@value{RPREFIX}BARRIER_AUTOMATIC_RELEASE} in
217@code{attribute_set} causes tasks calling the
218@code{@value{DIRPREFIX}barrier_wait} directive to block until
219there are @code{maximum_waiters - 1} tasks waiting at the barrier.
220When the @code{maximum_waiters} task invokes the
221@code{@value{DIRPREFIX}barrier_wait} directive, the previous
222@code{maximum_waiters - 1} tasks are automatically released
223and the caller returns.
224
225In contrast, when the @code{@value{RPREFIX}BARRIER_MANUAL_RELEASE}
226attribute is specified, there is no limit on the number of
227tasks that will block at the barrier. Only when the
228@code{@value{DIRPREFIX}barrier_release} directive is invoked,
229are the tasks waiting at the barrier unblocked.
230
231@subheading NOTES:
232
233This directive will not cause the calling task to be preempted.
234
235The following barrier attribute constants are defined by RTEMS:
236
237@itemize @bullet
238
239@item @code{@value{RPREFIX}BARRIER_AUTOMATIC_RELEASE} - automatically
240release the barrier when the configured number of tasks are blocked
241
242@item @code{@value{RPREFIX}BARRIER_MANUAL_RELEASE} - only release
243the barrier when the application invokes the
244@code{@value{DIRPREFIX}barrier_release} directive.  (default)
245
246@end itemize
247
248@c
249@c
250@c
251@page
252@subsection BARRIER_IDENT - Get ID of a barrier
253
254@cindex get ID of a barrier
255@cindex obtain ID of a barrier
256
257@subheading CALLING SEQUENCE:
258
259@ifset is-C
260@findex rtems_barrier_ident
261@example
262rtems_status_code rtems_barrier_ident(
263  rtems_name        name,
264  rtems_id         *id
265);
266@end example
267@end ifset
268
269@ifset is-Ada
270@example
271procedure Barrier_Ident (
272   Name   : in     RTEMS.Name;
273   ID     :    out RTEMS.ID;
274   Result :    out RTEMS.Status_Codes
275);
276@end example
277@end ifset
278
279@subheading DIRECTIVE STATUS CODES:
280@code{@value{RPREFIX}SUCCESSFUL} - barrier identified successfully@*
281@code{@value{RPREFIX}INVALID_NAME} - barrier name not found@*
282@code{@value{RPREFIX}INVALID_NODE} - invalid node id
283
284@subheading DESCRIPTION:
285
286This directive obtains the barrier id associated
287with the barrier name.  If the barrier name is not unique,
288then the barrier id will match one of the barriers with that
289name.  However, this barrier id is not guaranteed to
290correspond to the desired barrier.  The barrier id is used
291by other barrier related directives to access the barrier.
292
293@subheading NOTES:
294
295This directive will not cause the running task to be
296preempted.
297
298@c
299@c
300@c
301@page
302@subsection BARRIER_DELETE - Delete a barrier
303
304@cindex delete a barrier
305
306@subheading CALLING SEQUENCE:
307
308@ifset is-C
309@findex rtems_barrier_delete
310@example
311rtems_status_code rtems_barrier_delete(
312  rtems_id id
313);
314@end example
315@end ifset
316
317@ifset is-Ada
318@example
319procedure Barrier_Delete (
320   ID     : in     RTEMS.ID;
321   Result :    out RTEMS.Status_Codes
322);
323@end example
324@end ifset
325
326@subheading DIRECTIVE STATUS CODES:
327@code{@value{RPREFIX}SUCCESSFUL} - barrier deleted successfully@*
328@code{@value{RPREFIX}INVALID_ID} - invalid barrier id@
329
330@subheading DESCRIPTION:
331
332This directive deletes the barrier specified by @code{id}.
333All tasks blocked waiting for the barrier to be released will be
334readied and returned a status code which indicates that the
335barrier was deleted.  The BCB for this barrier is reclaimed
336by RTEMS.
337
338@subheading NOTES:
339
340The calling task will be preempted if it is enabled
341by the task's execution mode and a higher priority local task is
342waiting on the deleted barrier.  The calling task will NOT be
343preempted if all of the tasks that are waiting on the barrier
344are remote tasks.
345
346The calling task does not have to be the task that
347created the barrier.  Any local task that knows the barrier
348id can delete the barrier.
349
350@c
351@c Barrier Obtain
352@c
353@page
354@subsection BARRIER_OBTAIN - Acquire a barrier
355
356@cindex obtain a barrier
357@cindex lock a barrier
358
359@subheading CALLING SEQUENCE:
360
361@ifset is-C
362@findex rtems_barrier_wait
363@example
364rtems_status_code rtems_barrier_wait(
365  rtems_id         id,
366  rtems_interval   timeout
367);
368@end example
369@end ifset
370
371@ifset is-Ada
372@example
373procedure Barrier_Wait (
374   ID         : in     RTEMS.ID;
375   Timeout    : in     RTEMS.Interval;
376   Result     :    out RTEMS.Status_Codes
377);
378@end example
379@end ifset
380
381@subheading DIRECTIVE STATUS CODES:
382@code{@value{RPREFIX}SUCCESSFUL} - barrier released and task unblocked@*
383@code{@value{RPREFIX}UNSATISFIED} - barrier not available@*
384@code{@value{RPREFIX}TIMEOUT} - timed out waiting for barrier@*
385@code{@value{RPREFIX}OBJECT_WAS_DELETED} - barrier deleted while waiting@*
386@code{@value{RPREFIX}INVALID_ID} - invalid barrier id
387
388@subheading DESCRIPTION:
389
390This directive acquires the barrier specified by
391id.  The @code{@value{RPREFIX}WAIT} and @code{@value{RPREFIX}NO_WAIT}
392components of the options parameter indicate whether the calling task
393wants to wait for the barrier to become available or return immediately
394if the barrier is not currently available.  With either
395@code{@value{RPREFIX}WAIT} or @code{@value{RPREFIX}NO_WAIT},
396if the current barrier count is positive, then it is
397decremented by one and the barrier is successfully acquired by
398returning immediately with a successful return code.
399
400Conceptually, the calling task should always be thought
401of as blocking when it makes this call and being unblocked when
402the barrier is released.  If the barrier is configured for
403manual release, this rule of thumb will always be valid.
404If the barrier is configured for automatic release, all callers
405will block except for the one which is the Nth task which trips
406the automatic release condition.
407
408The timeout parameter specifies the maximum interval the calling task is
409willing to be blocked waiting for the barrier.  If it is set to
410@code{@value{RPREFIX}NO_TIMEOUT}, then the calling task will wait forever. 
411If the barrier is available or the @code{@value{RPREFIX}NO_WAIT} option
412component is set, then timeout is ignored.
413
414@subheading NOTES:
415The following barrier acquisition option constants are defined by RTEMS:
416
417@itemize @bullet
418@item @code{@value{RPREFIX}WAIT} - task will wait for barrier (default)
419@item @code{@value{RPREFIX}NO_WAIT} - task should not wait
420@end itemize
421
422A clock tick is required to support the timeout functionality of
423this directive.
424
425@c
426@c Release Barrier
427@c
428@page
429@subsection BARRIER_RELEASE - Release a barrier
430
431@cindex wait at a barrier
432@cindex release a barrier
433
434@subheading CALLING SEQUENCE:
435
436@ifset is-C
437@findex rtems_barrier_release
438@example
439rtems_status_code rtems_barrier_release(
440  rtems_id  id,
441  uint32_t *released
442);
443@end example
444@end ifset
445
446@ifset is-Ada
447@example
448procedure Barrier_Release (
449   ID       : in     RTEMS.ID;
450   Released :    out RTEMS.Unsigned32;
451   Result   :    out RTEMS.Status_Codes
452);
453@end example
454@end ifset
455
456@subheading DIRECTIVE STATUS CODES:
457@code{@value{RPREFIX}SUCCESSFUL} - barrier released successfully@*
458@code{@value{RPREFIX}INVALID_ID} - invalid barrier id@*
459
460@subheading DESCRIPTION:
461
462This directive releases the barrier specified by id.
463All tasks waiting at the barrier will be unblocked.
464If the running task's preemption mode is enabled and one of
465the unblocked tasks has a higher priority than the running task.
466
467@subheading NOTES:
468
469The calling task may be preempted if it causes a
470higher priority task to be made ready for execution.
Note: See TracBrowser for help on using the repository browser.