Device Ready
7-44
The device’s ready semaphore handle is set to the semaphore handle
passed in by SIO_select. To better understand Dxx_ready, consider the
following details of SIO_select.
SIO_select can be summarized in pseudocode as shown in Example 7-33.
Example 7-33. SIO_Select Pseudocode
/*
* ======== SIO_select ========
*/
Uns SIO_select(streamtab, n, timeout)
SIO_Handle streamtab[]; /* array of streams */
Int n; /* number of streams */
Uns timeout; /* passed to SEM_pend() */
{
Int i;
Uns mask = 1; /* used to build ready mask */
Uns ready = 0; /* bit mask of ready streams */
SEM_Handle sem; /* local semaphore */
SIO_Handle *stream; /* pointer into streamtab[] */
/*
* For efficiency, the "real" SIO_select() doesn't call
* SEM_create() but instead initializes a SEM_Obj on the
* current stack.
*/
sem = SEM_create(0, NULL);
stream = streamtab;
for (i = n; i > 0; i--, stream++) {
/*
* call each device ready function with 'sem'
*/
if ( `Dxx_ready(device, sem)` )
ready = 1;
}
}
if (!ready) {
/* wait until at least one device is ready */
SEM_pend(sem, timeout);
}
ready = 0;
stream = streamtab;
for (i = n; i > 0; i--, stream++) {
/*
* Call each device ready function with NULL.
* When this loop is done, ready will have a bit set
* for each ready device.
*/
if ( `Dxx_ready(device, NULL)` )
ready |= mask;
}
mask = mask << 1;
}
return (ready);
}