Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/nick-nhusb]: src/sys/dev/usb Retire usb_detach_{wait, broadcast} and simp...



details:   https://anonhg.NetBSD.org/src/rev/13b788bef78d
branches:  nick-nhusb
changeset: 334548:13b788bef78d
user:      skrll <skrll%NetBSD.org@localhost>
date:      Thu Oct 27 07:46:19 2016 +0000

description:
Retire usb_detach_{wait,broadcast} and simply use condvar(9) instead

diffstat:

 sys/dev/usb/ucom.c       |  19 +++++++++++--------
 sys/dev/usb/ugen.c       |  15 +++++++++------
 sys/dev/usb/uhid.c       |  16 +++++++++-------
 sys/dev/usb/umass.c      |   9 ++++++---
 sys/dev/usb/umidi.c      |  13 ++++++++-----
 sys/dev/usb/usbdi_util.c |  25 ++-----------------------
 sys/dev/usb/usbdi_util.h |   9 +--------
 7 files changed, 46 insertions(+), 60 deletions(-)

diffs (truncated from 337 to 300 lines):

diff -r 5ecbdc3ff58c -r 13b788bef78d sys/dev/usb/ucom.c
--- a/sys/dev/usb/ucom.c        Wed Oct 26 07:31:24 2016 +0000
+++ b/sys/dev/usb/ucom.c        Thu Oct 27 07:46:19 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ucom.c,v 1.108.2.23 2016/10/25 07:32:25 skrll Exp $    */
+/*     $NetBSD: ucom.c,v 1.108.2.24 2016/10/27 07:46:19 skrll Exp $    */
 
 /*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.108.2.23 2016/10/25 07:32:25 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.108.2.24 2016/10/27 07:46:19 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -440,7 +440,10 @@
                        mutex_spin_exit(&tty_lock);
                }
                /* Wait for processes to go away. */
-               usb_detach_wait(sc->sc_dev, &sc->sc_detachcv, &sc->sc_lock);
+               if (cv_timedwait(&sc->sc_detachcv, &sc->sc_lock, hz * 60)) {
+                       printf("%s: %s didn't detach\n", __func__,
+                           device_xname(sc->sc_dev));
+               }
        }
 
        softint_disestablish(sc->sc_si);
@@ -736,7 +739,7 @@
                sc->sc_methods->ucom_close(sc->sc_parent, sc->sc_portno);
 
        if (--sc->sc_refcnt < 0)
-               usb_detach_broadcast(sc->sc_dev, &sc->sc_detachcv);
+               cv_broadcast(&sc->sc_detachcv);
 
 out:
        sc->sc_closing = 0;
@@ -773,7 +776,7 @@
 
        mutex_enter(&sc->sc_lock);
        if (--sc->sc_refcnt < 0)
-               usb_detach_broadcast(sc->sc_dev, &sc->sc_detachcv);
+               cv_broadcast(&sc->sc_detachcv);
        mutex_exit(&sc->sc_lock);
 
        return error;
@@ -803,7 +806,7 @@
 
        mutex_enter(&sc->sc_lock);
        if (--sc->sc_refcnt < 0)
-               usb_detach_broadcast(sc->sc_dev, &sc->sc_detachcv);
+               cv_broadcast(&sc->sc_detachcv);
        mutex_exit(&sc->sc_lock);
 
        return error;
@@ -833,7 +836,7 @@
 
        mutex_enter(&sc->sc_lock);
        if (--sc->sc_refcnt < 0)
-               usb_detach_broadcast(sc->sc_dev, &sc->sc_detachcv);
+               cv_broadcast(&sc->sc_detachcv);
        mutex_exit(&sc->sc_lock);
 
        return revents;
@@ -869,7 +872,7 @@
 
        mutex_enter(&sc->sc_lock);
        if (--sc->sc_refcnt < 0)
-               usb_detach_broadcast(sc->sc_dev, &sc->sc_detachcv);
+               cv_broadcast(&sc->sc_detachcv);
        mutex_exit(&sc->sc_lock);
 
        return error;
diff -r 5ecbdc3ff58c -r 13b788bef78d sys/dev/usb/ugen.c
--- a/sys/dev/usb/ugen.c        Wed Oct 26 07:31:24 2016 +0000
+++ b/sys/dev/usb/ugen.c        Thu Oct 27 07:46:19 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ugen.c,v 1.126.2.15 2016/07/09 20:25:16 skrll Exp $    */
+/*     $NetBSD: ugen.c,v 1.126.2.16 2016/10/27 07:46:19 skrll Exp $    */
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.126.2.15 2016/07/09 20:25:16 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.126.2.16 2016/10/27 07:46:19 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -812,7 +812,7 @@
 
        mutex_enter(&sc->sc_lock);
        if (--sc->sc_refcnt < 0)
