Revise lock name handling:

o construct a name for the com lock as done for other locks
o pass the device name to IEEE80211_LOCK_INIT so the mtx name
  is constructed as foo_com_lock
o introduce *_LOCK_OBJ macro's to hide the lock contents and
  minimize redundant code
This commit is contained in:
Sam Leffler 2008-05-28 23:10:53 +00:00
parent 4f30f2993f
commit 978359b3f6
3 changed files with 28 additions and 20 deletions

View File

@ -220,7 +220,7 @@ ieee80211_ifattach(struct ieee80211com *ic)
KASSERT(ifp->if_type == IFT_IEEE80211, ("if_type %d", ifp->if_type));
IEEE80211_LOCK_INIT(ic, "ieee80211com");
IEEE80211_LOCK_INIT(ic, ifp->if_xname);
TAILQ_INIT(&ic->ic_vaps);
/*
* Fill in 802.11 available channel set, mark all

View File

@ -36,15 +36,21 @@
/*
* Common state locking definitions.
*/
typedef struct mtx ieee80211_com_lock_t;
#define IEEE80211_LOCK_INIT(_ic, _name) \
mtx_init(&(_ic)->ic_comlock, _name, "802.11 com lock", \
MTX_DEF | MTX_RECURSE)
#define IEEE80211_LOCK_DESTROY(_ic) mtx_destroy(&(_ic)->ic_comlock)
#define IEEE80211_LOCK(_ic) mtx_lock(&(_ic)->ic_comlock)
#define IEEE80211_UNLOCK(_ic) mtx_unlock(&(_ic)->ic_comlock)
typedef struct {
char name[16]; /* e.g. "ath0_com_lock" */
struct mtx mtx;
} ieee80211_com_lock_t;
#define IEEE80211_LOCK_INIT(_ic, _name) do { \
ieee80211_com_lock_t *cl = &(_ic)->ic_comlock; \
snprintf(cl->name, sizeof(cl->name), "%s_com_lock", _name); \
mtx_init(&cl->mtx, cl->name, NULL, MTX_DEF | MTX_RECURSE); \
} while (0)
#define IEEE80211_LOCK_OBJ(_ic) (&(_ic)->ic_comlock.mtx)
#define IEEE80211_LOCK_DESTROY(_ic) mtx_destroy(IEEE80211_LOCK_OBJ(_ic))
#define IEEE80211_LOCK(_ic) mtx_lock(IEEE80211_LOCK_OBJ(_ic))
#define IEEE80211_UNLOCK(_ic) mtx_unlock(IEEE80211_LOCK_OBJ(_ic))
#define IEEE80211_LOCK_ASSERT(_ic) \
mtx_assert(&(_ic)->ic_comlock, MA_OWNED)
mtx_assert(IEEE80211_LOCK_OBJ(_ic), MA_OWNED)
/*
* Node locking definitions.
@ -56,18 +62,19 @@ typedef struct {
#define IEEE80211_NODE_LOCK_INIT(_nt, _name) do { \
ieee80211_node_lock_t *nl = &(_nt)->nt_nodelock; \
snprintf(nl->name, sizeof(nl->name), "%s_node_lock", _name); \
mtx_init(&nl->mtx, NULL, nl->name, MTX_DEF | MTX_RECURSE); \
mtx_init(&nl->mtx, nl->name, NULL, MTX_DEF | MTX_RECURSE); \
} while (0)
#define IEEE80211_NODE_LOCK_OBJ(_nt) (&(_nt)->nt_nodelock.mtx)
#define IEEE80211_NODE_LOCK_DESTROY(_nt) \
mtx_destroy(&(_nt)->nt_nodelock.mtx)
mtx_destroy(IEEE80211_NODE_LOCK_OBJ(_nt))
#define IEEE80211_NODE_LOCK(_nt) \
mtx_lock(&(_nt)->nt_nodelock.mtx)
mtx_lock(IEEE80211_NODE_LOCK_OBJ(_nt))
#define IEEE80211_NODE_IS_LOCKED(_nt) \
mtx_owned(&(_nt)->nt_nodelock.mtx)
mtx_owned(IEEE80211_NODE_LOCK_OBJ(_nt))
#define IEEE80211_NODE_UNLOCK(_nt) \
mtx_unlock(&(_nt)->nt_nodelock.mtx)
mtx_unlock(IEEE80211_NODE_LOCK_OBJ(_nt))
#define IEEE80211_NODE_LOCK_ASSERT(_nt) \
mtx_assert(&(_nt)->nt_nodelock.mtx, MA_OWNED)
mtx_assert(IEEE80211_NODE_LOCK_OBJ(_nt), MA_OWNED)
/*
* Node table iteration locking definitions; this protects the
@ -81,14 +88,15 @@ typedef struct {
#define IEEE80211_NODE_ITERATE_LOCK_INIT(_nt, _name) do { \
ieee80211_scan_lock_t *sl = &(_nt)->nt_scanlock; \
snprintf(sl->name, sizeof(sl->name), "%s_scan_lock", _name); \
mtx_init(&sl->mtx, NULL, sl->name, MTX_DEF); \
mtx_init(&sl->mtx, sl->name, NULL, MTX_DEF); \
} while (0)
#define IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt) (&(_nt)->nt_scanlock.mtx)
#define IEEE80211_NODE_ITERATE_LOCK_DESTROY(_nt) \
mtx_destroy(&(_nt)->nt_scanlock.mtx)
mtx_destroy(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt))
#define IEEE80211_NODE_ITERATE_LOCK(_nt) \
mtx_lock(&(_nt)->nt_scanlock.mtx)
mtx_lock(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt))
#define IEEE80211_NODE_ITERATE_UNLOCK(_nt) \
mtx_unlock(&(_nt)->nt_scanlock.mtx)
mtx_unlock(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt))
#define _AGEQ_ENQUEUE(_ifq, _m, _qlen, _age) do { \
(_m)->m_nextpkt = NULL; \

View File

@ -102,7 +102,7 @@ ieee80211_scan_attach(struct ieee80211com *ic)
ic->ic_scan = NULL;
return;
}
callout_init_mtx(&ss->ss_scan_timer, &ic->ic_comlock, 0);
callout_init_mtx(&ss->ss_scan_timer, IEEE80211_LOCK_OBJ(ic), 0);
ic->ic_scan = &ss->base;
ic->ic_scan_curchan = scan_curchan;