PERFORCE change 167819 for review
Marko Zec
zec at FreeBSD.org
Tue Aug 25 21:46:33 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=167819
Change 167819 by zec at zec_tpx32 on 2009/08/25 21:45:44
Wrap vnet_sysinit lock / unlock calls in macros, so that
the actual mechanism can be changed in the future without
introducing much churn in the code.
Suggested by: rwatson
Affected files ...
.. //depot/projects/vimage-commit2/src/sys/net/vnet.c#5 edit
Differences ...
==== //depot/projects/vimage-commit2/src/sys/net/vnet.c#5 (text+ko) ====
@@ -94,7 +94,7 @@
} while (0)
struct vnet_list_head vnet_head;
-struct vnet *vnet0;
+struct vnet *vnet0 = NULL;
/*
* The virtual network stack allocator provides storage for virtualized
@@ -185,12 +185,18 @@
* registered via VNET_SYSINIT() and VNET_SYSUNINIT(). Both lists are
* protected by the vnet_sysinit_sxlock global lock.
*/
-struct sx vnet_sysinit_sxlock;
static TAILQ_HEAD(vnet_sysinit_head, vnet_sysinit) vnet_constructors =
TAILQ_HEAD_INITIALIZER(vnet_constructors);
static TAILQ_HEAD(vnet_sysuninit_head, vnet_sysinit) vnet_destructors =
TAILQ_HEAD_INITIALIZER(vnet_destructors);
+struct sx vnet_sysinit_sxlock;
+
+#define VNET_SYSINIT_WLOCK() sx_xlock(&vnet_sysinit_sxlock);
+#define VNET_SYSINIT_WUNLOCK() sx_xunlock(&vnet_sysinit_sxlock);
+#define VNET_SYSINIT_RLOCK() sx_slock(&vnet_sysinit_sxlock);
+#define VNET_SYSINIT_RUNLOCK() sx_sunlock(&vnet_sysinit_sxlock);
+
struct vnet_data_free {
uintptr_t vnd_start;
int vnd_len;
@@ -229,9 +235,9 @@
/* Initialize / attach vnet module instances. */
CURVNET_SET_QUIET(vnet);
- sx_slock(&vnet_sysinit_sxlock);
+ VNET_SYSINIT_RLOCK();
vnet_sysinit();
- sx_sunlock(&vnet_sysinit_sxlock);
+ VNET_SYSINIT_RUNLOCK();
CURVNET_RESTORE();
VNET_LIST_WLOCK();
@@ -264,9 +270,9 @@
if_vmove(ifp, ifp->if_home_vnet);
}
- sx_slock(&vnet_sysinit_sxlock);
+ VNET_SYSINIT_RLOCK();
vnet_sysuninit();
- sx_sunlock(&vnet_sysinit_sxlock);
+ VNET_SYSINIT_RUNLOCK();
CURVNET_RESTORE();
/*
@@ -496,7 +502,7 @@
KASSERT(vs->subsystem > SI_SUB_VNET, ("vnet sysinit too early"));
/* Add the constructor to the global list of vnet constructors. */
- sx_xlock(&vnet_sysinit_sxlock);
+ VNET_SYSINIT_WLOCK();
TAILQ_FOREACH(vs2, &vnet_constructors, link) {
if (vs2->subsystem > vs->subsystem)
break;
@@ -517,7 +523,7 @@
vs->func(vs->arg);
CURVNET_RESTORE();
}
- sx_xunlock(&vnet_sysinit_sxlock);
+ VNET_SYSINIT_WUNLOCK();
}
void
@@ -528,9 +534,9 @@
vs = arg;
/* Remove the constructor from the global list of vnet constructors. */
- sx_xlock(&vnet_sysinit_sxlock);
+ VNET_SYSINIT_WLOCK();
TAILQ_REMOVE(&vnet_constructors, vs, link);
- sx_xunlock(&vnet_sysinit_sxlock);
+ VNET_SYSINIT_WUNLOCK();
}
void
@@ -541,7 +547,7 @@
vs = arg;
/* Add the destructor to the global list of vnet destructors. */
- sx_xlock(&vnet_sysinit_sxlock);
+ VNET_SYSINIT_WLOCK();
TAILQ_FOREACH(vs2, &vnet_destructors, link) {
if (vs2->subsystem > vs->subsystem)
break;
@@ -552,7 +558,7 @@
TAILQ_INSERT_BEFORE(vs2, vs, link);
else
TAILQ_INSERT_TAIL(&vnet_destructors, vs, link);
- sx_xunlock(&vnet_sysinit_sxlock);
+ VNET_SYSINIT_WUNLOCK();
}
void
@@ -567,7 +573,7 @@
* Invoke the destructor on all the existing vnets when it is
* deregistered.
*/
- sx_xlock(&vnet_sysinit_sxlock);
+ VNET_SYSINIT_WLOCK();
VNET_FOREACH(vnet) {
CURVNET_SET_QUIET(vnet);
vs->func(vs->arg);
@@ -576,7 +582,7 @@
/* Remove the destructor from the global list of vnet destructors. */
TAILQ_REMOVE(&vnet_destructors, vs, link);
- sx_xunlock(&vnet_sysinit_sxlock);
+ VNET_SYSINIT_WUNLOCK();
}
/*
More information about the p4-projects
mailing list