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 | |
---|
12 | The barrier manager provides a unique synchronization |
---|
13 | capability which can be used to have a set of tasks block |
---|
14 | and be unblocked as a set. The directives provided by the |
---|
15 | barrier 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 | |
---|
27 | A barrier can be viewed as a gate at which tasks wait until |
---|
28 | the gate is opened. This has many analogies in the real world. |
---|
29 | Horses and other farm animals may approach a closed gate and |
---|
30 | gather in front of it, waiting for someone to open the gate so |
---|
31 | they may proceed. Similarly, cticket holders gather at the gates |
---|
32 | of arenas before concerts or sporting events waiting for the |
---|
33 | arena personnel to open the gates so they may enter. |
---|
34 | |
---|
35 | Barriers are useful during application initialization. Each |
---|
36 | application task can perform its local initialization before |
---|
37 | waiting for the application as a whole to be initialized. Once |
---|
38 | all tasks have completed their independent initializations, |
---|
39 | the "application ready" barrier can be released. |
---|
40 | |
---|
41 | @subsection Automatic Versus Manual Barriers |
---|
42 | |
---|
43 | Just as with a real-world gate, barriers may be configured to |
---|
44 | be manually opened or automatically opened. All tasks |
---|
45 | calling the @code{@value{DIRPREFIX}barrier_wait} directive |
---|
46 | will block until a controlling task invokes the |
---|
47 | @code{@value{DIRPREFIX}barrier_release} directive. |
---|
48 | |
---|
49 | Automatic barriers are created with a limit to the number of |
---|
50 | tasks which may simultaneously block at the barrier. Once |
---|
51 | this limit is reached, all of the tasks are released. For |
---|
52 | example, if the automatic limit is ten tasks, then the first |
---|
53 | nine tasks calling the @code{@value{DIRPREFIX}barrier_wait} directive |
---|
54 | will block. When the tenth task calls the |
---|
55 | @code{@value{DIRPREFIX}barrier_wait} directive, the nine |
---|
56 | blocked tasks will be released and the tenth task returns |
---|
57 | to the caller without blocking. |
---|
58 | |
---|
59 | @subsection Building a Barrier Attribute Set |
---|
60 | |
---|
61 | In general, an attribute set is built by a bitwise OR |
---|
62 | of the desired attribute components. The following table lists |
---|
63 | the set of valid barrier attributes: |
---|
64 | |
---|
65 | @itemize @bullet |
---|
66 | |
---|
67 | @item @code{@value{RPREFIX}BARRIER_AUTOMATIC_RELEASE} - automatically |
---|
68 | release the barrier when the configured number of tasks are blocked |
---|
69 | |
---|
70 | @item @code{@value{RPREFIX}BARRIER_MANUAL_RELEASE} - only release |
---|
71 | the 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 |
---|
77 | waiting tasks are released as a set. Thus the released tasks |
---|
78 | will all become ready to execute at the same time and compete |
---|
79 | for the processor based upon their priority. |
---|
80 | |
---|
81 | Attribute values are specifically designed to be |
---|
82 | mutually exclusive, therefore bitwise OR and addition operations |
---|
83 | are equivalent as long as each attribute appears exactly once in |
---|
84 | the component list. An attribute listed as a default is not |
---|
85 | required to appear in the attribute list, although it is a good |
---|
86 | programming practice to specify default attributes. If all |
---|
87 | defaults are desired, the attribute |
---|
88 | @code{@value{RPREFIX}DEFAULT_ATTRIBUTES} should be |
---|
89 | specified on this call. |
---|
90 | |
---|
91 | This example demonstrates the attribute_set parameter needed to create a |
---|
92 | barrier 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 |
---|
96 | user must also specify the @i{maximum_waiters} parameter. |
---|
97 | |
---|
98 | @section Operations |
---|
99 | |
---|
100 | @subsection Creating a Barrier |
---|
101 | |
---|
102 | The @code{@value{DIRPREFIX}barrier_create} directive creates |
---|
103 | a barrier with a user-specified name and the desired attributes. |
---|
104 | RTEMS allocates a Barrier Control Block (BCB) from the BCB free list. |
---|
105 | This data structure is used by RTEMS to manage the newly created |
---|
106 | barrier. Also, a unique barrier ID is generated and returned to |
---|
107 | the calling task. |
---|
108 | |
---|
109 | @subsection Obtaining Barrier IDs |
---|
110 | |
---|
111 | When a barrier is created, RTEMS generates a unique |
---|
112 | barrier ID and assigns it to the created barrier until it is |
---|
113 | deleted. The barrier ID may be obtained by either of two |
---|
114 | methods. First, as the result of an invocation of the |
---|
115 | @code{@value{DIRPREFIX}barrier_create} directive, the |
---|
116 | barrier ID is stored in a user provided location. Second, |
---|
117 | the barrier ID may be obtained later using the |
---|
118 | @code{@value{DIRPREFIX}barrier_ident} directive. The barrier ID is |
---|
119 | used by other barrier manager directives to access this |
---|
120 | barrier. |
---|
121 | |
---|
122 | @subsection Waiting at a Barrier |
---|
123 | |
---|
124 | The @code{@value{DIRPREFIX}barrier_wait} directive is used to wait at |
---|
125 | the specified barrier. Since a barrier is, by definition, never immediately, |
---|
126 | the task may wait forever for the barrier to be released or it may |
---|
127 | specify a timeout. Specifying a timeout limits the interval the task will |
---|
128 | wait before returning with an error status code. |
---|
129 | |
---|
130 | If the barrier is configured as automatic and there are already |
---|
131 | one less then the maximum number of waiters, then the call will |
---|
132 | unblock all tasks waiting at the barrier and the caller will |
---|
133 | return immediately. |
---|
134 | |
---|
135 | When the task does wait to acquire the barrier, then it |
---|
136 | is placed in the barrier's task wait queue in FIFO order. |
---|
137 | All tasks waiting on a barrier are returned an error |
---|
138 | code when the barrier is deleted. |
---|
139 | |
---|
140 | @subsection Releasing a Barrier |
---|
141 | |
---|
142 | The @code{@value{DIRPREFIX}barrier_release} directive is used to release |
---|
143 | the specified barrier. When the @code{@value{DIRPREFIX}barrier_release} |
---|
144 | is invoked, all tasks waiting at the barrier are immediately made ready |
---|
145 | to execute and begin to compete for the processor to execute. |
---|
146 | |
---|
147 | @subsection Deleting a Barrier |
---|
148 | |
---|
149 | The @code{@value{DIRPREFIX}barrier_delete} directive removes a barrier |
---|
150 | from the system and frees its control block. A barrier can be |
---|
151 | deleted by any local task that knows the barrier's ID. As a |
---|
152 | result of this directive, all tasks blocked waiting for the |
---|
153 | barrier to be released, will be readied and returned a status code which |
---|
154 | indicates that the barrier was deleted. Any subsequent |
---|
155 | references to the barrier's name and ID are invalid. |
---|
156 | |
---|
157 | @section Directives |
---|
158 | |
---|
159 | This section details the barrier manager's |
---|
160 | directives. A subsection is dedicated to each of this manager's |
---|
161 | directives and describes the calling sequence, related |
---|
162 | constants, 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 |
---|
177 | rtems_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 |
---|
188 | procedure 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 | |
---|
206 | This directive creates a barrier which resides on |
---|
207 | the local node. The created barrier has the user-defined name |
---|
208 | specified in @code{name} and the initial count specified in @code{count}. For |
---|
209 | control and maintenance of the barrier, RTEMS allocates and |
---|
210 | initializes a BCB. The RTEMS-assigned barrier id is returned |
---|
211 | in @code{id}. This barrier id is used with other barrier related |
---|
212 | directives to access the barrier. |
---|
213 | |
---|
214 | @code{@value{RPREFIX}BARRIER_MANUAL_RELEASE} - only release |
---|
215 | |
---|
216 | Specifying @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 |
---|
219 | there are @code{maximum_waiters - 1} tasks waiting at the barrier. |
---|
220 | When 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 |
---|
223 | and the caller returns. |
---|
224 | |
---|
225 | In contrast, when the @code{@value{RPREFIX}BARRIER_MANUAL_RELEASE} |
---|
226 | attribute is specified, there is no limit on the number of |
---|
227 | tasks that will block at the barrier. Only when the |
---|
228 | @code{@value{DIRPREFIX}barrier_release} directive is invoked, |
---|
229 | are the tasks waiting at the barrier unblocked. |
---|
230 | |
---|
231 | @subheading NOTES: |
---|
232 | |
---|
233 | This directive will not cause the calling task to be preempted. |
---|
234 | |
---|
235 | The following barrier attribute constants are defined by RTEMS: |
---|
236 | |
---|
237 | @itemize @bullet |
---|
238 | |
---|
239 | @item @code{@value{RPREFIX}BARRIER_AUTOMATIC_RELEASE} - automatically |
---|
240 | release the barrier when the configured number of tasks are blocked |
---|
241 | |
---|
242 | @item @code{@value{RPREFIX}BARRIER_MANUAL_RELEASE} - only release |
---|
243 | the 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 |
---|
262 | rtems_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 |
---|
271 | procedure 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 | |
---|
286 | This directive obtains the barrier id associated |
---|
287 | with the barrier name. If the barrier name is not unique, |
---|
288 | then the barrier id will match one of the barriers with that |
---|
289 | name. However, this barrier id is not guaranteed to |
---|
290 | correspond to the desired barrier. The barrier id is used |
---|
291 | by other barrier related directives to access the barrier. |
---|
292 | |
---|
293 | @subheading NOTES: |
---|
294 | |
---|
295 | This directive will not cause the running task to be |
---|
296 | preempted. |
---|
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 |
---|
311 | rtems_status_code rtems_barrier_delete( |
---|
312 | rtems_id id |
---|
313 | ); |
---|
314 | @end example |
---|
315 | @end ifset |
---|
316 | |
---|
317 | @ifset is-Ada |
---|
318 | @example |
---|
319 | procedure 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 | |
---|
332 | This directive deletes the barrier specified by @code{id}. |
---|
333 | All tasks blocked waiting for the barrier to be released will be |
---|
334 | readied and returned a status code which indicates that the |
---|
335 | barrier was deleted. The BCB for this barrier is reclaimed |
---|
336 | by RTEMS. |
---|
337 | |
---|
338 | @subheading NOTES: |
---|
339 | |
---|
340 | The calling task will be preempted if it is enabled |
---|
341 | by the task's execution mode and a higher priority local task is |
---|
342 | waiting on the deleted barrier. The calling task will NOT be |
---|
343 | preempted if all of the tasks that are waiting on the barrier |
---|
344 | are remote tasks. |
---|
345 | |
---|
346 | The calling task does not have to be the task that |
---|
347 | created the barrier. Any local task that knows the barrier |
---|
348 | id 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 |
---|
364 | rtems_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 |
---|
373 | procedure 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 | |
---|
390 | This directive acquires the barrier specified by |
---|
391 | id. The @code{@value{RPREFIX}WAIT} and @code{@value{RPREFIX}NO_WAIT} |
---|
392 | components of the options parameter indicate whether the calling task |
---|
393 | wants to wait for the barrier to become available or return immediately |
---|
394 | if the barrier is not currently available. With either |
---|
395 | @code{@value{RPREFIX}WAIT} or @code{@value{RPREFIX}NO_WAIT}, |
---|
396 | if the current barrier count is positive, then it is |
---|
397 | decremented by one and the barrier is successfully acquired by |
---|
398 | returning immediately with a successful return code. |
---|
399 | |
---|
400 | Conceptually, the calling task should always be thought |
---|
401 | of as blocking when it makes this call and being unblocked when |
---|
402 | the barrier is released. If the barrier is configured for |
---|
403 | manual release, this rule of thumb will always be valid. |
---|
404 | If the barrier is configured for automatic release, all callers |
---|
405 | will block except for the one which is the Nth task which trips |
---|
406 | the automatic release condition. |
---|
407 | |
---|
408 | The timeout parameter specifies the maximum interval the calling task is |
---|
409 | willing 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. |
---|
411 | If the barrier is available or the @code{@value{RPREFIX}NO_WAIT} option |
---|
412 | component is set, then timeout is ignored. |
---|
413 | |
---|
414 | @subheading NOTES: |
---|
415 | The 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 | |
---|
422 | A clock tick is required to support the timeout functionality of |
---|
423 | this 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 |
---|
439 | rtems_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 |
---|
448 | procedure 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 | |
---|
462 | This directive releases the barrier specified by id. |
---|
463 | All tasks waiting at the barrier will be unblocked. |
---|
464 | If the running task's preemption mode is enabled and one of |
---|
465 | the unblocked tasks has a higher priority than the running task. |
---|
466 | |
---|
467 | @subheading NOTES: |
---|
468 | |
---|
469 | The calling task may be preempted if it causes a |
---|
470 | higher priority task to be made ready for execution. |
---|