Remove (mostly useless) usb_detach_{broadcast,wait} and replace with

cv_{broadcast,timedwait}

Really should loop on conditon.
This commit is contained in:
skrll 2019-02-07 13:20:41 +00:00
parent 4a35ae3e32
commit 4740d9862c
7 changed files with 31 additions and 55 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ugen.c,v 1.143 2019/01/29 09:28:50 pgoyette Exp $ */
/* $NetBSD: ugen.c,v 1.144 2019/02/07 13:20:41 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.143 2019/01/29 09:28:50 pgoyette Exp $");
__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.144 2019/02/07 13:20:41 skrll Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@ -843,7 +843,7 @@ ugenread(dev_t dev, struct uio *uio, int flag)
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;
@ -1033,7 +1033,7 @@ ugenwrite(dev_t dev, struct uio *uio, int flag)
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;
@ -1080,7 +1080,8 @@ ugen_detach(device_t self, int flags)
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))
aprint_error_dev(self, ": didn't detach\n");
}
mutex_exit(&sc->sc_lock);
@ -1867,7 +1868,7 @@ ugenioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
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;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: uhid.c,v 1.104 2019/01/29 09:28:50 pgoyette Exp $ */
/* $NetBSD: uhid.c,v 1.105 2019/02/07 13:20:41 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.104 2019/01/29 09:28:50 pgoyette Exp $");
__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.105 2019/02/07 13:20:41 skrll Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@ -230,8 +230,8 @@ uhid_detach(device_t self, int flags)
/* 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))
aprint_error_dev(self, ": didn't detach\n");
}
}
mutex_exit(&sc->sc_lock);
@ -458,7 +458,7 @@ uhidread(dev_t dev, struct uio *uio, int flag)
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;
}
@ -508,7 +508,7 @@ uhidwrite(dev_t dev, struct uio *uio, int flag)
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;
}
@ -702,7 +702,7 @@ uhidioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
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;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: umass.c,v 1.168 2019/02/03 03:19:28 mrg Exp $ */
/* $NetBSD: umass.c,v 1.169 2019/02/07 13:20:41 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.168 2019/02/03 03:19:28 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.169 2019/02/07 13:20:41 skrll Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -820,7 +820,8 @@ umass_detach(device_t self, int flags)
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))
aprint_error_dev(self, ": didn't detach\n");
}
mutex_exit(&sc->sc_lock);

View File

@ -1,4 +1,4 @@
/* $NetBSD: umass_scsipi.c,v 1.57 2019/01/22 06:46:21 skrll Exp $ */
/* $NetBSD: umass_scsipi.c,v 1.58 2019/02/07 13:20:41 skrll Exp $ */
/*
* Copyright (c) 2001, 2003, 2012 The NetBSD Foundation, Inc.
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.57 2019/01/22 06:46:21 skrll Exp $");
__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.58 2019/02/07 13:20:41 skrll Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -144,7 +144,7 @@ umass_scsi_attach(struct umass_softc *sc)
scsiprint);
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);
@ -177,7 +177,7 @@ umass_atapi_attach(struct umass_softc *sc)
atapiprint);
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 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: umidi.c,v 1.75 2018/09/03 16:29:34 riastradh Exp $ */
/* $NetBSD: umidi.c,v 1.76 2019/02/07 13:20:41 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.75 2018/09/03 16:29:34 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: umidi.c,v 1.76 2019/02/07 13:20:41 skrll Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -462,7 +462,8 @@ umidi_detach(device_t self, int flags)
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))
aprint_error_dev(self, ": didn't detach\n");
mutex_exit(&sc->sc_lock);
detach_all_mididevs(sc, flags);
@ -549,7 +550,7 @@ umidi_close(void *addr)
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;
@ -1786,7 +1787,7 @@ out_jack_output(struct umidi_jack *out_jack, u_char *src, int len, int cin)
}
if (--sc->sc_refcnt < 0)
usb_detach_broadcast(sc->sc_dev, &sc->sc_detach_cv);
cv_broadcast(&sc->sc_detach_cv);
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: usbdi_util.c,v 1.72 2018/11/08 02:11:54 manu Exp $ */
/* $NetBSD: usbdi_util.c,v 1.73 2019/02/07 13:20:41 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.72 2018/11/08 02:11:54 manu Exp $");
__KERNEL_RCSID(0, "$NetBSD: usbdi_util.c,v 1.73 2019/02/07 13:20:41 skrll Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -568,26 +568,6 @@ usbd_intr_transfer(struct usbd_xfer *xfer, struct usbd_pipe *pipe,
return err;
}
void
usb_detach_wait(device_t dv, kcondvar_t *cv, kmutex_t *lock)
{
USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
DPRINTFN(1, "waiting for dv %#jx", (uintptr_t)dv, 0, 0, 0);
if (cv_timedwait(cv, lock, hz * 60)) // dv, PZERO, "usbdet", hz * 60
aprint_error_dev(dv, "usb_detach_wait: didn't detach\n");
DPRINTFN(1, "done", 0, 0, 0, 0);
}
void
usb_detach_broadcast(device_t dv, kcondvar_t *cv)
{
USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
DPRINTFN(1, "for dv %#jx", (uintptr_t)dv, 0, 0, 0);
cv_broadcast(cv);
}
void
usb_detach_waitold(device_t dv)
{

View File

@ -1,4 +1,4 @@
/* $NetBSD: usbdi_util.h,v 1.48 2018/11/08 02:11:54 manu Exp $ */
/* $NetBSD: usbdi_util.h,v 1.49 2019/02/07 13:20:41 skrll Exp $ */
/*
* Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@ -90,13 +90,6 @@ usbd_status usbd_intr_transfer(struct usbd_xfer *, struct usbd_pipe *,
void usb_detach_waitold(device_t);
void usb_detach_wakeupold(device_t);
/*
* MPSAFE versions - mutex must be at IPL_USB.
*/
void usb_detach_wait(device_t dv, kcondvar_t *, kmutex_t *);
void usb_detach_broadcast(device_t, kcondvar_t *);
typedef struct {
uByte bLength;
uByte bDescriptorType;