Writing Device Drivers


There is always the possibility that either the driver accidentally waits for a condition that will never occur (as described in "cv_timedwait(9F)") or that the condition will not happen for a long time. In either case, the user may want to abort the thread by sending it a signal. Whether the signal causes the driver to wake up depends upon the driver.

cv_wait_sig(9F) allows a signal to unblock the thread. This allows the user to break out of potentially long waits by sending a signal to the thread with kill(1) or by typing the interrupt character. cv_wait_sig(9F) returns zero if it is returning because of a signal, or nonzero if the condition occurred.

Example 4-4 shows how to use cv_wait_sig(9F) to allow a signal to unblock the thread.

Example 4-4 Using cv_wait_sig(9F)

	while (xsp->busy) {
			if (cv_wait_sig(&xsp->cv, &xsp->mu) == 0) {
				/* Signalled while waiting for the condition. */
				tidy up and exit
				return (EINTR);
	xsp->busy = 1;