Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src-draft/trunk]: src/sys/dev/usb Hold the lock over access to the data stru...
details: https://anonhg.NetBSD.org/src-all/rev/4a92a330489c
branches: trunk
changeset: 937308:4a92a330489c
user: Taylor R Campbell <riastradh%NetBSD.org@localhost>
date: Sun Aug 16 00:36:24 2020 +0000
description:
Hold the lock over access to the data structures it covers.
Still not MPSAFE, but progress.
diffstat:
sys/dev/usb/ugen.c | 86 ++++++++++++++++++++++++++++++++---------------------
1 files changed, 51 insertions(+), 35 deletions(-)
diffs (138 lines):
diff -r ddb21176686b -r 4a92a330489c sys/dev/usb/ugen.c
--- a/sys/dev/usb/ugen.c Sun Aug 16 00:31:06 2020 +0000
+++ b/sys/dev/usb/ugen.c Sun Aug 16 00:36:24 2020 +0000
@@ -1964,12 +1964,18 @@
{
struct ugen_endpoint *sce = kn->kn_hook;
struct ugen_softc *sc = sce->sc;
+ int ret;
- if (sc->sc_dying)
- return 0;
+ mutex_enter(&sc->sc_lock);
+ if (sc->sc_dying) {
+ ret = 0;
+ } else {
+ kn->kn_data = sce->q.c_cc;
+ ret = kn->kn_data > 0;
+ }
+ mutex_exit(&sc->sc_lock);
- kn->kn_data = sce->q.c_cc;
- return kn->kn_data > 0;
+ return ret;
}
static int
@@ -1977,20 +1983,24 @@
{
struct ugen_endpoint *sce = kn->kn_hook;
struct ugen_softc *sc = sce->sc;
-
- if (sc->sc_dying)
- return 0;
+ int ret;
- if (sce->cur == sce->fill)
- return 0;
-
- if (sce->cur < sce->fill)
+ mutex_enter(&sc->sc_lock);
+ if (sc->sc_dying) {
+ ret = 0;
+ } else if (sce->cur == sce->fill) {
+ ret = 0;
+ } else if (sce->cur < sce->fill) {
kn->kn_data = sce->fill - sce->cur;
- else
+ ret = 1;
+ } else {
kn->kn_data = (sce->limit - sce->cur) +
(sce->fill - sce->ibuf);
+ ret = 1;
+ }
+ mutex_exit(&sc->sc_lock);
- return 1;
+ return ret;
}
static int
@@ -1998,24 +2008,27 @@
{
struct ugen_endpoint *sce = kn->kn_hook;
struct ugen_softc *sc = sce->sc;
+ int ret;
- if (sc->sc_dying)
- return 0;
-
- if (!(sce->state & UGEN_BULK_RA))
+ mutex_enter(&sc->sc_lock);
+ if (sc->sc_dying) {
+ ret = 0;
+ } else if (!(sce->state & UGEN_BULK_RA)) {
/*
* We have no easy way of determining if a read will
* yield any data or a write will happen.
* So, emulate "seltrue".
*/
- return filt_seltrue(kn, hint);
+ ret = filt_seltrue(kn, hint);
+ } else if (sce->ra_wb_used == 0) {
+ ret = 0;
+ } else {
+ kn->kn_data = sce->ra_wb_used;
+ ret = 1;
+ }
+ mutex_exit(&sc->sc_lock);
- if (sce->ra_wb_used == 0)
- return 0;
-
- kn->kn_data = sce->ra_wb_used;
-
- return 1;
+ return ret;
}
static int
@@ -2023,24 +2036,27 @@
{
struct ugen_endpoint *sce = kn->kn_hook;
struct ugen_softc *sc = sce->sc;
+ int ret;
- if (sc->sc_dying)
- return 0;
-
- if (!(sce->state & UGEN_BULK_WB))
+ mutex_enter(&sc->sc_lock);
+ if (sc->sc_dying) {
+ ret = 0;
+ } else if (!(sce->state & UGEN_BULK_WB)) {
/*
* We have no easy way of determining if a read will
* yield any data or a write will happen.
* So, emulate "seltrue".
*/
- return filt_seltrue(kn, hint);
+ ret = filt_seltrue(kn, hint);
+ } else if (sce->ra_wb_used == sce->limit - sce->ibuf) {
+ ret = 0;
+ } else {
+ kn->kn_data = (sce->limit - sce->ibuf) - sce->ra_wb_used;
+ ret = 1;
+ }
+ mutex_exit(&sc->sc_lock);
- if (sce->ra_wb_used == sce->limit - sce->ibuf)
- return 0;
-
- kn->kn_data = (sce->limit - sce->ibuf) - sce->ra_wb_used;
-
- return 1;
+ return ret;
}
static const struct filterops ugenread_intr_filtops = {
Home |
Main Index |
Thread Index |
Old Index