lockmgr -> mutex
This commit is contained in:
parent
6febf18c31
commit
6874e511b7
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: acpi_ec.c,v 1.42 2007/10/19 11:59:34 ad Exp $ */
|
||||
/* $NetBSD: acpi_ec.c,v 1.43 2007/12/05 07:58:29 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 2001 Wasabi Systems, Inc.
|
||||
|
@ -172,7 +172,7 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.42 2007/10/19 11:59:34 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.43 2007/12/05 07:58:29 ad Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -210,7 +210,7 @@ struct acpi_ec_softc {
|
|||
uint32_t sc_csrvalue; /* saved control register */
|
||||
uint32_t sc_uid; /* _UID in namespace (ECDT only) */
|
||||
|
||||
struct lock sc_lock; /* serialize operations to this EC */
|
||||
kmutex_t sc_lock; /* serialize operations to this EC */
|
||||
struct simplelock sc_slock; /* protect against interrupts */
|
||||
UINT32 sc_glkhandle; /* global lock handle */
|
||||
UINT32 sc_glk; /* need global lock? */
|
||||
|
@ -274,7 +274,7 @@ static inline int
|
|||
EcIsLocked(struct acpi_ec_softc *sc)
|
||||
{
|
||||
|
||||
return (lockstatus(&sc->sc_lock) == LK_EXCLUSIVE);
|
||||
return (mutex_owned(&sc->sc_lock));
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
@ -283,14 +283,14 @@ EcLock(struct acpi_ec_softc *sc)
|
|||
ACPI_STATUS rv;
|
||||
int s;
|
||||
|
||||
lockmgr(&sc->sc_lock, LK_EXCLUSIVE, NULL);
|
||||
mutex_enter(&sc->sc_lock);
|
||||
if (sc->sc_glk) {
|
||||
rv = AcpiAcquireGlobalLock(EC_LOCK_TIMEOUT,
|
||||
&sc->sc_glkhandle);
|
||||
if (ACPI_FAILURE(rv)) {
|
||||
printf("%s: failed to acquire global lock\n",
|
||||
sc->sc_dev.dv_xname);
|
||||
lockmgr(&sc->sc_lock, LK_RELEASE, NULL);
|
||||
mutex_exit(&sc->sc_lock);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -339,7 +339,7 @@ EcUnlock(struct acpi_ec_softc *sc)
|
|||
printf("%s: failed to release global lock\n",
|
||||
sc->sc_dev.dv_xname);
|
||||
}
|
||||
lockmgr(&sc->sc_lock, LK_RELEASE, NULL);
|
||||
mutex_exit(&sc->sc_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -454,7 +454,7 @@ acpiec_early_attach(struct device *parent)
|
|||
printf("%s: found ECDT, GPE %d\n", parent->dv_xname,
|
||||
ecdt_sc->sc_gpebit);
|
||||
|
||||
lockinit(&ecdt_sc->sc_lock, PWAIT, "eclock", 0, 0);
|
||||
mutex_init(&ecdt_sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
|
||||
simple_lock_init(&ecdt_sc->sc_slock);
|
||||
|
||||
AcpiOsUnmapMemory(ep, ep->Length);
|
||||
|
@ -495,7 +495,7 @@ acpiec_attach(struct device *parent, struct device *self, void *aux)
|
|||
aprint_naive(": ACPI Embedded Controller\n");
|
||||
aprint_normal(": ACPI Embedded Controller\n");
|
||||
|
||||
lockinit(&sc->sc_lock, PWAIT, "eclock", 0, 0);
|
||||
mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
|
||||
simple_lock_init(&sc->sc_slock);
|
||||
|
||||
sc->sc_handle = aa->aa_node->ad_handle;
|
||||
|
@ -530,6 +530,7 @@ acpiec_attach(struct device *parent, struct device *self, void *aux)
|
|||
bus_space_unmap(ecdt_sc->sc_data_st,
|
||||
ecdt_sc->sc_data_sh, 1);
|
||||
|
||||
mutex_destroy(&ecdt_sc->sc_lock);
|
||||
free(ecdt_sc, M_ACPI);
|
||||
ecdt_sc = NULL;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: apm.c,v 1.13 2007/11/25 07:55:21 xtraeme Exp $ */
|
||||
/* $NetBSD: apm.c,v 1.14 2007/12/05 07:58:29 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
|
||||
|
@ -40,7 +40,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: apm.c,v 1.13 2007/11/25 07:55:21 xtraeme Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: apm.c,v 1.14 2007/12/05 07:58:29 ad Exp $");
|
||||
|
||||
#include "opt_apm.h"
|
||||
|
||||
|
@ -102,9 +102,9 @@ int apmdebug = 0;
|
|||
* user context.
|
||||
*/
|
||||
#define APM_LOCK(apmsc) \
|
||||
(void) lockmgr(&(apmsc)->sc_lock, LK_EXCLUSIVE, NULL)
|
||||
(void) mutex_enter(&(apmsc)->sc_lock)
|
||||
#define APM_UNLOCK(apmsc) \
|
||||
(void) lockmgr(&(apmsc)->sc_lock, LK_RELEASE, NULL)
|
||||
(void) mutex_exit(&(apmsc)->sc_lock)
|
||||
|
||||
static void apm_event_handle(struct apm_softc *, u_int, u_int);
|
||||
static void apm_periodic_check(struct apm_softc *);
|
||||
|
@ -671,7 +671,7 @@ apm_attach(struct apm_softc *sc)
|
|||
if (sc->sc_ops->aa_cpu_busy)
|
||||
(*sc->sc_ops->aa_cpu_busy)(sc->sc_cookie);
|
||||
|
||||
lockinit(&sc->sc_lock, PWAIT, "apmlk", 0, 0);
|
||||
mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
|
||||
|
||||
/* Initial state is `resumed'. */
|
||||
sc->sc_power_state = PWR_RESUME;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: apmvar.h,v 1.4 2007/07/09 22:56:41 ad Exp $ */
|
||||
/* $NetBSD: apmvar.h,v 1.5 2007/12/05 07:58:29 ad Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
|
@ -62,7 +62,7 @@ struct apm_softc {
|
|||
int sc_event_ptr;
|
||||
int sc_power_state;
|
||||
lwp_t *sc_thread;
|
||||
struct lock sc_lock;
|
||||
kmutex_t sc_lock;
|
||||
struct apm_event_info sc_event_list[APM_NEVENTS];
|
||||
struct apm_accessops *sc_ops;
|
||||
int sc_hwflags;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: apmdev.c,v 1.12 2007/07/10 13:55:20 nonaka Exp $ */
|
||||
/* $NetBSD: apmdev.c,v 1.13 2007/12/05 07:58:29 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
|
||||
|
@ -40,7 +40,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: apmdev.c,v 1.12 2007/07/10 13:55:20 nonaka Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: apmdev.c,v 1.13 2007/12/05 07:58:29 ad Exp $");
|
||||
|
||||
#ifdef _KERNEL_OPT
|
||||
#include "opt_apmdev.h"
|
||||
|
@ -60,7 +60,7 @@ __KERNEL_RCSID(0, "$NetBSD: apmdev.c,v 1.12 2007/07/10 13:55:20 nonaka Exp $");
|
|||
#include <sys/kernel.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/kthread.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/user.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/device.h>
|
||||
|
@ -104,8 +104,8 @@ struct apm_softc {
|
|||
int event_count;
|
||||
int event_ptr;
|
||||
int sc_power_state;
|
||||
struct lwp *sc_thread;
|
||||
struct lock sc_lock;
|
||||
lwp_t *sc_thread;
|
||||
kmutex_t sc_lock;
|
||||
struct apm_event_info event_list[APM_NEVENTS];
|
||||
struct apm_accessops *ops;
|
||||
void *cookie;
|
||||
|
@ -126,9 +126,9 @@ struct apm_softc {
|
|||
* user context.
|
||||
*/
|
||||
#define APM_LOCK(apmsc) \
|
||||
(void) lockmgr(&(apmsc)->sc_lock, LK_EXCLUSIVE, NULL)
|
||||
(void) mutex_enter(&(apmsc)->sc_lock)
|
||||
#define APM_UNLOCK(apmsc) \
|
||||
(void) lockmgr(&(apmsc)->sc_lock, LK_RELEASE, NULL)
|
||||
(void) mutex_exit(&(apmsc)->sc_lock)
|
||||
|
||||
static void apmattach(struct device *, struct device *, void *);
|
||||
static int apmmatch(struct device *, struct cfdata *, void *);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: i82365.c,v 1.100 2007/10/19 11:59:52 ad Exp $ */
|
||||
/* $NetBSD: i82365.c,v 1.101 2007/12/05 07:58:29 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 Charles M. Hannum. All rights reserved.
|
||||
|
@ -49,7 +49,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: i82365.c,v 1.100 2007/10/19 11:59:52 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: i82365.c,v 1.101 2007/12/05 07:58:29 ad Exp $");
|
||||
|
||||
#define PCICDEBUG
|
||||
|
||||
|
@ -237,7 +237,7 @@ pcic_attach(sc)
|
|||
|
||||
DPRINTF(("pcic ident regs:"));
|
||||
|
||||
lockinit(&sc->sc_pcic_lock, PWAIT, "pciclk", 0, 0);
|
||||
mutex_init(&sc->sc_pcic_lock, MUTEX_DEFAULT, IPL_NONE);
|
||||
|
||||
/* find and configure for the available sockets */
|
||||
for (i = 0; i < __arraycount(sc->handle); i++) {
|
||||
|
@ -537,7 +537,7 @@ pcic_event_thread(arg)
|
|||
* Serialize event processing on the PCIC. We may
|
||||
* sleep while we hold this lock.
|
||||
*/
|
||||
(void) lockmgr(&sc->sc_pcic_lock, LK_EXCLUSIVE, NULL);
|
||||
mutex_enter(&sc->sc_pcic_lock);
|
||||
|
||||
s = splhigh();
|
||||
if ((pe = SIMPLEQ_FIRST(&h->events)) == NULL) {
|
||||
|
@ -549,7 +549,7 @@ pcic_event_thread(arg)
|
|||
/*
|
||||
* No events to process; release the PCIC lock.
|
||||
*/
|
||||
(void) lockmgr(&sc->sc_pcic_lock, LK_RELEASE, NULL);
|
||||
(void) mutex_exit(&sc->sc_pcic_lock);
|
||||
(void) tsleep(&h->events, PWAIT, "pcicev", 0);
|
||||
continue;
|
||||
} else {
|
||||
|
@ -619,7 +619,7 @@ pcic_event_thread(arg)
|
|||
}
|
||||
free(pe, M_TEMP);
|
||||
|
||||
(void) lockmgr(&sc->sc_pcic_lock, LK_RELEASE, NULL);
|
||||
mutex_exit(&sc->sc_pcic_lock);
|
||||
}
|
||||
|
||||
h->event_thread = NULL;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: i82365var.h,v 1.27 2007/07/09 21:00:36 ad Exp $ */
|
||||
/* $NetBSD: i82365var.h,v 1.28 2007/12/05 07:58:30 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Marc Horowitz. All rights reserved.
|
||||
|
@ -31,7 +31,7 @@
|
|||
|
||||
#include <sys/device.h>
|
||||
#include <sys/callout.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
|
||||
#include <dev/pcmcia/pcmciareg.h>
|
||||
#include <dev/pcmcia/pcmciachip.h>
|
||||
|
@ -129,7 +129,7 @@ struct pcic_softc {
|
|||
|
||||
pcmcia_chipset_tag_t pct;
|
||||
|
||||
struct lock sc_pcic_lock;
|
||||
kmutex_t sc_pcic_lock;
|
||||
|
||||
/* this needs to be large enough to hold PCIC_MEM_PAGES bits */
|
||||
int subregionmask;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mtd803.c,v 1.15 2007/10/19 11:59:57 ad Exp $ */
|
||||
/* $NetBSD: mtd803.c,v 1.16 2007/12/05 07:58:30 ad Exp $ */
|
||||
|
||||
/*-
|
||||
*
|
||||
|
@ -43,7 +43,7 @@
|
|||
* I don't have access to a computer with PCI other than i386, and i386
|
||||
* is just such a machine where dmamap_syncs don't do anything.
|
||||
* - Powerhook for when resuming after standby.
|
||||
* - Watchdog stuff doesn't work yet, the system crashes.(lockmgr: no context)
|
||||
* - Watchdog stuff doesn't work yet, the system crashes.
|
||||
* - There seems to be a CardBus version of the card. (see datasheet)
|
||||
* Perhaps a detach function is necessary then? (free buffs, stop rx/tx etc)
|
||||
* - When you enable the TXBUN (Tx buffer unavailable) interrupt, it gets
|
||||
|
@ -51,7 +51,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: mtd803.c,v 1.15 2007/10/19 11:59:57 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: mtd803.c,v 1.16 2007/12/05 07:58:30 ad Exp $");
|
||||
|
||||
#include "bpfilter.h"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: irframe_tty.c,v 1.47 2007/11/19 18:51:48 ad Exp $ */
|
||||
/* $NetBSD: irframe_tty.c,v 1.48 2007/12/05 07:58:30 ad Exp $ */
|
||||
|
||||
/*
|
||||
* TODO
|
||||
|
@ -48,14 +48,14 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: irframe_tty.c,v 1.47 2007/11/19 18:51:48 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: irframe_tty.c,v 1.48 2007/12/05 07:58:30 ad Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/tty.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -101,7 +101,7 @@ struct irframet_softc {
|
|||
#define IRT_WSLP 0x02 /* waiting for data (write) */
|
||||
#define IRT_CLOSING 0x04 /* waiting for output to drain */
|
||||
#endif
|
||||
struct lock sc_wr_lk;
|
||||
kmutex_t sc_wr_lk;
|
||||
|
||||
struct irda_params sc_params;
|
||||
|
||||
|
@ -533,6 +533,7 @@ irframet_open(void *h, int flag, int mode,
|
|||
{
|
||||
struct tty *tp = h;
|
||||
struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
|
||||
static bool again;
|
||||
|
||||
DPRINTF(("%s: tp=%p\n", __FUNCTION__, tp));
|
||||
|
||||
|
@ -543,8 +544,13 @@ irframet_open(void *h, int flag, int mode,
|
|||
sc->sc_nframes = 0;
|
||||
sc->sc_framei = 0;
|
||||
sc->sc_frameo = 0;
|
||||
callout_init(&sc->sc_timeout, 0);
|
||||
lockinit(&sc->sc_wr_lk, PZERO, "irfrtl", 0, 0);
|
||||
|
||||
/* XXX */
|
||||
if (!again) {
|
||||
again = true;
|
||||
callout_init(&sc->sc_timeout, 0);
|
||||
mutex_init(&sc->sc_wr_lk, MUTEX_DEFAULT, IPL_NONE);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
@ -693,11 +699,11 @@ irt_write_frame(struct tty *tp, u_int8_t *tbuf, size_t len)
|
|||
|
||||
DPRINTF(("%s: tp=%p len=%zd\n", __FUNCTION__, tp, len));
|
||||
|
||||
lockmgr(&sc->sc_wr_lk, LK_EXCLUSIVE, NULL);
|
||||
mutex_enter(&sc->sc_wr_lk);
|
||||
error = 0;
|
||||
for (i = 0; !error && i < len; i++)
|
||||
error = irt_putc(tp, tbuf[i]);
|
||||
lockmgr(&sc->sc_wr_lk, LK_RELEASE, NULL);
|
||||
mutex_exit(&sc->sc_wr_lk);
|
||||
|
||||
irframetstart(tp);
|
||||
|
||||
|
@ -833,9 +839,9 @@ irframet_set_params(void *h, struct irda_params *p)
|
|||
|
||||
if (p->speed != sc->sc_params.speed) {
|
||||
/* Checked in irframe.c */
|
||||
lockmgr(&sc->sc_wr_lk, LK_EXCLUSIVE, NULL);
|
||||
mutex_enter(&sc->sc_wr_lk);
|
||||
irt_dongles[sc->sc_dongle].setspeed(tp, p->speed);
|
||||
lockmgr(&sc->sc_wr_lk, LK_RELEASE, NULL);
|
||||
mutex_exit(&sc->sc_wr_lk);
|
||||
sc->sc_params.speed = p->speed;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mcd.c,v 1.102 2007/10/19 12:00:20 ad Exp $ */
|
||||
/* $NetBSD: mcd.c,v 1.103 2007/12/05 07:58:30 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993, 1994, 1995 Charles M. Hannum. All rights reserved.
|
||||
|
@ -56,7 +56,7 @@
|
|||
/*static char COPYRIGHT[] = "mcd-driver (C)1993 by H.Veit & B.Moore";*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: mcd.c,v 1.102 2007/10/19 12:00:20 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: mcd.c,v 1.103 2007/12/05 07:58:30 ad Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -75,7 +75,7 @@ __KERNEL_RCSID(0, "$NetBSD: mcd.c,v 1.102 2007/10/19 12:00:20 ad Exp $");
|
|||
#include <sys/disklabel.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/disk.h>
|
||||
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/cpu.h>
|
||||
#include <sys/intr.h>
|
||||
#include <sys/bus.h>
|
||||
|
@ -122,7 +122,7 @@ struct mcd_mbx {
|
|||
struct mcd_softc {
|
||||
struct device sc_dev;
|
||||
struct disk sc_dk;
|
||||
struct lock sc_lock;
|
||||
kmutex_t sc_lock;
|
||||
void *sc_ih;
|
||||
|
||||
callout_t sc_pintr_ch;
|
||||
|
@ -249,7 +249,7 @@ mcdattach(struct device *parent, struct device *self, void *aux)
|
|||
return;
|
||||
}
|
||||
|
||||
lockinit(&sc->sc_lock, PRIBIO | PCATCH, "mcdlock", 0, 0);
|
||||
mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
|
||||
|
||||
sc->sc_iot = iot;
|
||||
sc->sc_ioh = ioh;
|
||||
|
@ -298,8 +298,7 @@ mcdopen(dev_t dev, int flag, int fmt, struct lwp *l)
|
|||
if (sc == NULL)
|
||||
return ENXIO;
|
||||
|
||||
if ((error = lockmgr(&sc->sc_lock, LK_EXCLUSIVE, NULL)) != 0)
|
||||
return error;
|
||||
mutex_enter(&sc->sc_lock);
|
||||
|
||||
if (sc->sc_dk.dk_openmask != 0) {
|
||||
/*
|
||||
|
@ -368,7 +367,7 @@ mcdopen(dev_t dev, int flag, int fmt, struct lwp *l)
|
|||
}
|
||||
sc->sc_dk.dk_openmask = sc->sc_dk.dk_copenmask | sc->sc_dk.dk_bopenmask;
|
||||
|
||||
lockmgr(&sc->sc_lock, LK_RELEASE, NULL);
|
||||
mutex_exit(&sc->sc_lock);
|
||||
return 0;
|
||||
|
||||
bad2:
|
||||
|
@ -383,7 +382,7 @@ bad:
|
|||
}
|
||||
|
||||
bad3:
|
||||
lockmgr(&sc->sc_lock, LK_RELEASE, NULL);
|
||||
mutex_exit(&sc->sc_lock);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
@ -392,12 +391,10 @@ mcdclose(dev_t dev, int flag, int fmt, struct lwp *l)
|
|||
{
|
||||
struct mcd_softc *sc = device_lookup(&mcd_cd, MCDUNIT(dev));
|
||||
int part = MCDPART(dev);
|
||||
int error;
|
||||
|
||||
MCD_TRACE("close: partition=%d\n", part);
|
||||
|
||||
if ((error = lockmgr(&sc->sc_lock, LK_EXCLUSIVE, NULL)) != 0)
|
||||
return error;
|
||||
mutex_enter(&sc->sc_lock);
|
||||
|
||||
switch (fmt) {
|
||||
case S_IFCHR:
|
||||
|
@ -418,7 +415,7 @@ mcdclose(dev_t dev, int flag, int fmt, struct lwp *l)
|
|||
(void) mcd_setlock(sc, MCD_LK_UNLOCK);
|
||||
}
|
||||
|
||||
lockmgr(&sc->sc_lock, LK_RELEASE, NULL);
|
||||
mutex_exit(&sc->sc_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -605,8 +602,7 @@ mcdioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
|
|||
#endif
|
||||
lp = addr;
|
||||
|
||||
if ((error = lockmgr(&sc->sc_lock, LK_EXCLUSIVE, NULL)) != 0)
|
||||
return error;
|
||||
mutex_enter(&sc->sc_lock);
|
||||
sc->flags |= MCDF_LABELLING;
|
||||
|
||||
error = setdisklabel(sc->sc_dk.dk_label,
|
||||
|
@ -616,7 +612,7 @@ mcdioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
|
|||
}
|
||||
|
||||
sc->flags &= ~MCDF_LABELLING;
|
||||
lockmgr(&sc->sc_lock, LK_RELEASE, NULL);
|
||||
mutex_exit(&sc->sc_lock);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: gti2c.c,v 1.7 2007/12/03 15:34:32 ad Exp $ */
|
||||
/* $NetBSD: gti2c.c,v 1.8 2007/12/05 07:58:31 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 Brocade Communcations, inc.
|
||||
|
@ -32,13 +32,13 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: gti2c.c,v 1.7 2007/12/03 15:34:32 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: gti2c.c,v 1.8 2007/12/05 07:58:31 ad Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/proc.h>
|
||||
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/intr.h>
|
||||
#include <sys/bus.h>
|
||||
|
||||
|
@ -54,7 +54,7 @@ struct gti2c_softc {
|
|||
struct evcnt sc_ev_intr;
|
||||
struct i2c_controller sc_i2c;
|
||||
struct gt_softc *sc_gt;
|
||||
struct lock sc_lock;
|
||||
kmutex_t sc_lock;
|
||||
};
|
||||
|
||||
static int gt_i2c_match(struct device *, struct cfdata *, void *);
|
||||
|
@ -111,10 +111,7 @@ gt_i2c_acquire_bus(void *cookie, int flags)
|
|||
if (flags & I2C_F_POLL)
|
||||
return 0;
|
||||
|
||||
error = lockmgr(&sc->sc_lock, LK_EXCLUSIVE, NULL);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
mutex_enter(&sc->sc_lock);
|
||||
status = gt_read(sc->sc_gt, I2C_REG_Status);
|
||||
if (status != I2C_Status_Idle) {
|
||||
gt_write(sc->sc_gt, I2C_REG_SoftReset, 1);
|
||||
|
@ -128,7 +125,7 @@ gt_i2c_release_bus(void *cookie, int flags)
|
|||
{
|
||||
struct gti2c_softc * const sc = cookie;
|
||||
|
||||
lockmgr(&sc->sc_lock, LK_RELEASE, NULL);
|
||||
mutex_exit(&sc->sc_lock);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -255,7 +252,7 @@ gt_i2c_attach(struct device *parent, struct device *self, void *aux)
|
|||
|
||||
GT_I2CFOUND(gt, ga);
|
||||
|
||||
lockinit(&sc->sc_lock, PZERO, sc->sc_dev.dv_xname, 0, 0);
|
||||
mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
|
||||
|
||||
sc->sc_i2c.ic_cookie = sc;
|
||||
sc->sc_i2c.ic_acquire_bus = gt_i2c_acquire_bus;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ppbus_base.c,v 1.13 2007/03/04 06:02:28 christos Exp $ */
|
||||
/* $NetBSD: ppbus_base.c,v 1.14 2007/12/05 07:58:31 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998, 1999 Nicolas Souchu
|
||||
|
@ -30,7 +30,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ppbus_base.c,v 1.13 2007/03/04 06:02:28 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ppbus_base.c,v 1.14 2007/12/05 07:58:31 ad Exp $");
|
||||
|
||||
#include "opt_ppbus_1284.h"
|
||||
#include "opt_ppbus.h"
|
||||
|
@ -371,9 +371,7 @@ ppbus_request_bus(struct device * dev, struct device * busdev, int how,
|
|||
|
||||
/* Loop until lock acquired (if PPBUS_WAIT) or an error occurs */
|
||||
for(;;) {
|
||||
error = lockmgr(&(bus->sc_lock), LK_EXCLUSIVE | LK_RECURSEFAIL,
|
||||
NULL);
|
||||
if(!error)
|
||||
if (mutex_tryenter(&(bus->sc_lock)))
|
||||
break;
|
||||
|
||||
if(how & PPBUS_WAIT) {
|
||||
|
@ -389,6 +387,7 @@ ppbus_request_bus(struct device * dev, struct device * busdev, int how,
|
|||
}
|
||||
}
|
||||
else {
|
||||
error = EWOULDBLOCK;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
@ -403,7 +402,7 @@ ppbus_request_bus(struct device * dev, struct device * busdev, int how,
|
|||
}
|
||||
|
||||
/* Release lock */
|
||||
lockmgr(&(bus->sc_lock), LK_RELEASE, NULL);
|
||||
mutex_exit(&(bus->sc_lock));
|
||||
|
||||
end:
|
||||
return error;
|
||||
|
@ -424,9 +423,7 @@ ppbus_release_bus(struct device * dev, struct device * busdev, int how,
|
|||
|
||||
/* Loop until lock acquired (if PPBUS_WAIT) or an error occurs */
|
||||
for(;;) {
|
||||
error = lockmgr(&(bus->sc_lock), LK_EXCLUSIVE | LK_RECURSEFAIL,
|
||||
NULL);
|
||||
if(!error)
|
||||
if (mutex_tryenter(&(bus->sc_lock)))
|
||||
break;
|
||||
|
||||
if(how & PPBUS_WAIT) {
|
||||
|
@ -442,6 +439,7 @@ ppbus_release_bus(struct device * dev, struct device * busdev, int how,
|
|||
}
|
||||
}
|
||||
else {
|
||||
error = EWOULDBLOCK;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
@ -456,7 +454,7 @@ ppbus_release_bus(struct device * dev, struct device * busdev, int how,
|
|||
}
|
||||
|
||||
/* Release lock */
|
||||
lockmgr(&(bus->sc_lock), LK_RELEASE, NULL);
|
||||
mutex_exit(&(bus->sc_lock));
|
||||
|
||||
end:
|
||||
return error;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ppbus_conf.c,v 1.11 2006/03/29 17:23:56 thorpej Exp $ */
|
||||
/* $NetBSD: ppbus_conf.c,v 1.12 2007/12/05 07:58:31 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998, 1999 Nicolas Souchu
|
||||
|
@ -30,7 +30,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ppbus_conf.c,v 1.11 2006/03/29 17:23:56 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ppbus_conf.c,v 1.12 2007/12/05 07:58:31 ad Exp $");
|
||||
|
||||
#include "opt_ppbus.h"
|
||||
#include "opt_ppbus_1284.h"
|
||||
|
@ -132,8 +132,7 @@ ppbus_attach(struct device *parent, struct device *self, void *aux)
|
|||
ppbus->ppbus_owner = NULL;
|
||||
|
||||
/* Initialize locking structures */
|
||||
lockinit(&(ppbus->sc_lock), PPBUSPRI | PCATCH, "ppbuslock", 0,
|
||||
LK_NOWAIT);
|
||||
mutex_init(&(ppbus->sc_lock), MUTEX_DEFAULT, IPL_NONE);
|
||||
|
||||
/* Set up bus mode and ieee state */
|
||||
ppbus->sc_mode = ppbus->ppbus_getmode(device_parent(self));
|
||||
|
@ -190,16 +189,7 @@ ppbus_detach(struct device *self, int flag)
|
|||
ppbus->sc_dev.dv_xname);
|
||||
}
|
||||
|
||||
if (lockmgr(&(ppbus->sc_lock), LK_DRAIN, NULL)) {
|
||||
if (!(flag & DETACH_QUIET))
|
||||
printf("%s: error while waiting for lock activity to "
|
||||
"end.\n", ppbus->sc_dev.dv_xname);
|
||||
if (!(flag & DETACH_FORCE))
|
||||
return 0;
|
||||
if (!(flag & DETACH_QUIET))
|
||||
printf("%s: continuing detach (DETACH_FORCE).\n",
|
||||
ppbus->sc_dev.dv_xname);
|
||||
}
|
||||
mutex_destroy(&(ppbus->sc_lock));
|
||||
|
||||
/* Detach children devices */
|
||||
while (!SLIST_EMPTY(&(ppbus->sc_childlist_head))) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ppbus_conf.h,v 1.8 2007/10/19 12:01:08 ad Exp $ */
|
||||
/* $NetBSD: ppbus_conf.h,v 1.9 2007/12/05 07:58:31 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998, 1999 Nicolas Souchu
|
||||
|
@ -32,7 +32,7 @@
|
|||
#define __PPBUS_CONF_H
|
||||
|
||||
#include <sys/device.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include <sys/bus.h>
|
||||
|
@ -87,7 +87,7 @@ struct ppbus_softc {
|
|||
struct device sc_dev;
|
||||
|
||||
/* Lock for critical section when requesting/releasing the bus */
|
||||
struct lock sc_lock;
|
||||
kmutex_t sc_lock;
|
||||
|
||||
#define PPBUS_OK 1
|
||||
#define PPBUS_NOK 0
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_axe.c,v 1.20 2007/09/01 07:32:32 dyoung Exp $ */
|
||||
/* $NetBSD: if_axe.c,v 1.21 2007/12/05 07:58:32 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 1999, 2000-2003
|
||||
|
@ -73,7 +73,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.20 2007/09/01 07:32:32 dyoung Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.21 2007/12/05 07:58:32 ad Exp $");
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
#include "opt_inet.h"
|
||||
|
@ -85,7 +85,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.20 2007/09/01 07:32:32 dyoung Exp $");
|
|||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/sockio.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/kernel.h>
|
||||
#if defined(__OpenBSD__)
|
||||
|
@ -199,13 +199,13 @@ Static void
|
|||
axe_lock_mii(struct axe_softc *sc)
|
||||
{
|
||||
sc->axe_refcnt++;
|
||||
usb_lockmgr(&sc->axe_mii_lock, LK_EXCLUSIVE, NULL);
|
||||
mutex_enter(&sc->axe_mii_lock);
|
||||
}
|
||||
|
||||
Static void
|
||||
axe_unlock_mii(struct axe_softc *sc)
|
||||
{
|
||||
usb_lockmgr(&sc->axe_mii_lock, LK_RELEASE, NULL);
|
||||
mutex_exit(&sc->axe_mii_lock);
|
||||
if (--sc->axe_refcnt < 0)
|
||||
usb_detach_wakeup(USBDEV(sc->axe_dev));
|
||||
}
|
||||
|
@ -216,10 +216,11 @@ axe_cmd(struct axe_softc *sc, int cmd, int index, int val, void *buf)
|
|||
usb_device_request_t req;
|
||||
usbd_status err;
|
||||
|
||||
KASSERT(mutex_owned(&sc->axe_mii_lock));
|
||||
|
||||
if (sc->axe_dying)
|
||||
return(0);
|
||||
|
||||
axe_lock_mii(sc);
|
||||
if (AXE_CMD_DIR(cmd))
|
||||
req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
|
||||
else
|
||||
|
@ -230,7 +231,6 @@ axe_cmd(struct axe_softc *sc, int cmd, int index, int val, void *buf)
|
|||
USETW(req.wLength, AXE_CMD_LEN(cmd));
|
||||
|
||||
err = usbd_do_request(sc->axe_udev, &req, buf);
|
||||
axe_unlock_mii(sc);
|
||||
|
||||
if (err)
|
||||
return(-1);
|
||||
|
@ -319,7 +319,9 @@ axe_miibus_statchg(device_ptr_t dev)
|
|||
else
|
||||
val = 0;
|
||||
DPRINTF(("axe_miibus_statchg: val=0x%x\n", val));
|
||||
axe_lock_mii(sc);
|
||||
err = axe_cmd(sc, AXE_CMD_WRITE_MEDIA, 0, val, NULL);
|
||||
axe_unlock_mii(sc);
|
||||
if (err) {
|
||||
printf("%s: media change failed\n", USBDEVNAME(sc->axe_dev));
|
||||
return;
|
||||
|
@ -375,6 +377,7 @@ axe_setmulti(struct axe_softc *sc)
|
|||
|
||||
ifp = GET_IFP(sc);
|
||||
|
||||
axe_lock_mii(sc);
|
||||
axe_cmd(sc, AXE_CMD_RXCTL_READ, 0, 0, (void *)&rxmode);
|
||||
rxmode = le16toh(rxmode);
|
||||
|
||||
|
@ -405,6 +408,7 @@ axe_setmulti(struct axe_softc *sc)
|
|||
ifp->if_flags &= ~IFF_ALLMULTI;
|
||||
axe_cmd(sc, AXE_CMD_WRITE_MCAST, 0, 0, (void *)&hashtbl);
|
||||
axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL);
|
||||
axe_unlock_mii(sc);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -461,7 +465,7 @@ USB_ATTACH(axe)
|
|||
}
|
||||
|
||||
usb_init_task(&sc->axe_tick_task, axe_tick_task, sc);
|
||||
lockinit(&sc->axe_mii_lock, PZERO, "axemii", 0, LK_CANRECURSE);
|
||||
mutex_init(&sc->axe_mii_lock, MUTEX_DEFAULT, IPL_NONE);
|
||||
usb_init_task(&sc->axe_stop_task, (void (*)(void *))axe_stop, sc);
|
||||
|
||||
err = usbd_device2interface_handle(dev, AXE_IFACE_IDX, &sc->axe_iface);
|
||||
|
@ -506,6 +510,7 @@ USB_ATTACH(axe)
|
|||
/*
|
||||
* Get station address.
|
||||
*/
|
||||
axe_lock_mii(sc);
|
||||
axe_cmd(sc, AXE_CMD_READ_NODEID, 0, 0, &eaddr);
|
||||
|
||||
/*
|
||||
|
@ -513,6 +518,7 @@ USB_ATTACH(axe)
|
|||
*/
|
||||
axe_cmd(sc, AXE_CMD_READ_IPG012, 0, 0, (void *)&sc->axe_ipgs);
|
||||
axe_cmd(sc, AXE_CMD_READ_PHYID, 0, 0, (void *)&sc->axe_phyaddrs);
|
||||
axe_unlock_mii(sc);
|
||||
|
||||
/*
|
||||
* Work around broken adapters that appear to lie about
|
||||
|
@ -1113,6 +1119,7 @@ axe_init(void *xsc)
|
|||
}
|
||||
|
||||
/* Set transmitter IPG values */
|
||||
axe_lock_mii(sc);
|
||||
axe_cmd(sc, AXE_CMD_WRITE_IPG0, 0, sc->axe_ipgs[0], NULL);
|
||||
axe_cmd(sc, AXE_CMD_WRITE_IPG1, 0, sc->axe_ipgs[1], NULL);
|
||||
axe_cmd(sc, AXE_CMD_WRITE_IPG2, 0, sc->axe_ipgs[2], NULL);
|
||||
|
@ -1128,6 +1135,7 @@ axe_init(void *xsc)
|
|||
rxmode |= AXE_RXCMD_BROADCAST;
|
||||
|
||||
axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL);
|
||||
axe_unlock_mii(sc);
|
||||
|
||||
/* Load the multicast filter. */
|
||||
axe_setmulti(sc);
|
||||
|
@ -1211,21 +1219,25 @@ axe_ioctl(struct ifnet *ifp, u_long cmd, void *data)
|
|||
ifp->if_flags & IFF_PROMISC &&
|
||||
!(sc->axe_if_flags & IFF_PROMISC)) {
|
||||
|
||||
axe_lock_mii(sc);
|
||||
axe_cmd(sc, AXE_CMD_RXCTL_READ,
|
||||
0, 0, (void *)&rxmode);
|
||||
rxmode = le16toh(rxmode) | AXE_RXCMD_PROMISC;
|
||||
axe_cmd(sc, AXE_CMD_RXCTL_WRITE,
|
||||
0, rxmode, NULL);
|
||||
axe_unlock_mii(sc);
|
||||
|
||||
axe_setmulti(sc);
|
||||
} else if (ifp->if_flags & IFF_RUNNING &&
|
||||
!(ifp->if_flags & IFF_PROMISC) &&
|
||||
sc->axe_if_flags & IFF_PROMISC) {
|
||||
axe_lock_mii(sc);
|
||||
axe_cmd(sc, AXE_CMD_RXCTL_READ,
|
||||
0, 0, (void *)&rxmode);
|
||||
rxmode = le16toh(rxmode) & ~AXE_RXCMD_PROMISC;
|
||||
axe_cmd(sc, AXE_CMD_RXCTL_WRITE,
|
||||
0, rxmode, NULL);
|
||||
axe_unlock_mii(sc);
|
||||
axe_setmulti(sc);
|
||||
} else if (!(ifp->if_flags & IFF_RUNNING))
|
||||
axe_init(sc);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_axereg.h,v 1.3 2005/12/11 12:24:00 christos Exp $ */
|
||||
/* $NetBSD: if_axereg.h,v 1.4 2007/12/05 07:58:32 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 1999, 2000-2003
|
||||
|
@ -193,7 +193,7 @@ struct axe_softc {
|
|||
struct usb_task axe_tick_task;
|
||||
struct usb_task axe_stop_task;
|
||||
|
||||
struct lock axe_mii_lock;
|
||||
kmutex_t axe_mii_lock;
|
||||
|
||||
int axe_link;
|
||||
unsigned char axe_ipgs[3];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_tap.c,v 1.33 2007/09/10 10:35:54 cube Exp $ */
|
||||
/* $NetBSD: if_tap.c,v 1.34 2007/12/05 08:05:57 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 The NetBSD Foundation.
|
||||
|
@ -36,7 +36,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.33 2007/09/10 10:35:54 cube Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.34 2007/12/05 08:05:57 ad Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "bpfilter.h"
|
||||
|
@ -56,6 +56,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.33 2007/09/10 10:35:54 cube Exp $");
|
|||
#include <sys/sockio.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/kauth.h>
|
||||
#include <sys/mutex.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
|
@ -105,7 +106,7 @@ struct tap_softc {
|
|||
#define TAP_GOING 0x00000008 /* interface is being destroyed */
|
||||
struct selinfo sc_rsel;
|
||||
pid_t sc_pgid; /* For async. IO */
|
||||
struct lock sc_rdlock;
|
||||
kmutex_t sc_rdlock;
|
||||
struct simplelock sc_kqlock;
|
||||
};
|
||||
|
||||
|
@ -344,7 +345,7 @@ tap_attach(struct device *parent, struct device *self,
|
|||
* to be protected, too, but we don't need the same level of
|
||||
* complexity for that lock, so a simple spinning lock is fine.
|
||||
*/
|
||||
lockinit(&sc->sc_rdlock, PSOCK|PCATCH, "tapl", 0, LK_SLEEPFAIL);
|
||||
mutex_init(&sc->sc_rdlock, MUTEX_DEFAULT, IPL_NONE);
|
||||
simple_lock_init(&sc->sc_kqlock);
|
||||
}
|
||||
|
||||
|
@ -359,19 +360,11 @@ tap_detach(struct device* self, int flags)
|
|||
struct ifnet *ifp = &sc->sc_ec.ec_if;
|
||||
int error, s;
|
||||
|
||||
/*
|
||||
* Some processes might be sleeping on "tap", so we have to make
|
||||
* them release their hold on the device.
|
||||
*
|
||||
* The LK_DRAIN operation will wait for every locked process to
|
||||
* release their hold.
|
||||
*/
|
||||
sc->sc_flags |= TAP_GOING;
|
||||
s = splnet();
|
||||
tap_stop(ifp, 1);
|
||||
if_down(ifp);
|
||||
splx(s);
|
||||
lockmgr(&sc->sc_rdlock, LK_DRAIN, NULL);
|
||||
|
||||
/*
|
||||
* Destroying a single leaf is a very straightforward operation using
|
||||
|
@ -385,6 +378,7 @@ tap_detach(struct device* self, int flags)
|
|||
ether_ifdetach(ifp);
|
||||
if_detach(ifp);
|
||||
ifmedia_delete_instance(&sc->sc_im, IFM_INST_ANY);
|
||||
mutex_destroy(&sc->sc_rdlock);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
@ -837,12 +831,12 @@ tap_dev_read(int unit, struct uio *uio, int flags)
|
|||
/*
|
||||
* In the TAP_NBIO case, we have to make sure we won't be sleeping
|
||||
*/
|
||||
if ((sc->sc_flags & TAP_NBIO) &&
|
||||
lockstatus(&sc->sc_rdlock) == LK_EXCLUSIVE)
|
||||
return (EWOULDBLOCK);
|
||||
error = lockmgr(&sc->sc_rdlock, LK_EXCLUSIVE, NULL);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
if ((sc->sc_flags & TAP_NBIO) != 0) {
|
||||
if (!mutex_tryenter(&sc->sc_rdlock))
|
||||
return (EWOULDBLOCK);
|
||||
} else {
|
||||
mutex_enter(&sc->sc_rdlock);
|
||||
}
|
||||
|
||||
s = splnet();
|
||||
if (IFQ_IS_EMPTY(&ifp->if_snd)) {
|
||||
|
@ -852,23 +846,22 @@ tap_dev_read(int unit, struct uio *uio, int flags)
|
|||
* We must release the lock before sleeping, and re-acquire it
|
||||
* after.
|
||||
*/
|
||||
(void)lockmgr(&sc->sc_rdlock, LK_RELEASE, NULL);
|
||||
mutex_exit(&sc->sc_rdlock);
|
||||
if (sc->sc_flags & TAP_NBIO)
|
||||
error = EWOULDBLOCK;
|
||||
else
|
||||
error = tsleep(sc, PSOCK|PCATCH, "tap", 0);
|
||||
|
||||
if (error != 0)
|
||||
return (error);
|
||||
/* The device might have been downed */
|
||||
if ((ifp->if_flags & IFF_UP) == 0)
|
||||
return (EHOSTDOWN);
|
||||
if ((sc->sc_flags & TAP_NBIO) &&
|
||||
lockstatus(&sc->sc_rdlock) == LK_EXCLUSIVE)
|
||||
return (EWOULDBLOCK);
|
||||
error = lockmgr(&sc->sc_rdlock, LK_EXCLUSIVE, NULL);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
if ((sc->sc_flags & TAP_NBIO)) {
|
||||
if (!mutex_tryenter(&sc->sc_rdlock))
|
||||
return (EWOULDBLOCK);
|
||||
} else {
|
||||
mutex_enter(&sc->sc_rdlock);
|
||||
}
|
||||
s = splnet();
|
||||
}
|
||||
|
||||
|
@ -900,7 +893,7 @@ tap_dev_read(int unit, struct uio *uio, int flags)
|
|||
m_freem(m);
|
||||
|
||||
out:
|
||||
(void)lockmgr(&sc->sc_rdlock, LK_RELEASE, NULL);
|
||||
mutex_exit(&sc->sc_rdlock);
|
||||
return (error);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue