summaryrefslogtreecommitdiff
path: root/sys/dev/usb
diff options
context:
space:
mode:
authorJacob Meuser <jakemsr@cvs.openbsd.org>2010-12-30 05:10:36 +0000
committerJacob Meuser <jakemsr@cvs.openbsd.org>2010-12-30 05:10:36 +0000
commitf6a5099b44f1218b8b9e6a7c28b5646e4f277942 (patch)
tree4fc2fbb1913473a71d51900df162170e95c3bdd6 /sys/dev/usb
parente707938ee54d291657561650400fae34c1403b14 (diff)
* add a process reference counting variable to struct usbd_device
* add functions to increment and decrement the reference count, and a function to wait until the reference count is zero ok martynas@
Diffstat (limited to 'sys/dev/usb')
-rw-r--r--sys/dev/usb/usbdi.c22
-rw-r--r--sys/dev/usb/usbdi.h6
-rw-r--r--sys/dev/usb/usbdivar.h5
3 files changed, 29 insertions, 4 deletions
diff --git a/sys/dev/usb/usbdi.c b/sys/dev/usb/usbdi.c
index 01e88d93a03..78e80e7c882 100644
--- a/sys/dev/usb/usbdi.c
+++ b/sys/dev/usb/usbdi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: usbdi.c,v 1.41 2010/12/06 04:25:27 jakemsr Exp $ */
+/* $OpenBSD: usbdi.c,v 1.42 2010/12/30 05:10:35 jakemsr Exp $ */
/* $NetBSD: usbdi.c,v 1.103 2002/09/27 15:37:38 provos Exp $ */
/* $FreeBSD: src/sys/dev/usb/usbdi.c,v 1.28 1999/11/17 22:33:49 n_hibma Exp $ */
@@ -97,6 +97,26 @@ usbd_deactivate(usbd_device_handle dev)
dev->dying = 1;
}
+void
+usbd_ref_incr(usbd_device_handle dev)
+{
+ dev->ref_cnt++;
+}
+
+void
+usbd_ref_decr(usbd_device_handle dev)
+{
+ if (--dev->ref_cnt == 0 && dev->dying)
+ wakeup(&dev->ref_cnt);
+}
+
+void
+usbd_ref_wait(usbd_device_handle dev)
+{
+ while (dev->ref_cnt > 0)
+ tsleep(&dev->ref_cnt, PWAIT, "usbref", hz * 60);
+}
+
static __inline int
usbd_xfer_isread(usbd_xfer_handle xfer)
{
diff --git a/sys/dev/usb/usbdi.h b/sys/dev/usb/usbdi.h
index 5996ad61c65..c7bc9a4c09e 100644
--- a/sys/dev/usb/usbdi.h
+++ b/sys/dev/usb/usbdi.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: usbdi.h,v 1.36 2010/12/06 04:25:27 jakemsr Exp $ */
+/* $OpenBSD: usbdi.h,v 1.37 2010/12/30 05:10:35 jakemsr Exp $ */
/* $NetBSD: usbdi.h,v 1.62 2002/07/11 21:14:35 augustss Exp $ */
/* $FreeBSD: src/sys/dev/usb/usbdi.h,v 1.18 1999/11/17 22:33:49 n_hibma Exp $ */
@@ -168,6 +168,10 @@ int usbd_ratecheck(struct timeval *last);
int usbd_is_dying(usbd_device_handle);
void usbd_deactivate(usbd_device_handle);
+void usbd_ref_incr(usbd_device_handle);
+void usbd_ref_decr(usbd_device_handle);
+void usbd_ref_wait(usbd_device_handle);
+
/* An iterator for descriptors. */
typedef struct {
const uByte *cur;
diff --git a/sys/dev/usb/usbdivar.h b/sys/dev/usb/usbdivar.h
index 2ebdb9b9d9b..f53369945ad 100644
--- a/sys/dev/usb/usbdivar.h
+++ b/sys/dev/usb/usbdivar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: usbdivar.h,v 1.40 2010/12/06 04:25:27 jakemsr Exp $ */
+/* $OpenBSD: usbdivar.h,v 1.41 2010/12/30 05:10:35 jakemsr Exp $ */
/* $NetBSD: usbdivar.h,v 1.70 2002/07/11 21:14:36 augustss Exp $ */
/* $FreeBSD: src/sys/dev/usb/usbdivar.h,v 1.11 1999/11/17 22:33:51 n_hibma Exp $ */
@@ -125,7 +125,8 @@ struct usbd_bus {
struct usbd_device {
struct usbd_bus *bus; /* our controller */
struct usbd_pipe *default_pipe; /* pipe 0 */
- u_int8_t dying; /* removed */
+ u_int8_t dying; /* hardware removed */
+ u_int8_t ref_cnt; /* # of procs using device */
u_int8_t address; /* device address */
u_int8_t config; /* current configuration # */
u_int8_t depth; /* distance from root hub */