Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Replace simple_lock(9) with mutex(9), clean up.
details: https://anonhg.NetBSD.org/src/rev/45b0bb96fcc4
branches: trunk
changeset: 764959:45b0bb96fcc4
user: rmind <rmind%NetBSD.org@localhost>
date: Sat May 14 12:44:15 2011 +0000
description:
Replace simple_lock(9) with mutex(9), clean up.
diffstat:
sys/compat/ndis/kern_ndis.c | 273 +++---------------------------------
sys/compat/ndis/nbcompat.c | 18 +--
sys/compat/ndis/nbcompat.h | 10 +-
sys/compat/ndis/ndis_var.h | 6 +-
sys/compat/ndis/subr_ndis.c | 10 +-
sys/compat/ndis/subr_ntoskrnl.c | 291 +++------------------------------------
sys/dev/if_ndis/if_ndis.c | 10 +-
sys/dev/if_ndis/if_ndisvar.h | 14 +-
8 files changed, 81 insertions(+), 551 deletions(-)
diffs (truncated from 1403 to 300 lines):
diff -r 56507a73d9ba -r 45b0bb96fcc4 sys/compat/ndis/kern_ndis.c
--- a/sys/compat/ndis/kern_ndis.c Sat May 14 10:57:50 2011 +0000
+++ b/sys/compat/ndis/kern_ndis.c Sat May 14 12:44:15 2011 +0000
@@ -1,3 +1,5 @@
+/* $NetBSD: kern_ndis.c,v 1.22 2011/05/14 12:44:16 rmind Exp $ */
+
/*-
* Copyright (c) 2003
* Bill Paul <wpaul%windriver.com@localhost>. All rights reserved.
@@ -35,7 +37,7 @@
__FBSDID("$FreeBSD: src/sys/compat/ndis/kern_ndis.c,v 1.60.2.5 2005/04/01 17:14:20 wpaul Exp $");
#endif
#ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: kern_ndis.c,v 1.21 2009/05/11 21:31:29 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ndis.c,v 1.22 2011/05/14 12:44:16 rmind Exp $");
#endif
#include <sys/param.h>
@@ -50,9 +52,7 @@
#include <sys/proc.h>
#include <sys/malloc.h>
#include <sys/lock.h>
-#ifdef __FreeBSD__
#include <sys/mutex.h>
-#endif
#include <sys/conf.h>
#include <sys/kernel.h>
@@ -134,9 +134,6 @@
struct proc *np_p;
int np_state;
uint8_t np_stack[PAGE_SIZE*NDIS_KSTACK_PAGES];
-#ifdef __NetBSD__
- int np_needs_wakeup;
-#endif
};
static void ndis_return(void *);
@@ -152,9 +149,7 @@
#ifdef __FreeBSD__
static struct mtx ndis_thr_mtx;
#else /* __NetBSD__ */
-static struct simplelock ndis_thr_mtx;
-#define THR_LOCK() do {old_ipl = splnet(); simple_lock(&ndis_thr_mtx);} while(0)
-#define THR_UNLOCK() do {simple_unlock(&ndis_thr_mtx); splx(old_ipl);} while(0)
+static kmutex_t ndis_thr_mtx;
#endif
static struct mtx ndis_req_mtx;
@@ -338,44 +333,18 @@
{
struct ndis_req *r = NULL, *die = NULL;
struct ndisproc *p;
-#ifdef __NetBSD__
- int old_ipl;
-#endif
p = arg;
- while (1) {
+ for (;;) {
+ mtx_lock_spin(&ndis_thr_mtx);
+ ndis_thsuspend(p->np_p, &ndis_thr_mtx, 0);
- /* Protect against interrupts between checking if the queue is empty, and going to sleep
- * to avoid a wakeup before sleep.
- */
- old_ipl = splnet();
- /* Sleep, but preserve our original priority. */
- if(STAILQ_EMPTY(p->np_q)) {
- /* TODO: If we get an interrupt between checking if the queue is empty,
- * TODO: and sleeping, then in the interrupt, an item could be placed
- * TODO: on the queue, and we could be woken up before we sleep.
- *
- */
- ndis_thsuspend(p->np_p, NULL, 0);
- }
- splx(old_ipl);
-
-#ifdef __NetBSD__
- p->np_needs_wakeup = FALSE;
-#endif
-
/* Look for any jobs on the work queue. */
-#ifdef __FreeBSD__
- mtx_lock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_LOCK();
-#endif
-
p->np_state = NDIS_PSTATE_RUNNING;
- while(!STAILQ_EMPTY(p->np_q)/*STAILQ_FIRST(p->np_q) != NULL*/) {
+ while (!STAILQ_EMPTY(p->np_q)) {
r = STAILQ_FIRST(p->np_q);
- STAILQ_REMOVE_HEAD(p->np_q, link);
+ STAILQ_REMOVE_HEAD(p->np_q, link);
/* for debugging */
@@ -388,11 +357,8 @@
_ndis_swi_req = r;
r->area = 2;
}
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
+
/* Just for debugging */
if(p == &ndis_tproc) {
@@ -412,11 +378,7 @@
calling_in_swi = FALSE;
}
-#ifdef __FreeBSD__
mtx_lock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_LOCK();
-#endif
/* Zeroing out the ndis_req is just for debugging */
//memset(r, 0, sizeof(struct ndis_req));
@@ -428,11 +390,7 @@
}
p->np_state = NDIS_PSTATE_SLEEPING;
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
/* Bail if we were told to shut down. */
@@ -441,18 +399,9 @@
}
wakeup(die);
-#ifdef __FreeBSD__
-#if __FreeBSD_version < 502113
- mtx_lock(&Giant);
-#endif
-#endif
- if(p == &ndis_tproc) {
- printf("taskqueue thread exiting!\n");
- } else if(p == &ndis_iproc) {
- printf("swi thread exiting!\n");
- }
+
kthread_exit(0);
- return; /* notreached */
+ /* NOTREACHED */
}
/*static*/ int
@@ -466,9 +415,8 @@
#ifdef __FreeBSD__
mtx_init(&ndis_thr_mtx, "NDIS thread lock", NULL, MTX_SPIN);
#else /* __NetBSD__ */
- simple_lock_init(&ndis_thr_mtx);
- //lockinit(&ndis_thr_mtx, PWAIT, "NDIS thread lock", 0, 0);
-#endif
+ mutex_init(&ndis_thr_mtx, MUTEX_DEFAULT, IPL_NET);
+#endif
mtx_init(&ndis_req_mtx, "NDIS request lock", MTX_NDIS_LOCK, MTX_DEF);
STAILQ_INIT(&ndis_ttodo);
@@ -539,9 +487,7 @@
}
mtx_destroy(&ndis_req_mtx);
-#ifndef __NetBSD__
mtx_destroy(&ndis_thr_mtx);
-#endif
return;
}
@@ -552,9 +498,6 @@
struct ndis_req *r;
struct ndisqhead *q;
struct proc *p;
-#ifdef __NetBSD__
- int old_ipl;
-#endif
if (t == NDIS_TASKQUEUE) {
q = &ndis_ttodo;
@@ -566,11 +509,8 @@
/* Create and post a special 'exit' job. */
-#ifdef __FreeBSD__
mtx_lock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_LOCK();
-#endif
+
r = STAILQ_FIRST(&ndis_free);
STAILQ_REMOVE_HEAD(&ndis_free, link);
r->nr_func = NULL;
@@ -578,40 +518,20 @@
r->nr_exit = TRUE;
r->area = 3;
STAILQ_INSERT_TAIL(q, r, link);
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
ndis_thresume(p);
- /* wait for thread exit */
-
-#ifdef __FreeBSD__
- tsleep(r, curthread->td_priority|PCATCH, "ndisthexit", hz * 60);
-#else
- tsleep(r, curlwp->l_priority|PCATCH, "ndisthexit", hz * 60);
-#endif
+ /* Wait for thread exit */
+ tsleep(r, PZERO | PCATCH, "ndisthexit", hz * 60);
/* Now empty the job list. */
-#ifdef __FreeBSD__
mtx_lock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_LOCK();
-#endif
while ((r = STAILQ_FIRST(q)) != NULL) {
STAILQ_REMOVE_HEAD(q, link);
STAILQ_INSERT_HEAD(&ndis_free, r, link);
}
-
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
-
- return;
}
static int
@@ -619,26 +539,16 @@
{
struct ndis_req *r;
int i;
-#ifdef __NetBSD__
- int old_ipl;
-#endif
for (i = 0; i < cnt; i++) {
r = malloc(sizeof(struct ndis_req), M_DEVBUF, M_WAITOK);
if (r == NULL)
return(ENOMEM);
-#ifdef __FreeBSD__
+
mtx_lock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_LOCK();
-#endif
STAILQ_INSERT_HEAD(&ndis_free, r, link);
ndis_jobs++;
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
}
return(0);
@@ -649,33 +559,17 @@
{
struct ndis_req *r;
int i;
-#ifdef __NetBSD__
- int old_ipl;
-#endif
for (i = 0; i < cnt; i++) {
-#ifdef __FreeBSD__
mtx_lock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_LOCK();
-#endif
r = STAILQ_FIRST(&ndis_free);
if (r == NULL) {
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
return(ENOMEM);
}
STAILQ_REMOVE_HEAD(&ndis_free, link);
ndis_jobs--;
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
Home |
Main Index |
Thread Index |
Old Index