|
|
void wakeup(caddr_t address); unsigned int wakeupn(caddr_t address, int maxwake);
The wakeup( ) function causes all processes that are sleeping at the specified address to be taken off the sleep queue. If the process is running, the unblocked processes are placed on the run queue. If the process is stopped, the unblocked process is taken off the sleep queue (but not placed it on the run queue). When a process is awakened, the call to sleep(D3oddi) returns a value of zero. It is still necessary to see whether the event being slept on has occurred, because there is no guarantee that the resource being waited for is actually free.
The wakeupn( ) function behaves the same way as wakeup( ), except that it only wakes up a maximum of maxwake processes.
DDI versions 7 and earlier use synchronization variables rather than sleep( ) and wakeup( ). In this scheme, SV_BROADCAST(D3) is roughly equivalent to wakeup( ) and SV_SIGNAL(D3) unblocks a single LWP, which is equivalent to the way wakeupn( ) is typically used. See ``Synchronization variables'' in HDK Technical Reference for more information about DDI sychronization variables and a comparison of their semantics with sleep( ) and wakeup( ).
char my_address; /* declare variable which is used for address */xxread(int dev); { #define MYPRI PZERO+15 /* PZERO is defined in <sys/param.h> */
/* allocate temporary storage */ /* set flag to indicate I/O transfer is in progress */ /* start I/O transfer */ /* * flag only indicates transfer is done if wakeup() has * been called by my xxintr(). */ while (/* flag indicates transfer is not done */) { /* * OR MYPRI with PCATCH to clean things up instead * of returning directly to user space with an error. */ if (sleep(&my_address, MYPRI | PCATCH) == 1) { /* stop I/O transfer */ /* clear I/O transfer flag */ /* free temporary memory */ u.u_error = EINTR; return(-1); } } /* only get past here when transfer is done */ /* copy data from temporary storage to user address */ . /* free temporary memory */ return( /* number of bytes transferred */ ); }
xxintr(int interrupt); { /* ``check that transfer is'' complete */ /* ``set flag to indicate transfer is complete'' */ /* wakeup sleeping process */ wakeup(&my_address); }