FreeBSD/sys/dev/usb/usb_dev.c
/*------------------------------------------------------------------------*
 *	usb_unref_device
 *
 * This function will release the reference count by one unit for the
 * given USB device.
 *------------------------------------------------------------------------*/
usb_unref_device
This function will release the reference count by one unit for the
given USB device.
usb_unref_device This function will release the reference count by one unit for the given USB device .
static void
usb_unref_device(struct usb_cdev_privdata *cpd,
    struct usb_cdev_refdata *crd)
{
	DPRINTFN(2, "cpd=%p is_uref=%d\n", cpd, crd->is_uref);
	if (crd->do_unlock)
		usbd_enum_unlock(cpd->udev);
	mtx_lock(&usb_ref_lock);
	if (crd->is_read) {
		if (--(crd->rxfifo->refcount) == 0) {
			cv_signal(&crd->rxfifo->cv_drain);
		}
		crd->is_read = 0;
	}
	if (crd->is_write) {
		if (--(crd->txfifo->refcount) == 0) {
			cv_signal(&crd->txfifo->cv_drain);
		}
		crd->is_write = 0;
	}
	if (crd->is_uref) {
		crd->is_uref = 0;
		if (--(cpd->udev->refcount) == 0)
			cv_broadcast(&cpd->udev->ref_cv);
	}
	mtx_unlock(&usb_ref_lock);
}
static void usb_unref_device ( struct usb_cdev_privdata * cpd , struct usb_cdev_refdata * crd ) { DPRINTFN ( 2 , " \n " , cpd , crd -> is_uref ) ; if ( crd -> do_unlock ) usbd_enum_unlock ( cpd -> udev ) ; mtx_lock ( & usb_ref_lock ) ; if ( crd -> is_read ) { if ( -- ( crd -> rxfifo -> refcount ) == 0 ) { cv_signal ( & crd -> rxfifo -> cv_drain ) ; } crd -> is_read = 0 ; } if ( crd -> is_write ) { if ( -- ( crd -> txfifo -> refcount ) == 0 ) { cv_signal ( & crd -> txfifo -> cv_drain ) ; } crd -> is_write = 0 ; } if ( crd -> is_uref ) { crd -> is_uref = 0 ; if ( -- ( cpd -> udev -> refcount ) == 0 ) cv_broadcast ( & cpd -> udev -> ref_cv ) ; } mtx_unlock ( & usb_ref_lock ) ; }
usb_unref_device
 This function will release the reference count by one unit for the
 given USB device.
usb_unref_device This function will release the reference count by one unit for the given USB device .