-               usb_detach_broadcast(sc->sc_dev, &sc->sc_detach_cv);
+               cv_broadcast(&sc->sc_detach_cv);
        mutex_exit(&sc->sc_lock);
 
        return error;
@@ -1006,7 +1006,7 @@
 
        mutex_enter(&sc->sc_lock);
        if (--sc->sc_refcnt < 0)
-               usb_detach_broadcast(sc->sc_dev, &sc->sc_detach_cv);
+               cv_broadcast(&sc->sc_detach_cv);
        mutex_exit(&sc->sc_lock);
 
        return error;
@@ -1053,7 +1053,10 @@
                for (i = 0; i < USB_MAX_ENDPOINTS; i++)
                        cv_signal(&sc->sc_endpoints[i][IN].cv);
                /* Wait for processes to go away. */
-               usb_detach_wait(sc->sc_dev, &sc->sc_detach_cv, &sc->sc_lock);
+               if (cv_timedwait(&sc->sc_detach_cv, &sc->sc_lock, hz * 60)) {
+                       printf("%s: %s didn't detach\n", __func__, 
+                           device_xname(sc->sc_dev));
+               }
        }
        mutex_exit(&sc->sc_lock);
 
@@ -1836,7 +1839,7 @@
        sc->sc_refcnt++;
        error = ugen_do_ioctl(sc, endpt, cmd, addr, flag, l);
        if (--sc->sc_refcnt < 0)
-               usb_detach_broadcast(sc->sc_dev, &sc->sc_detach_cv);
+               cv_broadcast(&sc->sc_detach_cv);
        return error;
 }
 
diff -r 5ecbdc3ff58c -r 13b788bef78d sys/dev/usb/uhid.c
--- a/sys/dev/usb/uhid.c        Wed Oct 26 07:31:24 2016 +0000
+++ b/sys/dev/usb/uhid.c        Thu Oct 27 07:46:19 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhid.c,v 1.92.4.10 2016/07/09 20:25:16 skrll Exp $     */
+/*     $NetBSD: uhid.c,v 1.92.4.11 2016/10/27 07:46:19 skrll Exp $     */
 
 /*
  * Copyright (c) 1998, 2004, 2008, 2012 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.92.4.10 2016/07/09 20:25:16 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.92.4.11 2016/10/27 07:46:19 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -229,8 +229,10 @@
                        /* Wake everyone */
                        cv_broadcast(&sc->sc_cv);
                        /* Wait for processes to go away. */
-                       usb_detach_wait(sc->sc_hdev.sc_dev,
-                           &sc->sc_detach_cv, &sc->sc_lock);
+                       if (cv_timedwait(&sc->sc_detach_cv, &sc->sc_lock, hz * 60)) {
+                               printf("%s: %s didn't detach\n", __func__,
+                                   device_xname(sc->sc_hdev.sc_dev));
+                       }
                }
        }
        mutex_exit(&sc->sc_lock);
@@ -457,7 +459,7 @@
 
        mutex_enter(&sc->sc_lock);
        if (--sc->sc_refcnt < 0)
-               usb_detach_broadcast(sc->sc_hdev.sc_dev, &sc->sc_detach_cv);
+               cv_broadcast(&sc->sc_detach_cv);
        mutex_exit(&sc->sc_lock);
        return error;
 }
@@ -507,7 +509,7 @@
 
        mutex_enter(&sc->sc_lock);
        if (--sc->sc_refcnt < 0)
-               usb_detach_broadcast(sc->sc_hdev.sc_dev, &sc->sc_detach_cv);
+               cv_broadcast(&sc->sc_detach_cv);
        mutex_exit(&sc->sc_lock);
        return error;
 }
@@ -699,7 +701,7 @@
 
        mutex_enter(&sc->sc_lock);
        if (--sc->sc_refcnt < 0)
-               usb_detach_broadcast(sc->sc_hdev.sc_dev, &sc->sc_detach_cv);
+               cv_broadcast(&sc->sc_detach_cv);
        mutex_exit(&sc->sc_lock);
        return error;
 }
