From owner-p4-projects@FreeBSD.ORG Fri Oct 5 11:57:00 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E949D16A543; Fri, 5 Oct 2007 11:56:59 +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 9ECA316A418 for ; Fri, 5 Oct 2007 11:56:59 +0000 (UTC) (envelope-from fli@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 82DAC13C45B for ; Fri, 5 Oct 2007 11:56:59 +0000 (UTC) (envelope-from fli@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l95Bux8g093085 for ; Fri, 5 Oct 2007 11:56:59 GMT (envelope-from fli@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l95BuxHE093082 for perforce@freebsd.org; Fri, 5 Oct 2007 11:56:59 GMT (envelope-from fli@FreeBSD.org) Date: Fri, 5 Oct 2007 11:56:59 GMT Message-Id: <200710051156.l95BuxHE093082@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to fli@FreeBSD.org using -f From: Fredrik Lindberg To: Perforce Change Reviews Cc: Subject: PERFORCE change 127223 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: Fri, 05 Oct 2007 11:57:00 -0000 http://perforce.freebsd.org/chv.cgi?CH=127223 Change 127223 by fli@fli_genesis on 2007/10/05 11:56:26 - Add obj_clean() that garbage collects old objects. - Add obj_destroy() to free objects on shutdown. - Don't call obj_flush() in obj_free(), obj_clean does that now. - Minor whitespace fixes. Affected files ... .. //depot/projects/soc2007/fli-mdns_sd/mdnsd/objalloc.c#3 edit .. //depot/projects/soc2007/fli-mdns_sd/mdnsd/objalloc.h#3 edit Differences ... ==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/objalloc.c#3 (text+ko) ==== @@ -78,7 +78,7 @@ { .os_sz = sizeof(struct cs_client) }, /* Query consumer */ { .os_sz = sizeof(struct query_cons) }, - /* Query type */ + /* Query type */ { .os_sz = sizeof(struct query_type) }, /* Outstanding UNIX pipe client query */ { .os_sz = sizeof(struct csc_query) } @@ -131,6 +131,51 @@ } /* + * Destroy and free object types + */ +void +obj_destroy() +{ + struct objs *os; + struct obj *o, *o2; + int i; + + for (i = 0; i < obj_table_size; i++) { + os = &obj_table[i]; + MDNS_INIT_ASSERT(os, os_magic); + MTX_LOCK(os, os_mtx); + TAILQ_FOREACH_SAFE(o, &os->os_free, o_next, o2) { + TAILQ_REMOVE(&os->os_free, o, o_next); + free(o); + } + + MDNS_INIT_UNSET(os, os_magic); + MTX_UNLOCK(os, os_mtx); + MTX_DESTROY(os, os_mtx); + } + dprintf(DEBUG_OA, "Object allocator destroyed"); +} + +/* + * Garbage collect old objects + */ +void +obj_clean() +{ + int i; + struct objs *os; + + dprintf(DEBUG_OA, "Garbage collecting objects"); + for (i = 0; i < obj_table_size; i++) { + os = &obj_table[i]; + MDNS_INIT_ASSERT(os, os_magic); + MTX_LOCK(os, os_mtx); + obj_flush(i); + MTX_UNLOCK(os, os_mtx); + } +} + +/* * Allocate an object of `type' */ void * @@ -185,6 +230,5 @@ MTX_LOCK(os, os_mtx); TAILQ_INSERT_HEAD(&os->os_free, o, o_next); dprintf(DEBUG_OA, "Released object type=%d o=%x", type, o); - obj_flush(type); MTX_UNLOCK(os, os_mtx); } ==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/objalloc.h#3 (text+ko) ==== @@ -27,8 +27,8 @@ #ifndef _OBJALLOC_H_ #define _OBJALLOC_H_ -#define OBJ_PKGCHAIN 0 /* struct mdns_pkgchain {} */ -#define OBJ_PKG 1 /* struct mdns_packet {} */ +#define OBJ_PKGCHAIN 0 /* struct mdns_pkgchain {} */ +#define OBJ_PKG 1 /* struct mdns_packet {} */ #define OBJ_PKGRES 2 /* struct mdns_pkg_res {} */ #define OBJ_PAC 3 /* struct dbr_pac {} */ #define OBJ_OQE 4 /* struct oq_entry {} */ @@ -39,6 +39,8 @@ #define _OBJ_MAX 8 void obj_init(void); +void obj_destroy(void); +void obj_clean(void); void * obj_alloc(int); void obj_free(int, void *);