Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/dreamcast/dev/maple Convert tsleep(9)/wakeup(9) pai...
details: https://anonhg.NetBSD.org/src/rev/3e7f7522b5de
branches: trunk
changeset: 342098:3e7f7522b5de
user: tsutsui <tsutsui%NetBSD.org@localhost>
date: Sun Dec 06 02:04:10 2015 +0000
description:
Convert tsleep(9)/wakeup(9) pairs to condvar(9) with mutex(9).
Briefly tested with mkbd(4).
diffstat:
sys/arch/dreamcast/dev/maple/maple.c | 41 ++++++++++++++++++++------------
sys/arch/dreamcast/dev/maple/maplevar.h | 10 +++++--
2 files changed, 32 insertions(+), 19 deletions(-)
diffs (167 lines):
diff -r c0043c5396ac -r 3e7f7522b5de sys/arch/dreamcast/dev/maple/maple.c
--- a/sys/arch/dreamcast/dev/maple/maple.c Sun Dec 06 00:39:26 2015 +0000
+++ b/sys/arch/dreamcast/dev/maple/maple.c Sun Dec 06 02:04:10 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: maple.c,v 1.51 2014/07/25 08:10:32 dholland Exp $ */
+/* $NetBSD: maple.c,v 1.52 2015/12/06 02:04:10 tsutsui Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: maple.c,v 1.51 2014/07/25 08:10:32 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: maple.c,v 1.52 2015/12/06 02:04:10 tsutsui Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -76,6 +76,8 @@
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/bus.h>
+#include <sys/mutex.h>
+#include <sys/condvar.h>
#include <uvm/uvm.h>
@@ -247,6 +249,11 @@
maple_polling = 1;
maple_scanbus(sc);
+ mutex_init(&sc->sc_dma_lock, MUTEX_DEFAULT, IPL_MAPLE);
+ cv_init(&sc->sc_dma_cv, device_xname(self));
+ mutex_init(&sc->sc_event_lock, MUTEX_DEFAULT, IPL_SOFTCLOCK);
+ cv_init(&sc->sc_event_cv, device_xname(self));
+
callout_init(&sc->maple_callout_ch, 0);
sc->sc_intrhand = sysasic_intr_establish(SYSASIC_EVENT_MAPLE_DMADONE,
@@ -835,13 +842,12 @@
{
struct maple_softc *sc = device_private(dev);
struct maple_func *fn;
- int s;
KASSERT(func >= 0 && func < 32);
KASSERT(command);
KASSERT((flags & ~MAPLE_FLAG_CMD_PERIODIC_TIMING) == 0);
- s = splsoftclock();
+ mutex_enter(&sc->sc_event_lock);
fn = &u->u_func[func];
#if 1 /*def DIAGNOSTIC*/
@@ -860,9 +866,9 @@
} else {
fn->f_cmdstat = MAPLE_CMDSTAT_ASYNC;
TAILQ_INSERT_TAIL(&sc->sc_acmdq, fn, f_cmdq);
- wakeup(&sc->sc_event); /* wake for async event */
+ cv_broadcast(&sc->sc_event_cv); /* wake for async event */
}
- splx(s);
+ mutex_exit(&sc->sc_event_lock);
}
static void
@@ -1422,7 +1428,6 @@
{
struct maple_softc *sc = arg;
unsigned cnt = 1; /* timing counter */
- int s;
#if defined(MAPLE_DEBUG) && MAPLE_DEBUG > 1
int noreq = 0;
#endif
@@ -1485,19 +1490,19 @@
/*
* start DMA
*/
- s = splmaple();
+ mutex_enter(&sc->sc_dma_lock);
maple_start(sc);
/*
* wait until DMA done
*/
- if (tsleep(&sc->sc_dmadone, PWAIT, "mdma", hz)
+ if (cv_timedwait(&sc->sc_dma_cv, &sc->sc_dma_lock, hz)
== EWOULDBLOCK) {
/* was DDB active? */
printf("%s: timed out\n",
device_xname(sc->sc_dev));
}
- splx(s);
+ mutex_exit(&sc->sc_dma_lock);
/*
* call handlers
@@ -1522,17 +1527,17 @@
/*
* wait for an event
*/
- s = splsoftclock();
+ mutex_enter(&sc->sc_event_lock);
if (TAILQ_EMPTY(&sc->sc_acmdq) && sc->sc_event == 0 &&
TAILQ_EMPTY(&sc->sc_periodicdeferq)) {
- if (tsleep(&sc->sc_event, PWAIT, "mslp", hz)
- == EWOULDBLOCK) {
+ if (cv_timedwait(&sc->sc_event_cv, &sc->sc_event_lock,
+ hz) == EWOULDBLOCK) {
printf("%s: event timed out\n",
device_xname(sc->sc_dev));
}
}
- splx(s);
+ mutex_exit(&sc->sc_event_lock);
}
@@ -1547,7 +1552,9 @@
{
struct maple_softc *sc = arg;
- wakeup(&sc->sc_dmadone);
+ mutex_enter(&sc->sc_dma_lock);
+ cv_broadcast(&sc->sc_dma_cv);
+ mutex_exit(&sc->sc_dma_lock);
return 1;
}
@@ -1557,8 +1564,10 @@
{
struct maple_softc *sc = ctx;
+ mutex_enter(&sc->sc_event_lock);
sc->sc_event = 1; /* mark as periodic event */
- wakeup(&sc->sc_event);
+ cv_broadcast(&sc->sc_event_cv);
+ mutex_exit(&sc->sc_event_lock);
}
/*
diff -r c0043c5396ac -r 3e7f7522b5de sys/arch/dreamcast/dev/maple/maplevar.h
--- a/sys/arch/dreamcast/dev/maple/maplevar.h Sun Dec 06 00:39:26 2015 +0000
+++ b/sys/arch/dreamcast/dev/maple/maplevar.h Sun Dec 06 02:04:10 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: maplevar.h,v 1.14 2012/10/27 17:17:45 chs Exp $ */
+/* $NetBSD: maplevar.h,v 1.15 2015/12/06 02:04:10 tsutsui Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -184,9 +184,13 @@
uint32_t sc_txbuf_phys; /* 29-bit physical address */
void *sc_intrhand;
- int sc_dmadone; /* wchan */
+
+ kmutex_t sc_dma_lock;
+ kcondvar_t sc_dma_cv;
- int sc_event; /* periodic event is active / wchan */
+ int sc_event; /* periodic event is active */
+ kmutex_t sc_event_lock;
+ kcondvar_t sc_event_cv;
SIMPLEQ_HEAD(maple_dmaq_head, maple_unit) sc_dmaq, sc_retryq;
TAILQ_HEAD(maple_unitq_head, maple_unit) sc_probeq, sc_pingq;
Home |
Main Index |
Thread Index |
Old Index