diff -r 5ecbdc3ff58c -r 13b788bef78d sys/dev/usb/umass.c
--- a/sys/dev/usb/umass.c       Wed Oct 26 07:31:24 2016 +0000
+++ b/sys/dev/usb/umass.c       Thu Oct 27 07:46:19 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: umass.c,v 1.149.2.14 2016/07/09 20:25:16 skrll Exp $   */
+/*     $NetBSD: umass.c,v 1.149.2.15 2016/10/27 07:46:19 skrll Exp $   */
 
 /*
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -124,7 +124,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.149.2.14 2016/07/09 20:25:16 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.149.2.15 2016/10/27 07:46:19 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -812,7 +812,10 @@
                aprint_normal_dev(self, "waiting for refcnt\n");
 #endif
                /* Wait for processes to go away. */
-               usb_detach_wait(sc->sc_dev, &sc->sc_detach_cv, &sc->sc_lock);
+               if (cv_timedwait(&sc->sc_detach_cv, &sc->sc_lock, hz * 60)) {
+                       printf("%s: %s didn't detach\n", __func__,
+                           device_xname(sc->sc_dev));
+               }
        }
        mutex_exit(&sc->sc_lock);
 
diff -r 5ecbdc3ff58c -r 13b788bef78d sys/dev/usb/umidi.c
--- a/sys/dev/usb/umidi.c       Wed Oct 26 07:31:24 2016 +0000
+++ b/sys/dev/usb/umidi.c       Thu Oct 27 07:46:19 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: umidi.c,v 1.65.14.12 2016/07/09 20:25:16 skrll Exp $   */
+/*     $NetBSD: umidi.c,v 1.65.14.13 2016/10/27 07:46:19 skrll Exp $   */
 
 /*
  * Copyright (c) 2001, 2012, 2014 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umidi.c,v 1.65.14.12 2016/07/09 20:25:16 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umidi.c,v 1.65.14.13 2016/10/27 07:46:19 skrll Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -458,7 +458,10 @@
        mutex_enter(&sc->sc_lock);
        sc->sc_dying = 1;
        if (--sc->sc_refcnt >= 0)
-               usb_detach_wait(sc->sc_dev, &sc->sc_detach_cv, &sc->sc_lock);
+               if (cv_timedwait(&sc->sc_detach_cv, &sc->sc_lock, hz * 60)) {
+                       printf("%s: %s didn't detach\n", __func__,
+                           device_xname(sc->sc_dev));
+               }
        mutex_exit(&sc->sc_lock);
 
        detach_all_mididevs(sc, flags);
@@ -545,7 +548,7 @@
                close_in_jack(mididev->in_jack);
 
        if (--sc->sc_refcnt < 0)
-               usb_detach_broadcast(sc->sc_dev, &sc->sc_detach_cv);
+               cv_broadcast(&sc->sc_detach_cv);
 
        mididev->opened = 0;
        mididev->closing = 0;
@@ -1793,7 +1796,7 @@
        }
 
        if (--sc->sc_refcnt < 0)
-               usb_detach_broadcast(sc->sc_dev, &sc->sc_detach_cv);
+               cv_broadcast(&sc->sc_detach_cv);
 
        return 0;
 }
diff -r 5ecbdc3ff58c -r 13b788bef78d sys/dev/usb/usbdi_util.c
--- a/sys/dev/usb/usbdi_util.c  Wed Oct 26 07:31:24 2016 +0000
+++ b/sys/dev/usb/usbdi_util.c  Thu Oct 27 07:46:19 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usbdi_util.c,v 1.63.2.13 2016/02/06 08:01:57 skrll Exp $       */
+/*     $NetBSD: usbdi_util.c,v 1.63.2.14 2016/10/27 07:46:19 skrll Exp $       */
 
 /*
  * Copyright (c) 1998, 2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbdi_util.c,v 1.63.2.13 2016/02/06 08:01:57 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi_util.c,v 1.63.2.14 2016/10/27 07:46:19 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -547,27 +547,6 @@
 }
 
 void
-usb_detach_wait(device_t dv, kcondvar_t *cv, kmutex_t *lock)
-{
-       USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
-
-       DPRINTFN(1, "waiting for dv %p", dv, 0, 0, 0);
-       if (cv_timedwait(cv, lock, hz * 60))    // dv, PZERO, "usbdet", hz * 60
-               printf("usb_detach_wait: %s didn't detach\n",
-                       device_xname(dv));
-       DPRINTFN(1, "done", 0, 0, 0, 0);
-}



Home | Main Index | Thread Index | Old Index