From owner-p4-projects@FreeBSD.ORG Tue Aug 25 21:46:33 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 1A8101065695; Tue, 25 Aug 2009 21:46:33 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BA8C0106568C for ; Tue, 25 Aug 2009 21:46:32 +0000 (UTC) (envelope-from zec@fer.hr) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id A999A8FC2D for ; Tue, 25 Aug 2009 21:46:32 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n7PLkWAi024792 for ; Tue, 25 Aug 2009 21:46:32 GMT (envelope-from zec@fer.hr) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n7PLkWqF024790 for perforce@freebsd.org; Tue, 25 Aug 2009 21:46:32 GMT (envelope-from zec@fer.hr) Date: Tue, 25 Aug 2009 21:46:32 GMT Message-Id: <200908252146.n7PLkWqF024790@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to zec@fer.hr using -f From: Marko Zec To: Perforce Change Reviews Cc: Subject: PERFORCE change 167819 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Aug 2009 21:46:33 -0000 http://perforce.freebsd.org/chv.cgi?CH=167819 Change 167819 by zec@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(); } /*