Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 Aug 2006 10:37:09 GMT
From:      Paolo Pisati <piso@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 105319 for review
Message-ID:  <200608301037.k7UAb937056603@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=105319

Change 105319 by piso@piso_newluxor on 2006/08/30 10:36:21

	Replace nat hand-rolled rwlock with a standard rwlock.

Affected files ...

.. //depot/projects/soc2005/libalias/sys/netinet/ip_fw2.c#7 edit

Differences ...

==== //depot/projects/soc2005/libalias/sys/netinet/ip_fw2.c#7 (text+ko) ====

@@ -302,62 +302,27 @@
 MODULE_DEPEND(ipfw, libalias, 1, 1, 1);
 
 struct _nat_chain {
-	struct cfg_nat *chain;	
-	struct mtx	mtx;		/* lock guarding rule list */
-	int		busy_count;	/* busy count for rw locks */
-	int		want_write;
-	struct cv	cv;
+	struct cfg_nat  *chain;	
+	struct rwlock   rwl; 
 } nat_chain;
 
 #define	NAT_LOCK_INIT(_chain) \
-	mtx_init(&(_chain)->mtx, "NAT instances", NULL, \
-		MTX_DEF | MTX_RECURSE)
-#define	NAT_LOCK_DESTROY(_chain)	mtx_destroy(&(_chain)->mtx)
+	rw_init(&(_chain)->rwl, "NAT instances")
+#define	NAT_LOCK_DESTROY(_chain)	rw_destroy(&(_chain)->rwl)
 #define	NAT_WLOCK_ASSERT(_chain)	do {				\
-	mtx_assert(&(_chain)->mtx, MA_OWNED);				\
+	rw_assert(&(_chain)->rwl, RA_WLOCKED);					\
 	NET_ASSERT_GIANT();						\
 } while (0)
 
-static __inline void
-NAT_RLOCK(struct _nat_chain *chain)
-{
-	mtx_lock(&chain->mtx);
-	chain->busy_count++;
-	mtx_unlock(&chain->mtx);
-}
+#define NAT_RLOCK(p) rw_rlock(&(p)->rwl)
+#define NAT_RUNLOCK(p) rw_runlock(&(p)->rwl)
+#define NAT_WLOCK(p) rw_wlock(&(p)->rwl)
+#define NAT_WUNLOCK(p) rw_wunlock(&(p)->rwl)
 
-static __inline void
-NAT_RUNLOCK(struct _nat_chain *chain)
-{
-	mtx_lock(&chain->mtx);
-	chain->busy_count--;
-	if (chain->busy_count == 0 && chain->want_write)
-		cv_signal(&chain->cv);
-	mtx_unlock(&chain->mtx);
-}
-
-static __inline void
-NAT_WLOCK(struct _nat_chain *chain)
-{
-	mtx_lock(&chain->mtx);
-	chain->want_write++;
-	while (chain->busy_count > 0)
-		cv_wait(&chain->cv, &chain->mtx);
-}
-
-static __inline void
-NAT_WUNLOCK(struct _nat_chain *chain)
-{
-	chain->want_write--;
-	cv_signal(&chain->cv);
-	mtx_unlock(&chain->mtx);
-}
-
 static eventhandler_tag ifaddr_event_tag;
 
 static int fw_deny_unknown_exthdrs = 1;
 
-
 /*
  * L3HDR maps an ipv4 pointer into a layer3 header pointer of type T
  * Other macros just cast void * into the appropriate type
@@ -4925,8 +4890,6 @@
 	ip_fw_chk_ptr = ipfw_chk;
 	callout_reset(&ipfw_timeout, hz, ipfw_tick, NULL);	
 	nat_chain.chain = NULL;
-	nat_chain.busy_count = 0;
-	nat_chain.want_write = 0;
 	NAT_LOCK_INIT(&nat_chain);
 	ifaddr_event_tag = EVENTHANDLER_REGISTER(ifaddr_event, ifaddr_change, 
 					 NULL, EVENTHANDLER_PRI_ANY);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200608301037.k7UAb937056603>