1 | @c |
---|
2 | @c This is the chapter from the RTEMS ITRON User's Guide that |
---|
3 | @c documents the services provided by the semaphore |
---|
4 | @c manager. |
---|
5 | @c |
---|
6 | @c $Id$ |
---|
7 | @c |
---|
8 | |
---|
9 | @chapter Semaphore Manager |
---|
10 | |
---|
11 | @section Introduction |
---|
12 | |
---|
13 | The semaphore manager provides functions to allocate, delete, and |
---|
14 | control counting semaphores. |
---|
15 | |
---|
16 | The services provided by the semaphore manager are: |
---|
17 | |
---|
18 | @itemize @bullet |
---|
19 | @item @code{cre_sem} - Create Semaphore |
---|
20 | @item @code{del_sem} - Delete Semaphore |
---|
21 | @item @code{sig_sem} - Signal Semaphore |
---|
22 | @item @code{wai_sem} - Wait on Semaphore |
---|
23 | @item @code{preq_sem} - Poll and Request Semaphore |
---|
24 | @item @code{twai_sem} - Wait on Semaphore with Timeout |
---|
25 | @item @code{ref_sem} - Reference Semaphore Status |
---|
26 | @end itemize |
---|
27 | |
---|
28 | @section Background |
---|
29 | |
---|
30 | @subsection Theory |
---|
31 | |
---|
32 | Semaphores are used for synchronization and mutual exclusion by indicating |
---|
33 | the availability and number of resources. The task (the task which is |
---|
34 | returning resources) notifying other tasks of an event increases the number |
---|
35 | of resources held by the semaphore by one. The task (the task which |
---|
36 | will obtain resources) waiting for the event decreases the number of |
---|
37 | resources held by the semaphore by one. If the number of resources held by a |
---|
38 | semaphore is insufficient (namely 0), the task requiring resources will |
---|
39 | wait until the next time resources are returned to the semaphore. If there is |
---|
40 | more than one task waiting for a semaphore, the tasks will be placed in the |
---|
41 | queue. |
---|
42 | |
---|
43 | |
---|
44 | @subsection T_CSEM Structure |
---|
45 | |
---|
46 | The T_CSEM structure is used to define the characteristics of a semaphore |
---|
47 | and passed an as argument to the @code{cre_sem} service. The structure |
---|
48 | is defined as follows: |
---|
49 | |
---|
50 | @example |
---|
51 | @group |
---|
52 | typedef struct t_csem @{ |
---|
53 | VP exinf; /* extended information */ |
---|
54 | ATR sematr; /* semaphore attributes */ |
---|
55 | /* Following is the extended function for [level X]. */ |
---|
56 | INT isemcnt; /* initial semaphore count */ |
---|
57 | INT maxsem; /* maximum semaphore count */ |
---|
58 | ... |
---|
59 | /* additional information may be included depending on the |
---|
60 | implementation */ |
---|
61 | ... |
---|
62 | @} T_CSEM; |
---|
63 | |
---|
64 | sematr: |
---|
65 | TA_TFIFO H'0...00 /* waiting tasks are handled by FIFO */ |
---|
66 | TA_TPRI H'0...01 /* waiting tasks are handled by priority */ |
---|
67 | |
---|
68 | @end group |
---|
69 | @end example |
---|
70 | |
---|
71 | where the meaning of each field is: |
---|
72 | |
---|
73 | @table @b |
---|
74 | @item exinf |
---|
75 | is the extended information XXX |
---|
76 | |
---|
77 | @item sematr |
---|
78 | is the attributes for this semaphore. The only attributed |
---|
79 | which can be specified is whether tasks wait in FIFO (@code{TA_TFIFO}) |
---|
80 | or priority (@code{TA_TPRI}) order. |
---|
81 | |
---|
82 | @item isemcnt |
---|
83 | is the initial count of the semaphore. |
---|
84 | |
---|
85 | @item maxsem |
---|
86 | is the maximum count the semaphore may have. It places an upper |
---|
87 | limit on the value taken by the semaphore. |
---|
88 | |
---|
89 | @end table |
---|
90 | |
---|
91 | @subsection T_RSEM Structure |
---|
92 | |
---|
93 | The T_RSEM structure is filled in by the @code{ref_sem} service with |
---|
94 | status and state information on a semaphore. The structure |
---|
95 | is defined as follows: |
---|
96 | |
---|
97 | @example |
---|
98 | @group |
---|
99 | typedef struct t_rsem @{ |
---|
100 | VP exinf; /* extended information */ |
---|
101 | BOOL_ID wtsk; /* indicates whether or not there is a |
---|
102 | waiting task */ |
---|
103 | INT semcnt; /* current semaphore count */ |
---|
104 | ... |
---|
105 | /* additional information may be included depending on the |
---|
106 | implementation */ |
---|
107 | ... |
---|
108 | @} T_RSEM; |
---|
109 | @end group |
---|
110 | @end example |
---|
111 | |
---|
112 | @table @b |
---|
113 | |
---|
114 | @item exinf |
---|
115 | is extended information. |
---|
116 | |
---|
117 | @item wtsk |
---|
118 | is TRUE when there is one or more task waiting on the semaphore. |
---|
119 | It is FALSE if no tasks are currently waiting. |
---|
120 | |
---|
121 | @item semcnt |
---|
122 | is the current semaphore count. |
---|
123 | |
---|
124 | @end table |
---|
125 | |
---|
126 | @section Operations |
---|
127 | |
---|
128 | @subsection Using as a Binary Semaphore |
---|
129 | |
---|
130 | Creating a semaphore with a limit on the count of 1 effectively |
---|
131 | restricts the semaphore to being a binary semaphore. When the |
---|
132 | binary semaphore is available, the count is 1. When the binary |
---|
133 | semaphore is unavailable, the count is 0.; |
---|
134 | |
---|
135 | @section System Calls |
---|
136 | |
---|
137 | This section details the semaphore manager's services. |
---|
138 | A subsection is dedicated to each of this manager's services |
---|
139 | and describes the calling sequence, related constants, usage, |
---|
140 | and status codes. |
---|
141 | |
---|
142 | |
---|
143 | @c |
---|
144 | @c cre_sem |
---|
145 | @c |
---|
146 | |
---|
147 | @page |
---|
148 | @subsection cre_sem - Create Semaphore |
---|
149 | |
---|
150 | @subheading CALLING SEQUENCE: |
---|
151 | |
---|
152 | @ifset is-C |
---|
153 | @example |
---|
154 | ER cre_sem( |
---|
155 | ID semid, |
---|
156 | T_CSEM *pk_csem |
---|
157 | ); |
---|
158 | @end example |
---|
159 | @end ifset |
---|
160 | |
---|
161 | @ifset is-Ada |
---|
162 | @end ifset |
---|
163 | |
---|
164 | @subheading STATUS CODES: |
---|
165 | |
---|
166 | @code{E_OK} - Normal Completion |
---|
167 | |
---|
168 | @code{E_NOMEM} - Insufficient memory (Memory for control block cannot be |
---|
169 | allocated) |
---|
170 | |
---|
171 | @code{E_ID} - Invalid ID number (semid was invalid or could not be used) |
---|
172 | |
---|
173 | @code{E_RSATR} - Reserved attribute (sematr was invalid or could not be |
---|
174 | used) |
---|
175 | |
---|
176 | @code{E_OBJ} - Invalid object state (a semaphore of the same ID already |
---|
177 | exists) |
---|
178 | |
---|
179 | @code{E_OACV} - Object access violation (A semid less than -4 was |
---|
180 | specified from a user task. This is implementation dependent.) |
---|
181 | |
---|
182 | @code{E_PAR} - Parameter error (pk_csem is invalid and/or isemcnt or |
---|
183 | maxsem is negative or invalid) |
---|
184 | |
---|
185 | @code{EN_OBJNO} - An object number which could not be accessed on the |
---|
186 | target node is specified. |
---|
187 | |
---|
188 | @code{EN_CTXID} - Specified an object on another node when the system call |
---|
189 | was issued from a task in dispatch disabled state or from a task- |
---|
190 | independent portion |
---|
191 | |
---|
192 | @code{EN_PAR} - A value outside the range supported by the target node |
---|
193 | and/or transmission packet format was specified as a parameter (a value |
---|
194 | outside supported range was specified for exinf, sematr, isemcnt and/or |
---|
195 | maxsem) |
---|
196 | |
---|
197 | @subheading DESCRIPTION: |
---|
198 | |
---|
199 | |
---|
200 | |
---|
201 | @subheading NOTES: |
---|
202 | |
---|
203 | NONE |
---|
204 | |
---|
205 | |
---|
206 | @c |
---|
207 | @c del_sem |
---|
208 | @c |
---|
209 | |
---|
210 | @page |
---|
211 | @subsection del_sem - Delete Semaphore |
---|
212 | |
---|
213 | @subheading CALLING SEQUENCE: |
---|
214 | |
---|
215 | @ifset is-C |
---|
216 | @example |
---|
217 | ER del_sem( |
---|
218 | ID semid |
---|
219 | ); |
---|
220 | @end example |
---|
221 | @end ifset |
---|
222 | |
---|
223 | @ifset is-Ada |
---|
224 | @end ifset |
---|
225 | |
---|
226 | @subheading STATUS CODES: |
---|
227 | |
---|
228 | @subheading DESCRIPTION: |
---|
229 | |
---|
230 | @code{E_OK} - Normal Completion |
---|
231 | |
---|
232 | @code{E_ID} - Invalid ID number (semid was invalid or could not be used) |
---|
233 | |
---|
234 | @code{E_NOEXS} - Object does not exist (the semaphore specified by semid |
---|
235 | does not exist) |
---|
236 | |
---|
237 | @code{E_OACV} - Object access violation (A semid less than -4 was |
---|
238 | specified from a user task. This is implementation dependent.) |
---|
239 | |
---|
240 | @code{EN_OBJNO} - An object number which could not be accessed on the |
---|
241 | target node is specified. |
---|
242 | |
---|
243 | @code{EN_CTXID} - Specified an object on another node when the system call |
---|
244 | was issued from a task in dispatch disabled state or from a |
---|
245 | task-independent portion |
---|
246 | |
---|
247 | |
---|
248 | @subheading NOTES: |
---|
249 | |
---|
250 | NONE |
---|
251 | |
---|
252 | |
---|
253 | @c |
---|
254 | @c sig_sem |
---|
255 | @c |
---|
256 | |
---|
257 | @page |
---|
258 | @subsection sig_sem - Signal Semaphore |
---|
259 | |
---|
260 | @subheading CALLING SEQUENCE: |
---|
261 | |
---|
262 | @ifset is-C |
---|
263 | @example |
---|
264 | ER sig_sem( |
---|
265 | ID semid |
---|
266 | ); |
---|
267 | @end example |
---|
268 | @end ifset |
---|
269 | |
---|
270 | @ifset is-Ada |
---|
271 | @end ifset |
---|
272 | |
---|
273 | @subheading STATUS CODES: |
---|
274 | |
---|
275 | @code{E_OK} - Normal Completion |
---|
276 | |
---|
277 | @code{E_ID} - Invalid ID number (semid was invalid or could not be used) |
---|
278 | |
---|
279 | @code{E_NOEXS} - Object does not exist (the semaphore specified by semid |
---|
280 | does not exist) |
---|
281 | |
---|
282 | @code{E_OACV} - Object access violation (A semid less than -4 was |
---|
283 | specified from a user task. This is implementation dependent.) |
---|
284 | |
---|
285 | @code{E_QOVR} - Queuing or nesting overflow (the queuing count given by |
---|
286 | semcnt went over the maximum allowed) |
---|
287 | |
---|
288 | @code{EN_OBJNO} - An object number which could not be accessed on the |
---|
289 | target node is specified. |
---|
290 | |
---|
291 | @code{EN_CTXID} - Specified an object on another node when the system call |
---|
292 | was issued from a task in dispatch disabled state or from a |
---|
293 | task-independent portion |
---|
294 | |
---|
295 | @subheading DESCRIPTION: |
---|
296 | |
---|
297 | @subheading NOTES: |
---|
298 | |
---|
299 | NONE |
---|
300 | |
---|
301 | |
---|
302 | @c |
---|
303 | @c wai_sem |
---|
304 | @c |
---|
305 | |
---|
306 | @page |
---|
307 | @subsection wai_sem - Wait on Semaphore |
---|
308 | |
---|
309 | @subheading CALLING SEQUENCE: |
---|
310 | |
---|
311 | @ifset is-C |
---|
312 | @example |
---|
313 | ER wai_sem( |
---|
314 | ID semid |
---|
315 | ); |
---|
316 | @end example |
---|
317 | @end ifset |
---|
318 | |
---|
319 | @ifset is-Ada |
---|
320 | @end ifset |
---|
321 | |
---|
322 | @subheading STATUS CODES: |
---|
323 | |
---|
324 | @code{E_OK} - Normal Completion |
---|
325 | |
---|
326 | @code{E_ID} - Invalid ID number (semid was invalid or could not be used) |
---|
327 | |
---|
328 | @code{E_NOEXS} - Object does not exist (the semaphore specified by semid |
---|
329 | does not exist) |
---|
330 | |
---|
331 | @code{E_OACV} - Object access violation (A semid less than -4 was |
---|
332 | specified from a user task. This is implementation dependent.) |
---|
333 | |
---|
334 | @code{E_PAR} - Parameter error (tmout is -2 or less) |
---|
335 | |
---|
336 | @code{E_DLT} - The object being waited for was deleted (the specified |
---|
337 | semaphore was deleted while waiting) |
---|
338 | |
---|
339 | @code{E_RLWAI} - Wait state was forcibly released (rel_wai was received |
---|
340 | while waiting) |
---|
341 | |
---|
342 | @code{E_TMOUT} - Polling failure or timeout exceeded |
---|
343 | |
---|
344 | @code{E_CTX} - Context error (issued from task-independent portions or a |
---|
345 | task in dispatch disabled state) |
---|
346 | |
---|
347 | @code{EN_OBJNO} - An object number which could not be accessed on the |
---|
348 | target node is specified. |
---|
349 | |
---|
350 | @code{EN_PAR} - A value outside the range supported by the target node |
---|
351 | and/or transmission packet format was specified as a parameter (a value |
---|
352 | outside supported range was specified for tmout) |
---|
353 | |
---|
354 | |
---|
355 | @subheading DESCRIPTION: |
---|
356 | |
---|
357 | @subheading NOTES: |
---|
358 | |
---|
359 | NONE |
---|
360 | |
---|
361 | |
---|
362 | @c |
---|
363 | @c preq_sem |
---|
364 | @c |
---|
365 | |
---|
366 | @page |
---|
367 | @subsection preq_sem - Poll and Request Semaphore |
---|
368 | |
---|
369 | @subheading CALLING SEQUENCE: |
---|
370 | |
---|
371 | @ifset is-C |
---|
372 | @example |
---|
373 | ER preq_sem( |
---|
374 | ID semid |
---|
375 | ); |
---|
376 | @end example |
---|
377 | @end ifset |
---|
378 | |
---|
379 | @ifset is-Ada |
---|
380 | @end ifset |
---|
381 | |
---|
382 | @subheading STATUS CODES: |
---|
383 | |
---|
384 | @code{E_OK} - Normal Completion |
---|
385 | |
---|
386 | @code{E_ID} - Invalid ID number (semid was invalid or could not be used) |
---|
387 | |
---|
388 | @code{E_NOEXS} - Object does not exist (the semaphore specified by semid |
---|
389 | does not exist) |
---|
390 | |
---|
391 | @code{E_OACV} - Object access violation (A semid less than -4 was |
---|
392 | specified from a user task. This is implementation dependent.) |
---|
393 | |
---|
394 | @code{E_PAR} - Parameter error (tmout is -2 or less) |
---|
395 | |
---|
396 | @code{E_DLT} - The object being waited for was deleted (the specified |
---|
397 | semaphore was deleted while waiting) |
---|
398 | |
---|
399 | @code{E_RLWAI} - Wait state was forcibly released (rel_wai was received |
---|
400 | while waiting) |
---|
401 | |
---|
402 | @code{E_TMOUT} - Polling failure or timeout exceeded |
---|
403 | |
---|
404 | @code{E_CTX} - Context error (issued from task-independent portions or a |
---|
405 | task in dispatch disabled state) |
---|
406 | |
---|
407 | @code{EN_OBJNO} - An object number which could not be accessed on the |
---|
408 | target node is specified. |
---|
409 | |
---|
410 | @code{EN_PAR} - A value outside the range supported by the target node |
---|
411 | and/or transmission packet format was specified as a parameter (a value |
---|
412 | outside supported range was specified for tmout) |
---|
413 | |
---|
414 | |
---|
415 | @subheading DESCRIPTION: |
---|
416 | |
---|
417 | @subheading NOTES: |
---|
418 | |
---|
419 | NONE |
---|
420 | |
---|
421 | |
---|
422 | @c |
---|
423 | @c twai_sem |
---|
424 | @c |
---|
425 | |
---|
426 | @page |
---|
427 | @subsection twai_sem - Wait on Semaphore with Timeout |
---|
428 | |
---|
429 | @subheading CALLING SEQUENCE: |
---|
430 | |
---|
431 | @ifset is-C |
---|
432 | @example |
---|
433 | ER twai_sem( |
---|
434 | ID semid, |
---|
435 | TMO tmout |
---|
436 | ); |
---|
437 | @end example |
---|
438 | @end ifset |
---|
439 | |
---|
440 | @ifset is-Ada |
---|
441 | @end ifset |
---|
442 | |
---|
443 | @subheading STATUS CODES: |
---|
444 | |
---|
445 | @code{E_OK} - Normal Completion |
---|
446 | |
---|
447 | @code{E_ID} - Invalid ID number (semid was invalid or could not be used) |
---|
448 | |
---|
449 | @code{E_NOEXS} - Object does not exist (the semaphore specified by semid |
---|
450 | does not exist) |
---|
451 | |
---|
452 | @code{E_OACV} - Object access violation (A semid less than -4 was |
---|
453 | specified from a user task. This is implementation dependent.) |
---|
454 | |
---|
455 | @code{E_PAR} - Parameter error (tmout is -2 or less) |
---|
456 | |
---|
457 | @code{E_DLT} - The object being waited for was deleted (the specified |
---|
458 | semaphore was deleted while waiting) |
---|
459 | |
---|
460 | @code{E_RLWAI} - Wait state was forcibly released (rel_wai was received |
---|
461 | while waiting) |
---|
462 | |
---|
463 | @code{E_TMOUT} - Polling failure or timeout exceeded |
---|
464 | |
---|
465 | @code{E_CTX} - Context error (issued from task-independent portions or a |
---|
466 | task in dispatch disabled state) |
---|
467 | |
---|
468 | @code{EN_OBJNO} - An object number which could not be accessed on the |
---|
469 | target node is specified. |
---|
470 | |
---|
471 | @code{EN_PAR} - A value outside the range supported by the target node |
---|
472 | and/or transmission packet format was specified as a parameter (a value |
---|
473 | outside supported range was specified for tmout) |
---|
474 | |
---|
475 | |
---|
476 | @subheading DESCRIPTION: |
---|
477 | |
---|
478 | @subheading NOTES: |
---|
479 | |
---|
480 | NONE |
---|
481 | |
---|
482 | |
---|
483 | @c |
---|
484 | @c ref_sem |
---|
485 | @c |
---|
486 | |
---|
487 | @page |
---|
488 | @subsection ref_sem - Reference Semaphore Status |
---|
489 | |
---|
490 | @subheading CALLING SEQUENCE: |
---|
491 | |
---|
492 | @ifset is-C |
---|
493 | @example |
---|
494 | ER ref_sem( |
---|
495 | T_RSEM *pk_rsem, |
---|
496 | ID semid |
---|
497 | ); |
---|
498 | @end example |
---|
499 | @end ifset |
---|
500 | |
---|
501 | @ifset is-Ada |
---|
502 | @end ifset |
---|
503 | |
---|
504 | @subheading STATUS CODES: |
---|
505 | |
---|
506 | @code{E_OK} - Normal Completion |
---|
507 | |
---|
508 | @code{E_ID} - Invalid ID number (semid was invalid or could not be used) |
---|
509 | |
---|
510 | @code{E_NOEXS} - Object does not exist (the semaphore specified by semid |
---|
511 | does not exist) |
---|
512 | |
---|
513 | @code{E_OACV} - Object access violation (A semid less than -4 was |
---|
514 | specified from a user task. This is implementation dependent.) |
---|
515 | |
---|
516 | @code{E_PAR} - Parameter error (the packet address for the return |
---|
517 | parameters could not be used) |
---|
518 | |
---|
519 | @code{EN_OBJNO} - An object number which could not be accessed on the |
---|
520 | target node is specified. |
---|
521 | |
---|
522 | @code{EN_CTXID} - Specified an object on another node when the system call |
---|
523 | was issued from a task in dispatch disabled state or from a |
---|
524 | task-independent portion |
---|
525 | |
---|
526 | @code{EN_RPAR} - A value outside the range supported by the requesting |
---|
527 | node and/or transmission packet format was returned as a parameter (a |
---|
528 | value outside supported range was specified for exinf, wtsk or semcnt) |
---|
529 | |
---|
530 | @subheading DESCRIPTION: |
---|
531 | |
---|
532 | @subheading NOTES: |
---|
533 | |
---|
534 | NONE |
---|
535 | |
---|