source: rtems/doc/itron3.0/semaphore.t @ ce66895e

4.104.114.84.95
Last change on this file since ce66895e was ce66895e, checked in by Joel Sherrill <joel.sherrill@…>, on 05/26/99 at 17:59:16

Changed word "directive" to "system call."

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