FreeBSD/sys/dev/usb/usb_process.c
/*------------------------------------------------------------------------*
 *	usb_proc_drain
 *
 * This function will tear down an USB process, waiting for the
 * currently executing command to return.
 *
 * NOTE: If the structure pointed to by "up" is all zero,
 * this function does nothing.
 *------------------------------------------------------------------------*/
usb_proc_drain
This function will tear down an USB process, waiting for the
currently executing command to return.

If the structure pointed to by "up" is all zero,
this function does nothing.
usb_proc_drain This function will tear down an USB process waiting for the currently executing command to return . If the structure pointed to by " up " is all zero this function does nothing .
void
usb_proc_drain(struct usb_process *up)
{
	if (up->up_mtx == NULL)
		return;
	if (up->up_mtx != &Giant)
		mtx_assert(up->up_mtx, MA_NOTOWNED);
	mtx_lock(up->up_mtx);
	up->up_gone = 1;
	while (up->up_ptr) {
		if (up->up_msleep || up->up_csleep) {
			up->up_msleep = 0;
			up->up_csleep = 0;
			cv_signal(&up->up_cv);
		}
		if (cold) {
			USB_THREAD_SUSPEND(up->up_ptr);
			printf("WARNING: A USB process has "
			    "been left suspended\n");
			break;
		}
		cv_wait(&up->up_cv, up->up_mtx);
	}
	if (up->up_dsleep) {
		up->up_dsleep = 0;
		cv_broadcast(&up->up_drain);
		DPRINTF("WARNING: Someone is waiting "
		    "for USB process drain!\n");
	}
	mtx_unlock(up->up_mtx);
}
void usb_proc_drain ( struct usb_process * up ) { if ( up -> up_mtx == NULL ) return ; if ( up -> up_mtx != & Giant ) mtx_assert ( up -> up_mtx , MA_NOTOWNED ) ; mtx_lock ( up -> up_mtx ) ; up -> up_gone = 1 ; while ( up -> up_ptr ) { if ( up -> up_msleep || up -> up_csleep ) { up -> up_msleep = 0 ; up -> up_csleep = 0 ; cv_signal ( & up -> up_cv ) ; } if ( cold ) { USB_THREAD_SUSPEND ( up -> up_ptr ) ; printf ( " " " \n " ) ; break ; } cv_wait ( & up -> up_cv , up -> up_mtx ) ; } if ( up -> up_dsleep ) { up -> up_dsleep = 0 ; cv_broadcast ( & up -> up_drain ) ; DPRINTF ( " " " \n " ) ; } mtx_unlock ( up -> up_mtx ) ; }
usb_proc_drain
 This function will tear down an USB process, waiting for the
 currently executing command to return.
usb_proc_drain This function will tear down an USB process waiting for the currently executing command to return .
/* check if not initialised */ /* handle special case with Giant */ /* Set the gone flag */ /* Check if we need to wakeup the USB process */ /* Check if we are still cold booted */ /* Check if someone is waiting - should not happen */