From owner-p4-projects@FreeBSD.ORG Tue Jul 4 13:56:59 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 98D5216A4DF; Tue, 4 Jul 2006 13:56:59 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 13D1416A4DD for ; Tue, 4 Jul 2006 13:56:59 +0000 (UTC) (envelope-from piso@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id CF62843D49 for ; Tue, 4 Jul 2006 13:56:58 +0000 (GMT) (envelope-from piso@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k64Duw5t047874 for ; Tue, 4 Jul 2006 13:56:58 GMT (envelope-from piso@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k64DuwF5047871 for perforce@freebsd.org; Tue, 4 Jul 2006 13:56:58 GMT (envelope-from piso@freebsd.org) Date: Tue, 4 Jul 2006 13:56:58 GMT Message-Id: <200607041356.k64DuwF5047871@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to piso@freebsd.org using -f From: Paolo Pisati To: Perforce Change Reviews Cc: Subject: PERFORCE change 100560 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, 04 Jul 2006 13:56:59 -0000 http://perforce.freebsd.org/chv.cgi?CH=100560 Change 100560 by piso@piso_newluxor on 2006/07/04 13:56:03 Use rwlock(9) instead of my own read-write lock. Affected files ... .. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.c#8 edit .. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.h#7 edit Differences ... ==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.c#8 (text+ko) ==== @@ -28,6 +28,8 @@ #ifdef _KERNEL #include #include +#include +#include #include #else #include @@ -63,61 +65,47 @@ #ifdef _KERNEL #define LIBALIAS_LOCK_INIT(_chain) \ - mtx_init(&(_chain)->mtx, "libalias list of proto-handlers", NULL, \ - MTX_DEF | MTX_RECURSE) -#define LIBALIAS_LOCK_DESTROY(_chain) mtx_destroy(&(_chain)->mtx) -#define LIBALIAS_WLOCK_ASSERT(_chain) do { \ - mtx_assert(&(_chain)->mtx, MA_OWNED); \ - NET_ASSERT_GIANT(); \ -} while (0) + rw_init(&_chain->rw, "Libalias_rwlock") +#define LIBALIAS_LOCK_DESTROY(_chain) rw_destroy(&_chain->rw) +#define LIBALIAS_WLOCK_ASSERT(_chain) \ + rw_assert(&_chain->rw, RA_WLOCKED) static __inline void LIBALIAS_RLOCK(struct chain *chain) { - mtx_lock(&chain->mtx); - chain->busy_count++; - mtx_unlock(&chain->mtx); + rw_rlock(&chain->rw); } static __inline void LIBALIAS_RUNLOCK(struct 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); + rw_runlock(&chain->rw); } static __inline void LIBALIAS_WLOCK(struct chain *chain) { - mtx_lock(&chain->mtx); - chain->want_write++; - while (chain->busy_count > 0) - cv_wait(&chain->cv, &chain->mtx); + rw_wlock(&chain->rw); } static __inline void LIBALIAS_WUNLOCK(struct chain *chain) { - chain->want_write--; - cv_signal(&chain->cv); - mtx_unlock(&chain->mtx); + rw_wunlock(&chain->rw); } static void -_handler_chain_init(struct chain *c) { +_handler_chain_init(struct chain *chain) { - if (!mtx_initialized(&c->mtx)) - LIBALIAS_LOCK_INIT(c); + if (!rw_initialized(&chain->rw)) + LIBALIAS_LOCK_INIT(chain); } static void -_handler_chain_destroy(struct chain *c) { +_handler_chain_destroy(struct chain *chain) { - if (mtx_initialized(&c->mtx)) - LIBALIAS_LOCK_DESTROY(c); + if (rw_initialized(&chain->rw)) + LIBALIAS_LOCK_DESTROY(chain); } #else ==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.h#7 (text+ko) ==== @@ -32,6 +32,10 @@ #ifndef _ALIAS_MOD_H_ #define _ALIAS_MOD_H_ +#include +#include +#include + /* Protocol handlers struct & function. */ /* Packet flow direction. */ @@ -76,13 +80,10 @@ }; #ifdef _KERNEL -// XXX - convert it to use queue(3) and rwlock(9) +// XXX - convert it to use queue(3) struct chain { void *chain; - struct mtx mtx; /* Lock guarding list. */ - int busy_count; /* Busy count for rw locks. */ - int want_write; - struct cv cv; + struct rwlock rw; }; #else // XXX - convert it to use queue(3)