source: rtems/doc/itron3.0/semaphore.t @ 110bdfe

4.104.114.84.95
Last change on this file since 110bdfe was 110bdfe, checked in by Joel Sherrill <joel.sherrill@…>, on 05/26/99 at 18:20:40

Made the gen_section more accurate.

  • Property mode set to 100644
File size: 12.1 KB
Line 
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
13The semaphore manager provides functions to allocate, delete, and
14control counting semaphores.
15
16The 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
32Semaphores are used for synchronization and mutual exclusion by indicating
33the availability and number of resources.  The task (the task which is
34returning resources) notifying other tasks of an event increases the number
35of resources held by the semaphore by one.  The task (the task which
36will obtain resources) waiting for the event decreases the number of
37resources held by the semaphore by one.  If the number of resources held by a
38semaphore is insufficient (namely 0), the task requiring resources will
39wait until the next time resources are returned to the semaphore.  If there is
40more than one task waiting for a semaphore, the tasks will be placed in the
41queue.
42
43
44@subsection T_CSEM Structure
45
46The T_CSEM structure is used to define the characteristics of a semaphore
47and passed an as argument to the @code{cre_sem} service.  The structure
48is defined as follows:
49
50@example
51@group
52typedef 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
64sematr:
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
71where the meaning of each field is:
72
73@table @b
74@item exinf
75is the extended information XXX
76
77@item sematr
78is the attributes for this semaphore.  The only attributed
79which can be specified is whether tasks wait in FIFO (@code{TA_TFIFO})
80or priority (@code{TA_TPRI}) order.
81
82@item isemcnt
83is the initial count of the semaphore.
84
85@item maxsem
86is the maximum count the semaphore may have.  It places an upper
87limit on the value taken by the semaphore.
88
89@end table
90
91@subsection T_RSEM Structure
92
93The T_RSEM structure is filled in by the @code{ref_sem} service with
94status and state information on a semaphore.  The structure
95is defined as follows:
96
97@example
98@group
99typedef 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
115is extended information.
116
117@item wtsk
118is TRUE when there is one or more task waiting on the semaphore.
119It is FALSE if no tasks are currently waiting.
120
121@item semcnt
122is the current semaphore count.
123
124@end table
125
126@section Operations
127
128@subsection Using as a Binary Semaphore
129
130Creating a semaphore with a limit on the count of 1 effectively
131restricts the semaphore to being a binary semaphore.  When the
132binary semaphore is available, the count is 1.  When the binary
133semaphore is unavailable, the count is 0.;
134
135@section System Calls
136
137This section details the semaphore manager's services.
138A subsection is dedicated to each of this manager's services
139and describes the calling sequence, related constants, usage,
140and 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
154ER 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
169allocated)
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
174used)
175
176@code{E_OBJ} - Invalid object state (a semaphore of the same ID already
177exists)
178
179@code{E_OACV} - Object access violation (A semid less than -4 was
180specified from a user task.  This is implementation dependent.)
181
182@code{E_PAR} - Parameter error (pk_csem is invalid and/or isemcnt or
183maxsem is negative or invalid)
184
185@code{EN_OBJNO} - An object number which could not be accessed on the
186target node is specified.
187
188@code{EN_CTXID} - Specified an object on another node when the system call
189was issued from a task in dispatch disabled state or from a task-
190independent portion
191
192@code{EN_PAR} - A value outside the range supported by the target node
193and/or transmission packet format was specified as a parameter (a value
194outside supported range was specified for exinf, sematr, isemcnt and/or
195maxsem)
196
197@subheading DESCRIPTION:
198
199
200
201@subheading NOTES:
202
203NONE
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
217ER 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
235does not exist)
236
237@code{E_OACV} - Object access violation (A semid less than -4 was
238specified from a user task.  This is implementation dependent.)
239
240@code{EN_OBJNO} - An object number which could not be accessed on the
241target node is specified.
242
243@code{EN_CTXID} - Specified an object on another node when the system call
244was issued from a task in dispatch disabled state or from a
245task-independent portion
246
247
248@subheading NOTES:
249
250NONE
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
264ER 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
280does not exist)
281
282@code{E_OACV} - Object access violation (A semid less than -4 was
283specified from a user task.  This is implementation dependent.)
284
285@code{E_QOVR} - Queuing or nesting overflow (the queuing count given by
286semcnt went over the maximum allowed)
287
288@code{EN_OBJNO} - An object number which could not be accessed on the
289target node is specified.
290
291@code{EN_CTXID} - Specified an object on another node when the system call
292was issued from a task in dispatch disabled state or from a
293task-independent portion
294
295@subheading DESCRIPTION:
296
297@subheading NOTES:
298
299NONE
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
313ER 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
329does not exist)
330
331@code{E_OACV} - Object access violation (A semid less than -4 was
332specified 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
337semaphore was deleted while waiting)
338
339@code{E_RLWAI} - Wait state was forcibly released (rel_wai was received
340while 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
345task in dispatch disabled state)
346
347@code{EN_OBJNO} - An object number which could not be accessed on the
348target node is specified.
349
350@code{EN_PAR} - A value outside the range supported by the target node
351and/or transmission packet format was specified as a parameter (a value
352outside supported range was specified for tmout)
353
354
355@subheading DESCRIPTION:
356
357@subheading NOTES:
358
359NONE
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
373ER 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
389does not exist)
390
391@code{E_OACV} - Object access violation (A semid less than -4 was
392specified 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
397semaphore was deleted while waiting)
398
399@code{E_RLWAI} - Wait state was forcibly released (rel_wai was received
400while 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
405task in dispatch disabled state)
406
407@code{EN_OBJNO} - An object number which could not be accessed on the
408target node is specified.
409
410@code{EN_PAR} - A value outside the range supported by the target node
411and/or transmission packet format was specified as a parameter (a value
412outside supported range was specified for tmout)
413
414
415@subheading DESCRIPTION:
416
417@subheading NOTES:
418
419NONE
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
433ER 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
450does not exist)
451
452@code{E_OACV} - Object access violation (A semid less than -4 was
453specified 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
458semaphore was deleted while waiting)
459
460@code{E_RLWAI} - Wait state was forcibly released (rel_wai was received
461while 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
466task in dispatch disabled state)
467
468@code{EN_OBJNO} - An object number which could not be accessed on the
469target node is specified.
470
471@code{EN_PAR} - A value outside the range supported by the target node
472and/or transmission packet format was specified as a parameter (a value
473outside supported range was specified for tmout)
474
475
476@subheading DESCRIPTION:
477
478@subheading NOTES:
479
480NONE
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
494ER 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
511does not exist)
512
513@code{E_OACV} - Object access violation (A semid less than -4 was
514specified from a user task.  This is implementation dependent.)
515
516@code{E_PAR} - Parameter error (the packet address for the return
517parameters could not be used)
518
519@code{EN_OBJNO} - An object number which could not be accessed on the
520target node is specified.
521
522@code{EN_CTXID} - Specified an object on another node when the system call
523was issued from a task in dispatch disabled state or from a
524task-independent portion
525
526@code{EN_RPAR} - A value outside the range supported by the requesting
527node and/or transmission packet format was returned as a parameter (a
528value outside supported range was specified for exinf, wtsk or semcnt)
529
530@subheading DESCRIPTION:
531
532@subheading NOTES:
533
534NONE
535
Note: See TracBrowser for help on using the repository browser.