1.\" $OpenBSD: usbd_ref_wait.9,v 1.3 2016/06/30 19:54:13 mglocker Exp $ 2.\" 3.\" Copyright (c) 2016 Marcus Glocker <mglocker@openbsd.org> 4.\" 5.\" Permission to use, copy, modify, and distribute this software for any 6.\" purpose with or without fee is hereby granted, provided that the above 7.\" copyright notice and this permission notice appear in all copies. 8.\" 9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16.\" 17.Dd $Mdocdate: June 30 2016 $ 18.Dt USBD_REF_WAIT 9 19.Os 20.Sh NAME 21.Nm usbd_ref_incr , usbd_ref_decr , usbd_ref_wait 22.Nd wait for all USB device references to complete 23.Sh SYNOPSIS 24.In dev/usb/usb.h 25.In dev/usb/usbdi.h 26.Ft void 27.Fn usbd_ref_incr "struct usbd_device *dev" 28.Ft void 29.Fn usbd_ref_decr "struct usbd_device *dev" 30.Ft void 31.Fn usbd_ref_wait "struct usbd_device *dev" 32.Sh DESCRIPTION 33The 34.Fn usbd_ref_wait 35function is used on a device level to 36.Xr tsleep 9 37until the reference counter has reached zero. 38.Pp 39To increase the reference counter use 40.Fn usbd_ref_incr . 41To decrease the reference counter use 42.Fn usbd_ref_decr . 43Once the reference counter has been decreased to zero, 44.Fn usbd_ref_decr 45will call 46.Fn wakeup 47to interrupt the 48.Fn tsleep 49at the point where 50.Fn usbd_ref_wait 51was previously set. 52.Pp 53Typical use cases to wait for tasks to complete is at device closing 54or detachment. 55.Sh CONTEXT 56.Fn usbd_ref_incr , 57.Fn usbd_ref_decr , 58and 59.Fn usbd_ref_wait 60can be called during autoconf or from process context. 61.Sh SEE ALSO 62.Xr usb 4 , 63.Xr tsleep 9 , 64.Xr wakeup 9 65