source: rtems/doc/itron3.0/semaphore.t @ 6ff1ac4e

4.104.114.84.95
Last change on this file since 6ff1ac4e was 6ff1ac4e, checked in by Joel Sherrill <joel.sherrill@…>, on 06/04/99 at 13:37:23

Added much of the text required to turn this into a real chapter.

  • Property mode set to 100644
File size: 19.0 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
52/*
53 *  Create Semaphore (cre_sem) Structure
54 */
55
56typedef struct t_csem @{
57  VP    exinf;    /* extended information */
58  ATR   sematr;   /* semaphore attributes */
59  /* Following is the extended function for [level X]. */
60  INT   isemcnt;   /* initial semaphore count */
61  INT   maxsem;    /* maximum semaphore count */
62  /* additional information may be included depending on the implementation */
63@} T_CSEM;
64
65/*
66 *  sematr - Semaphore Attribute Values
67 */
68
69#define TA_TFIFO   0x00   /* waiting tasks are handled by FIFO */
70#define TA_TPRI    0x01   /* waiting tasks are handled by priority */
71
72@end group
73@end example
74
75where the meaning of each field is:
76
77@table @b
78@item exinf
79is for any extended information that the implementation may define.
80This implementation does not use this field.
81
82@item sematr
83is the attributes for this semaphore.  The only attributed
84which can be specified is whether tasks wait in FIFO (@code{TA_TFIFO})
85or priority (@code{TA_TPRI}) order.
86
87@item isemcnt
88is the initial count of the semaphore.
89
90@item maxsem
91is the maximum count the semaphore may have.  It places an upper
92limit on the value taken by the semaphore.
93
94@end table
95
96@subsection Building a Semaphore's Attribute Set
97
98In general, an attribute set is built by a bitwise OR
99of the desired attribute components.  The following table lists
100the set of valid semaphore attributes:
101
102@itemize @bullet
103@item @code{TA_TFIFO} - tasks wait by FIFO
104
105@item @code{TA_TPRI} - tasks wait by priority
106
107@end itemize
108
109Attribute values are specifically designed to be
110mutually exclusive, therefore bitwise OR and addition operations
111are equivalent as long as each attribute appears exactly once in
112the component list.
113
114@subsection T_RSEM Structure
115
116The T_RSEM structure is filled in by the @code{ref_sem} service with
117status and state information on a semaphore.  The structure
118is defined as follows:
119
120@example
121@group
122/*
123 *  Reference Semaphore (ref_sem) Structure
124 */
125
126typedef struct t_rsem @{
127  VP      exinf;    /* extended information */
128  BOOL_ID wtsk;     /* indicates whether or not there is a waiting task */
129  INT     semcnt;   /* current semaphore count */
130  /* additional information may be included depending on the implementation */
131@} T_RSEM;
132@end group
133@end example
134
135@table @b
136
137@item exinf
138is for any extended information that the implementation may define.
139This implementation does not use this field.
140
141@item wtsk
142is TRUE when there is one or more task waiting on the semaphore.
143It is FALSE if no tasks are currently waiting.  The meaning of this
144field is allowed to vary between ITRON implementations.  It may have
145the ID of a waiting task, the number of tasks waiting, or a boolean
146indication that one or more tasks are waiting.
147
148@item semcnt
149is the current semaphore count.
150
151@end table
152
153The information in this table is very volatile and should be used
154with caution in an application.
155
156@section Operations
157
158@subsection Using as a Binary Semaphore
159
160Creating a semaphore with a limit on the count of 1 effectively
161restricts the semaphore to being a binary semaphore.  When the
162binary semaphore is available, the count is 1.  When the binary
163semaphore is unavailable, the count is 0.
164
165Since this does not result in a true binary semaphore, advanced
166binary features like the Priority Inheritance and Priority
167Ceiling Protocols are not available.
168
169@section System Calls
170
171This section details the semaphore manager's services.
172A subsection is dedicated to each of this manager's services
173and describes the calling sequence, related constants, usage,
174and status codes.
175
176
177@c
178@c  cre_sem
179@c
180
181@page
182@subsection cre_sem - Create Semaphore
183
184@subheading CALLING SEQUENCE:
185
186@ifset is-C
187@example
188ER cre_sem(
189  ID semid,
190  T_CSEM *pk_csem
191);
192@end example
193@end ifset
194
195@ifset is-Ada
196@end ifset
197
198@subheading STATUS CODES:
199
200@code{E_OK} - Normal Completion
201
202@code{E_ID} - Invalid ID number (semid was invalid or could not be used)
203
204@code{E_NOMEM} - Insufficient memory (Memory for control block cannot be
205allocated)
206
207@code{E_OACV} - Object access violation (A semid less than -4 was
208specified from a user task.  This is implementation dependent.)
209
210@code{E_RSATR} - Reserved attribute (sematr was invalid or could not be
211used)
212
213@code{E_OBJ} - Invalid object state (a semaphore of the same ID already
214exists)
215
216@code{E_PAR} - Parameter error (pk_csem is invalid and/or isemcnt or
217maxsem is negative or invalid)
218
219@code{EN_OBJNO} - An object number which could not be accessed on the
220target node is specified.
221
222@code{EN_CTXID} - Specified an object on another node when the system call
223was issued from a task in dispatch disabled state or from a task-
224independent portion
225
226@code{EN_PAR} - A value outside the range supported by the target node
227and/or transmission packet format was specified as a parameter (a value
228outside supported range was specified for exinf, sematr, isemcnt and/or
229maxsem)
230
231@subheading DESCRIPTION:
232
233This routine creates a semaphore that resides on the local node.  The
234semaphore is initialized based on the attributes specified in the
235@code{pk_csem} structure.  The initial and maximum counts of the
236semaphore are set based on the @code{isemcnt} and @code{maxsem} fields
237in this structure.
238
239Specifying @code{TA_TPRI} in the @code{sematr} field of the
240semaphore attributes structure causes tasks
241waiting for a semaphore to be serviced according to task
242priority.  When @code{TA_TFIFO} is selected, tasks are serviced in First
243In-First Out order.
244
245@subheading NOTES:
246
247Multiprocessing is not supported.  Thus none of the "EN_" status codes
248will be returned.
249
250All memory is preallocated for RTEMS ITRON objects.  Thus, no dynamic
251memory allocation is performed by @code{cre_sem} and the @code{E_NOMEM}
252error can not be returned.
253
254The ITRON specification calls for @code{E_OACV} to be returned for
255some invalid semaphore IDs.  This implementation returns @code{E_ID}
256for all invalid IDs as there are no system reserved ITRON objects.
257
258This directive will not cause the running task to be
259preempted.
260
261The following semaphore attribute constants are
262defined by RTEMS:
263
264@itemize @bullet
265@item @code{TA_TFIFO} - tasks wait by FIFO
266
267@item @code{TA_TPRI} - tasks wait by priority
268
269@end itemize
270
271@c
272@c  del_sem
273@c
274
275@page
276@subsection del_sem - Delete Semaphore
277
278@subheading CALLING SEQUENCE:
279
280@ifset is-C
281@example
282ER del_sem(
283  ID semid
284);
285@end example
286@end ifset
287
288@ifset is-Ada
289@end ifset
290
291@subheading STATUS CODES:
292
293@code{E_OK} - Normal Completion
294
295@code{E_ID} - Invalid ID number (semid was invalid or could not be used)
296
297@code{E_NOEXS} - Object does not exist (the semaphore specified by semid
298does not exist)
299
300@code{E_OACV} - Object access violation (A semid less than -4 was
301specified from a user task.  This is implementation dependent.)
302
303@code{EN_OBJNO} - An object number which could not be accessed on the
304target node is specified.
305
306@code{EN_CTXID} - Specified an object on another node when the system call
307was issued from a task in dispatch disabled state or from a
308task-independent portion
309
310@subheading DESCRIPTION:
311
312This routine deletes the semaphore specified by @code{semid}.
313All tasks blocked waiting to acquire the semaphore will be
314readied and returned a status code which indicates that the
315semaphore was deleted.  The control block for this semaphore
316is reclaimed by RTEMS.
317
318
319@subheading NOTES:
320
321Multiprocessing is not supported.  Thus none of the "EN_" status codes
322will be returned.
323
324This implementation does not distinguish between an invalid ID (@code{E_ID})
325and a valid id for a non-existent object (@code{E_NOEXS}).  In addition,
326there are no system reserved ITRON objects so the @code{E_OACV} error
327is not returned.  All IDs which do not correspond to an active user
328created semaphore return @code{E_ID}.
329
330The calling task will be preempted if it is enabled
331by the task's execution mode and a higher priority local task is
332waiting on the deleted semaphore.  The calling task will NOT be
333preempted if all of the tasks that are waiting on the semaphore
334are remote tasks.
335
336The calling task does not have to be the task that
337created the semaphore.  Any local task that knows the semaphore
338id can delete the semaphore.
339
340
341@c
342@c  sig_sem
343@c
344
345@page
346@subsection sig_sem - Signal Semaphore
347
348@subheading CALLING SEQUENCE:
349
350@ifset is-C
351@example
352ER sig_sem(
353  ID semid
354);
355@end example
356@end ifset
357
358@ifset is-Ada
359@end ifset
360
361@subheading STATUS CODES:
362
363@code{E_OK} - Normal Completion
364
365@code{E_ID} - Invalid ID number (semid was invalid or could not be used)
366
367@code{E_NOEXS} - Object does not exist (the semaphore specified by semid
368does not exist)
369
370@code{E_OACV} - Object access violation (A semid less than -4 was
371specified from a user task.  This is implementation dependent.)
372
373@code{E_QOVR} - Queuing or nesting overflow (the queuing count given by
374semcnt went over the maximum allowed)
375
376@code{EN_OBJNO} - An object number which could not be accessed on the
377target node is specified.
378
379@code{EN_CTXID} - Specified an object on another node when the system call
380was issued from a task in dispatch disabled state or from a
381task-independent portion
382
383@subheading DESCRIPTION:
384
385@subheading NOTES:
386
387Multiprocessing is not supported.  Thus none of the "EN_" status codes
388will be returned.
389
390This implementation does not distinguish between an invalid ID (@code{E_ID})
391and a valid id for a non-existent object (@code{E_NOEXS}).  In addition,
392there are no system reserved ITRON objects so the @code{E_OACV} error
393is not returned.  All IDs which do not correspond to an active user
394created semaphore return @code{E_ID}.
395
396@c
397@c  wai_sem
398@c
399
400@page
401@subsection wai_sem - Wait on Semaphore
402
403@subheading CALLING SEQUENCE:
404
405@ifset is-C
406@example
407ER wai_sem(
408  ID semid
409);
410@end example
411@end ifset
412
413@ifset is-Ada
414@end ifset
415
416@subheading STATUS CODES:
417
418@code{E_OK} - Normal Completion
419
420@code{E_ID} - Invalid ID number (semid was invalid or could not be used)
421
422@code{E_NOEXS} - Object does not exist (the semaphore specified by semid
423does not exist)
424
425@code{E_OACV} - Object access violation (A semid less than -4 was
426specified from a user task.  This is implementation dependent.)
427
428@code{E_DLT} - The object being waited for was deleted (the specified
429semaphore was deleted while waiting)
430
431@code{E_RLWAI} - Wait state was forcibly released (rel_wai was received
432while waiting)
433
434@code{E_CTX} - Context error (issued from task-independent portions or a
435task in dispatch disabled state)
436
437@code{EN_OBJNO} - An object number which could not be accessed on the
438target node is specified.
439
440@code{EN_PAR} - A value outside the range supported by the target node
441and/or transmission packet format was specified as a parameter (a value
442outside supported range was specified for tmout)
443
444@subheading DESCRIPTION:
445
446This routine attempts to acquire the semaphore specified by @code{semid}.
447If the semaphore is available (i.e. positive semaphore count), then the
448semaphore count is decremented and the calling task returns immediately. 
449Otherwise the calling tasking is blocked until the semaphore is released
450by a subsequent invocation of @code{sig_sem}.
451
452@subheading NOTES:
453
454Multiprocessing is not supported.  Thus none of the "EN_" status codes
455will be returned.
456
457This implementation does not distinguish between an invalid ID (@code{E_ID})
458and a valid id for a non-existent object (@code{E_NOEXS}).  In addition,
459there are no system reserved ITRON objects so the @code{E_OACV} error
460is not returned.  All IDs which do not correspond to an active user
461created semaphore return @code{E_ID}.
462
463If the semaphore is not available, then the calling task will be blocked.
464
465@c
466@c  preq_sem
467@c
468
469@page
470@subsection preq_sem - Poll and Request Semaphore
471
472@subheading CALLING SEQUENCE:
473
474@ifset is-C
475@example
476ER preq_sem(
477  ID semid
478);
479@end example
480@end ifset
481
482@ifset is-Ada
483@end ifset
484
485@subheading STATUS CODES:
486
487@code{E_OK} - Normal Completion
488
489@code{E_ID} - Invalid ID number (semid was invalid or could not be used)
490
491@code{E_NOEXS} - Object does not exist (the semaphore specified by semid
492does not exist)
493
494@code{E_OACV} - Object access violation (A semid less than -4 was
495specified from a user task.  This is implementation dependent.)
496
497@code{E_TMOUT} - Polling failure or timeout exceeded
498
499@code{E_CTX} - Context error (issued from task-independent portions or a
500task in dispatch disabled state)
501
502@code{EN_OBJNO} - An object number which could not be accessed on the
503target node is specified.
504
505@code{EN_PAR} - A value outside the range supported by the target node
506and/or transmission packet format was specified as a parameter (a value
507outside supported range was specified for tmout)
508
509@subheading DESCRIPTION:
510
511This routine attempts to acquire the semaphore specified by @code{semid}.
512If the semaphore is available (i.e. positive semaphore count), then the
513semaphore count is decremented and the calling task returns immediately.
514Otherwise, the @code{E_TMOUT} error is returned to the calling task to
515indicate the semaphore is unavailable.
516
517@subheading NOTES:
518
519Multiprocessing is not supported.  Thus none of the "EN_" status codes
520will be returned.
521
522This implementation does not distinguish between an invalid ID (@code{E_ID})
523and a valid id for a non-existent object (@code{E_NOEXS}).  In addition,
524there are no system reserved ITRON objects so the @code{E_OACV} error
525is not returned.  All IDs which do not correspond to an active user
526created semaphore return @code{E_ID}.
527
528This routine will not cause the running task to be preempted.
529
530@c
531@c  twai_sem
532@c
533
534@page
535@subsection twai_sem - Wait on Semaphore with Timeout
536
537@subheading CALLING SEQUENCE:
538
539@ifset is-C
540@example
541ER twai_sem(
542  ID semid,
543  TMO tmout
544);
545@end example
546@end ifset
547
548@ifset is-Ada
549@end ifset
550
551@subheading STATUS CODES:
552
553@code{E_OK} - Normal Completion
554
555@code{E_ID} - Invalid ID number (semid was invalid or could not be used)
556
557@code{E_NOEXS} - Object does not exist (the semaphore specified by semid
558does not exist)
559
560@code{E_OACV} - Object access violation (A semid less than -4 was
561specified from a user task.  This is implementation dependent.)
562
563@code{E_PAR} - Parameter error (tmout is -2 or less)
564
565@code{E_DLT} - The object being waited for was deleted (the specified
566semaphore was deleted while waiting)
567
568@code{E_RLWAI} - Wait state was forcibly released (rel_wai was received
569while waiting)
570
571@code{E_TMOUT} - Polling failure or timeout exceeded
572
573@code{E_CTX} - Context error (issued from task-independent portions or a
574task in dispatch disabled state)
575
576@code{EN_OBJNO} - An object number which could not be accessed on the
577target node is specified.
578
579@code{EN_PAR} - A value outside the range supported by the target node
580and/or transmission packet format was specified as a parameter (a value
581outside supported range was specified for tmout)
582
583@subheading DESCRIPTION:
584
585This routine attempts to acquire the semaphore specified by @code{semid}.
586If the semaphore is available (i.e. positive semaphore count), then the
587semaphore count is decremented and the calling task returns immediately.
588Otherwise the calling tasking is blocked until the semaphore is released
589by a subsequent invocation of @code{sig_sem} or the timeout period specified
590by @code{tmout} milliseconds is exceeded.  If the timeout period is exceeded,
591then the @code{E_TMOUT} error is returned.
592
593By specifiying @code{tmout} as @code{TMO_FEVR}, this routine has the same
594behavior as @code{wai_sem}.  Similarly, by specifiying @code{tmout} as
595@code{TMO_POL}, this routine has the same behavior as @code{preq_sem}.
596
597@subheading NOTES:
598
599Multiprocessing is not supported.  Thus none of the "EN_" status codes
600will be returned.
601
602This implementation does not distinguish between an invalid ID (@code{E_ID})
603and a valid id for a non-existent object (@code{E_NOEXS}).  In addition,
604there are no system reserved ITRON objects so the @code{E_OACV} error
605is not returned.  All IDs which do not correspond to an active user
606created semaphore return @code{E_ID}.
607
608This routine may cause the calling task to block.
609
610A clock tick is required to support the timeout functionality of
611this routine.
612
613@c
614@c  ref_sem
615@c
616
617@page
618@subsection ref_sem - Reference Semaphore Status
619
620@subheading CALLING SEQUENCE:
621
622@ifset is-C
623@example
624ER ref_sem(
625  T_RSEM *pk_rsem,
626  ID semid
627);
628@end example
629@end ifset
630
631@ifset is-Ada
632@end ifset
633
634@subheading STATUS CODES:
635
636@code{E_OK} - Normal Completion
637
638@code{E_ID} - Invalid ID number (semid was invalid or could not be used)
639
640@code{E_NOEXS} - Object does not exist (the semaphore specified by semid
641does not exist)
642
643@code{E_OACV} - Object access violation (A semid less than -4 was
644specified from a user task.  This is implementation dependent.)
645
646@code{E_PAR} - Parameter error (the packet address for the return
647parameters could not be used)
648
649@code{EN_OBJNO} - An object number which could not be accessed on the
650target node is specified.
651
652@code{EN_CTXID} - Specified an object on another node when the system call
653was issued from a task in dispatch disabled state or from a
654task-independent portion
655
656@code{EN_RPAR} - A value outside the range supported by the requesting
657node and/or transmission packet format was returned as a parameter (a
658value outside supported range was specified for exinf, wtsk or semcnt)
659
660@subheading DESCRIPTION:
661
662This routine returns status information on the semaphore specified
663by @code{semid}.  The @code{pk_rsem} structure is filled in by
664this service call.
665
666@subheading NOTES:
667
668Multiprocessing is not supported.  Thus none of the "EN_" status codes
669will be returned.
670
671This implementation does not distinguish between an invalid ID (@code{E_ID})
672and a valid id for a non-existent object (@code{E_NOEXS}).  In addition,
673there are no system reserved ITRON objects so the @code{E_OACV} error
674is not returned.  All IDs which do not correspond to an active user
675created semaphore return @code{E_ID}.
676
677This routine will not cause the running task to be preempted.
678
Note: See TracBrowser for help on using the repository browser.