summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorsam <sam@FreeBSD.org>2003-10-17 21:41:52 +0000
committersam <sam@FreeBSD.org>2003-10-17 21:41:52 +0000
commit365e4629edf786bcc796bf7f5ca4bd137bd5056f (patch)
tree8aa23f5524cace34ff5c78a678f7cd8e58c7f011 /sys
parent1869c3be82cfa3adc867643c5d5d4620a4d3a9d6 (diff)
downloadFreeBSD-src-365e4629edf786bcc796bf7f5ca4bd137bd5056f.zip
FreeBSD-src-365e4629edf786bcc796bf7f5ca4bd137bd5056f.tar.gz
parameterize locking to improve portability and possible
change to different locking strategies
Diffstat (limited to 'sys')
-rw-r--r--sys/net80211/ieee80211_node.c34
-rw-r--r--sys/net80211/ieee80211_node.h8
-rw-r--r--sys/net80211/ieee80211_proto.c8
3 files changed, 29 insertions, 21 deletions
diff --git a/sys/net80211/ieee80211_node.c b/sys/net80211/ieee80211_node.c
index 966f812..eae29e9 100644
--- a/sys/net80211/ieee80211_node.c
+++ b/sys/net80211/ieee80211_node.c
@@ -86,7 +86,7 @@ ieee80211_node_attach(struct ifnet *ifp)
struct ieee80211com *ic = (void *)ifp;
/* XXX need unit */
- mtx_init(&ic->ic_nodelock, ifp->if_name, "802.11 node table", MTX_DEF);
+ IEEE80211_NODE_LOCK_INIT(ic, ifp->if_name);
TAILQ_INIT(&ic->ic_node);
ic->ic_node_alloc = ieee80211_node_alloc;
ic->ic_node_free = ieee80211_node_free;
@@ -113,7 +113,7 @@ ieee80211_node_detach(struct ifnet *ifp)
if (ic->ic_bss != NULL)
(*ic->ic_node_free)(ic, ic->ic_bss);
ieee80211_free_allnodes(ic);
- mtx_destroy(&ic->ic_nodelock);
+ IEEE80211_NODE_LOCK_DESTROY(ic);
}
/*
@@ -428,7 +428,7 @@ ieee80211_setup_node(struct ieee80211com *ic,
IEEE80211_ADDR_COPY(ni->ni_macaddr, macaddr);
hash = IEEE80211_NODE_HASH(macaddr);
ni->ni_refcnt = 1; /* mark referenced */
- mtx_lock(&ic->ic_nodelock);
+ IEEE80211_NODE_LOCK(ic);
TAILQ_INSERT_TAIL(&ic->ic_node, ni, ni_list);
LIST_INSERT_HEAD(&ic->ic_hash[hash], ni, ni_hash);
/*
@@ -442,7 +442,7 @@ ieee80211_setup_node(struct ieee80211com *ic,
*/
if (ic->ic_opmode != IEEE80211_M_STA)
ic->ic_inact_timer = IEEE80211_INACT_WAIT;
- mtx_unlock(&ic->ic_nodelock);
+ IEEE80211_NODE_UNLOCK(ic);
}
struct ieee80211_node *
@@ -472,14 +472,14 @@ ieee80211_find_node(struct ieee80211com *ic, u_int8_t *macaddr)
int hash;
hash = IEEE80211_NODE_HASH(macaddr);
- mtx_lock(&ic->ic_nodelock);
+ IEEE80211_NODE_LOCK(ic);
LIST_FOREACH(ni, &ic->ic_hash[hash], ni_hash) {
if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr)) {
atomic_add_int(&ni->ni_refcnt, 1); /* mark referenced */
break;
}
}
- mtx_unlock(&ic->ic_nodelock);
+ IEEE80211_NODE_UNLOCK(ic);
return ni;
}
@@ -494,14 +494,14 @@ ieee80211_lookup_node(struct ieee80211com *ic,
int hash;
hash = IEEE80211_NODE_HASH(macaddr);
- mtx_lock(&ic->ic_nodelock);
+ IEEE80211_NODE_LOCK(ic);
LIST_FOREACH(ni, &ic->ic_hash[hash], ni_hash) {
if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr) && ni->ni_chan == chan) {
atomic_add_int(&ni->ni_refcnt, 1);/* mark referenced */
break;
}
}
- mtx_unlock(&ic->ic_nodelock);
+ IEEE80211_NODE_UNLOCK(ic);
return ni;
}
@@ -525,9 +525,9 @@ ieee80211_free_node(struct ieee80211com *ic, struct ieee80211_node *ni)
/* XXX need equivalent of atomic_dec_and_test */
atomic_subtract_int(&ni->ni_refcnt, 1);
if (atomic_cmpset_int(&ni->ni_refcnt, 0, 1)) {
- mtx_lock(&ic->ic_nodelock);
+ IEEE80211_NODE_LOCK(ic);
_ieee80211_free_node(ic, ni);
- mtx_unlock(&ic->ic_nodelock);
+ IEEE80211_NODE_UNLOCK(ic);
}
}
@@ -536,10 +536,10 @@ ieee80211_free_allnodes(struct ieee80211com *ic)
{
struct ieee80211_node *ni;
- mtx_lock(&ic->ic_nodelock);
+ IEEE80211_NODE_LOCK(ic);
while ((ni = TAILQ_FIRST(&ic->ic_node)) != NULL)
_ieee80211_free_node(ic, ni);
- mtx_unlock(&ic->ic_nodelock);
+ IEEE80211_NODE_UNLOCK(ic);
}
/*
@@ -558,7 +558,7 @@ ieee80211_timeout_nodes(struct ieee80211com *ic)
u_int gen = ic->ic_scangen++; /* NB: ok 'cuz single-threaded*/
restart:
- mtx_lock(&ic->ic_nodelock);
+ IEEE80211_NODE_LOCK(ic);
TAILQ_FOREACH(ni, &ic->ic_node, ni_list) {
if (ni->ni_scangen == gen) /* previously handled */
continue;
@@ -576,7 +576,7 @@ restart:
* a lock, as this will result in a LOR between the
* node lock and the driver lock.
*/
- mtx_unlock(&ic->ic_nodelock);
+ IEEE80211_NODE_UNLOCK(ic);
IEEE80211_SEND_MGMT(ic, ni,
IEEE80211_FC0_SUBTYPE_DEAUTH,
IEEE80211_REASON_AUTH_EXPIRE);
@@ -586,7 +586,7 @@ restart:
}
if (!TAILQ_EMPTY(&ic->ic_node))
ic->ic_inact_timer = IEEE80211_INACT_WAIT;
- mtx_unlock(&ic->ic_nodelock);
+ IEEE80211_NODE_UNLOCK(ic);
}
void
@@ -594,8 +594,8 @@ ieee80211_iterate_nodes(struct ieee80211com *ic, ieee80211_iter_func *f, void *a
{
struct ieee80211_node *ni;
- mtx_lock(&ic->ic_nodelock);
+ IEEE80211_NODE_LOCK(ic);
TAILQ_FOREACH(ni, &ic->ic_node, ni_list)
(*f)(arg, ni);
- mtx_unlock(&ic->ic_nodelock);
+ IEEE80211_NODE_UNLOCK(ic);
}
diff --git a/sys/net80211/ieee80211_node.h b/sys/net80211/ieee80211_node.h
index d61ff7b..b0e0437 100644
--- a/sys/net80211/ieee80211_node.h
+++ b/sys/net80211/ieee80211_node.h
@@ -118,6 +118,14 @@ ieee80211_unref_node(struct ieee80211_node **ni)
*ni = NULL; /* guard against use */
}
+#define IEEE80211_NODE_LOCK_INIT(_ic, _name) \
+ mtx_init(&(_ic)->ic_nodelock, _name, "802.11 node table", MTX_DEF)
+#define IEEE80211_NODE_LOCK_DESTROY(_ic) mtx_destroy(&(_ic)->ic_nodelock)
+#define IEEE80211_NODE_LOCK(_ic) mtx_lock(&(_ic)->ic_nodelock)
+#define IEEE80211_NODE_UNLOCK(_ic) mtx_unlock(&(_ic)->ic_nodelock)
+#define IEEE80211_NODE_LOCK_ASSERT(_ic) \
+ mtx_assert(&(_ic)->ic_nodelock, MA_OWNED)
+
struct ieee80211com;
extern void ieee80211_node_attach(struct ifnet *);
diff --git a/sys/net80211/ieee80211_proto.c b/sys/net80211/ieee80211_proto.c
index 047d29c..143f135 100644
--- a/sys/net80211/ieee80211_proto.c
+++ b/sys/net80211/ieee80211_proto.c
@@ -321,7 +321,7 @@ ieee80211_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int mgt
IEEE80211_REASON_ASSOC_LEAVE);
break;
case IEEE80211_M_HOSTAP:
- mtx_lock(&ic->ic_nodelock);
+ IEEE80211_NODE_LOCK(ic);
TAILQ_FOREACH(ni, &ic->ic_node, ni_list) {
if (ni->ni_associd == 0)
continue;
@@ -329,7 +329,7 @@ ieee80211_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int mgt
IEEE80211_FC0_SUBTYPE_DISASSOC,
IEEE80211_REASON_ASSOC_LEAVE);
}
- mtx_unlock(&ic->ic_nodelock);
+ IEEE80211_NODE_UNLOCK(ic);
break;
default:
break;
@@ -343,13 +343,13 @@ ieee80211_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int mgt
IEEE80211_REASON_AUTH_LEAVE);
break;
case IEEE80211_M_HOSTAP:
- mtx_lock(&ic->ic_nodelock);
+ IEEE80211_NODE_LOCK(ic);
TAILQ_FOREACH(ni, &ic->ic_node, ni_list) {
IEEE80211_SEND_MGMT(ic, ni,
IEEE80211_FC0_SUBTYPE_DEAUTH,
IEEE80211_REASON_AUTH_LEAVE);
}
- mtx_unlock(&ic->ic_nodelock);
+ IEEE80211_NODE_UNLOCK(ic);
break;
default:
break;
OpenPOWER on IntegriCloud