From owner-p4-projects@FreeBSD.ORG Wed May 9 16:13:52 2007 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 D561216A406; Wed, 9 May 2007 16:13:51 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 960E516A402 for ; Wed, 9 May 2007 16:13:51 +0000 (UTC) (envelope-from fli@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 8461513C44C for ; Wed, 9 May 2007 16:13:51 +0000 (UTC) (envelope-from fli@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.8/8.13.8) with ESMTP id l49GDpWs099561 for ; Wed, 9 May 2007 16:13:51 GMT (envelope-from fli@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l49GDpPj099558 for perforce@freebsd.org; Wed, 9 May 2007 16:13:51 GMT (envelope-from fli@FreeBSD.org) Date: Wed, 9 May 2007 16:13:51 GMT Message-Id: <200705091613.l49GDpPj099558@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 119564 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: Wed, 09 May 2007 16:13:52 -0000 http://perforce.freebsd.org/chv.cgi?CH=119564 Change 119564 by fli@fli_genesis on 2007/05/09 16:13:23 Nuke my own-rolled list and replace with sys/queue.h Affected files ... .. //depot/projects/soc2007/fli-mdns_sd/mdnsd/hash.c#2 edit .. //depot/projects/soc2007/fli-mdns_sd/mdnsd/hash.h#2 edit .. //depot/projects/soc2007/fli-mdns_sd/mdnsd/list.h#2 delete .. //depot/projects/soc2007/fli-mdns_sd/mdnsd/mdns.h#2 edit .. //depot/projects/soc2007/fli-mdns_sd/mdnsd/stack_buf.c#2 edit .. //depot/projects/soc2007/fli-mdns_sd/mdnsd/stack_buf.h#2 edit .. //depot/projects/soc2007/fli-mdns_sd/mdnsd/stack_mdns.c#2 edit .. //depot/projects/soc2007/fli-mdns_sd/mdnsd/stack_packet.c#2 edit Differences ... ==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/hash.c#2 (text+ko) ==== @@ -239,7 +239,7 @@ chunk = malloc(sizeof(struct hashentry) * entries); for (i = 0; i < entries; i++) { - list_insert_tail(ht->ht_free, &chunk[i], he_next); + TAILQ_INSERT_TAIL(&ht->ht_free, &chunk[i], he_next); } ht->ht_chunk[ht->ht_chunks++] = chunk; @@ -253,15 +253,20 @@ int hashtbl_init(struct hashtbl *ht, size_t len) { + size_t i; bzero(ht, sizeof(struct hashtbl)); ht->ht_table = malloc(sizeof(*ht->ht_table) * len); - bzero(ht->ht_table, sizeof(*ht->ht_table) * len); ht->ht_tblsz = len; ht->ht_mask = len - 1; ht->ht_entries = 0; + + for (i = 0; i < len; i++) { + TAILQ_INIT(&ht->ht_table[i]); + } + TAILQ_INIT(&ht->ht_free); + pre_alloc(ht); - return (0); } @@ -275,7 +280,7 @@ size_t i; for (i = 0; i < ht->ht_tblsz; i++) { - list_foreach(ht->ht_table[i], he, he_next) { + TAILQ_FOREACH(he, &ht->ht_table[i], he_next) { free(he->he_key); } } @@ -298,7 +303,7 @@ { struct hashentry *he; - list_foreach(ht->ht_table[hval], he, he_next) { + TAILQ_FOREACH(he, &ht->ht_table[hval], he_next) { if (keylen == he->he_keylen) { if (memcmp(key, he->he_key, keylen) == 0) break; @@ -329,18 +334,18 @@ if (he != NULL) return (-1); - if (list_empty(ht->ht_free)) { + if (TAILQ_EMPTY(&ht->ht_free)) { pre_alloc(ht); } - he = list_first(ht->ht_free); - list_remove_head(ht->ht_free, he_next); + he = TAILQ_FIRST(&ht->ht_free); + TAILQ_REMOVE(&ht->ht_free, he, he_next); he->he_key = malloc(keylen); memcpy(he->he_key, key, keylen); he->he_keylen = keylen; he->he_data = data; - list_insert_tail(ht->ht_table[hval], he, he_next); + TAILQ_INSERT_TAIL(&ht->ht_table[hval], he, he_next); return (0); } @@ -366,9 +371,9 @@ if (he != NULL) { hval = hash(key, keylen, time(NULL)); hval &= ht->ht_mask; - list_remove(ht->ht_table[hval], he, he_next); + TAILQ_REMOVE(&ht->ht_table[hval], he, he_next); free(he->he_key); - list_insert_tail(ht->ht_free, he, he_next); + TAILQ_INSERT_TAIL(&ht->ht_free, he, he_next); return (0); } return (-1); ==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/hash.h#2 (text+ko) ==== @@ -27,13 +27,13 @@ #ifndef _HASH_H_ #define _HASH_H_ -#include "list.h" +#include /* * Hash table entry */ struct hashentry { - list_entry(hashentry) he_next; /* Next entry */ + TAILQ_ENTRY(hashentry) he_next; /* Next entry */ void *he_key; /* Key */ size_t he_keylen; /* Key length */ void *he_data; /* Data object pointer */ @@ -43,11 +43,11 @@ * Hash table */ struct hashtbl { - list_head(hashentry) *ht_table; /* Bucket array */ + TAILQ_HEAD(, hashentry) *ht_table; /* Bucket array */ size_t ht_tblsz; /* Size of table */ uint32_t ht_mask; struct hashentry **ht_chunk; /* Chunk array */ - list_head(hashentry) ht_free; /* Free list */ + TAILQ_HEAD(, hashentry) ht_free; /* Free list */ size_t ht_entries; /* Entries per chunk */ size_t ht_chunks; /* Number of chunks */ }; ==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/mdns.h#2 (text+ko) ==== @@ -31,8 +31,8 @@ #include #include #include +#include -#include "list.h" #include "stack_buf.h" /* @@ -62,7 +62,7 @@ #endif uint16_t md_maxpkgsz; /* max (udp) packet size */ struct mdns_bufpool *md_bp; /* buffer pool */ - list_head(mdns_packet) md_pkglist; /* free list */ + TAILQ_HEAD(, mdns_packet) md_pkglist; /* free list */ int md_pkgfree; int md_pkgtotal; }; @@ -82,7 +82,7 @@ struct mdns_packet { uint32_t p_magic; struct mdns_pkgchain *p_pc; - list_entry(mdns_packet) p_list; /* packet list */ + TAILQ_ENTRY(mdns_packet) p_list; /* packet list */ size_t p_len; /* total packet length */ struct mdns_bufhead p_buflist; @@ -117,7 +117,7 @@ typedef int (*md_unlock)(void *); struct mdns_pkgchain { uint32_t pc_magic; - list_head(mdns_packet) pc_head; /* packet list */ + TAILQ_HEAD(, mdns_packet) pc_head; /* packet list */ int pc_list_len; /* packet list length */ int pc_flags; #define MDNS_PC_NONE 0x0 ==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/stack_buf.c#2 (text+ko) ==== @@ -55,8 +55,7 @@ bp->bp_lock = lock; bp->bp_unlock = unlock; bp->bp_lockarg = arg; - list_init(bp->bp_list); - + TAILQ_INIT(&bp->bp_list); return (bp); } @@ -68,14 +67,14 @@ MDNS_BP_LOCK(bp); - while (!list_empty(bp->bp_list)) { - buf = list_first(bp->bp_list); - list_remove_head(bp->bp_list, b_list); + while (!TAILQ_EMPTY(&bp->bp_list)) { + buf = TAILQ_FIRST(&bp->bp_list); + TAILQ_REMOVE(&bp->bp_list, buf, b_list); free(buf->b_buf); free(buf); } - ret = list_empty(bp->bp_list); + ret = TAILQ_EMPTY(&bp->bp_list); MDNS_BP_UNLOCK(bp); if (ret == 1) @@ -115,9 +114,9 @@ buf = NULL; do { - if (!list_empty(bp->bp_list)) { - buf = list_first(bp->bp_list); - list_remove_head(bp->bp_list, b_list); + if (!TAILQ_EMPTY(&bp->bp_list)) { + buf = TAILQ_FIRST(&bp->bp_list); + TAILQ_REMOVE(&bp->bp_list, buf, b_list); bp->bp_buffree--; if (buf->b_sz < bp->bp_defsz) { mdns_buf_free(bp, bh, buf, 1); @@ -143,7 +142,9 @@ } while (buf == NULL); buf->b_len = 0; - list_insert_tail(bh->bh_list, buf, b_list); + if (bh->bh_size == 0) + TAILQ_INIT(&bh->bh_list); + TAILQ_INSERT_TAIL(&bh->bh_list, buf, b_list); bh->bh_size++; if (!locked) @@ -160,10 +161,10 @@ if (!locked) MDNS_BP_LOCK(bp); - list_remove(bh->bh_list, buf, b_list); + TAILQ_REMOVE(&bh->bh_list, buf, b_list); bh->bh_size--; if (!(buf->b_flags & MDNS_BUF_TEMP)) { - list_insert_tail(bp->bp_list, buf, b_list); + TAILQ_INSERT_TAIL(&bp->bp_list, buf, b_list); bp->bp_buffree++; } else { @@ -174,10 +175,10 @@ i = (bp->bp_buffree - 1) / 4; for (; i > 0; i--) { - buf = list_first(bp->bp_list); + buf = TAILQ_FIRST(&bp->bp_list); if (buf == NULL) break; - list_remove_head(bp->bp_list, b_list); + TAILQ_REMOVE(&bp->bp_list, buf, b_list); free(buf->b_buf); free(buf); bp->bp_buftotal--; @@ -200,22 +201,22 @@ struct mdns_bufhead bh2; if (MDNS_BUFHSZ(bh) <= 1) - return (list_first(bh->bh_list)); + return (TAILQ_FIRST(&bh->bh_list)); if (!locked) MDNS_BP_LOCK(bp); len = 0; - list_foreach(bh->bh_list, buf, b_list) { + TAILQ_FOREACH(buf, &bh->bh_list, b_list) { len += MDNS_BUFLEN(buf); } bzero(&bh2, sizeof(struct mdns_bufhead)); buf = mdns_buf_alloc(bp, &bh2, len, 1); - while (!list_empty(bh->bh_list)) { - buf2 = list_first(bh->bh_list); - list_remove_head(bh->bh_list, b_list); + while (!TAILQ_EMPTY(&bh->bh_list)) { + buf2 = TAILQ_FIRST(&bh->bh_list); + TAILQ_REMOVE(&bh->bh_list, buf2, b_list); memcpy(MDNS_BUFPOS(buf), MDNS_BUF(buf2), MDNS_BUFLEN(buf2)); MDNS_BUFLEN(buf) += MDNS_BUFLEN(buf2); mdns_buf_free(bp, bh, buf2, 1); ==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/stack_buf.h#2 (text+ko) ==== @@ -28,13 +28,13 @@ #define _CORE_BUF_H_ #include -#include "list.h" +#include /* * Buffer segment */ struct mdns_buf { - list_entry(mdns_buf) b_list; + TAILQ_ENTRY(mdns_buf) b_list; char *b_buf; /* raw byte buffer */ size_t b_sz; /* buffer size */ size_t b_len; @@ -46,8 +46,8 @@ #define MDNS_BUFSZ(b) (b)->b_sz #define MDNS_BUFLEN(b) (b)->b_len #define MDNS_BUFPOS(b) (((b)->b_buf) + ((b)->b_len)) -#define MDNS_BUFNEXT(b) list_next((b), b_list) -#define MDNS_BUFPREV(b) list_prev((b), b_list) +#define MDNS_BUFNEXT(b) TAILQ_NEXT((b), b_list) +#define MDNS_BUFPREV(b) TAILQ_PREV((b), b_list) /* External buffer pool locking functions */ typedef int (*bp_lock)(void *); @@ -65,7 +65,7 @@ */ struct mdns_bufpool { uint32_t bp_magic; - list_head(mdns_buf) bp_list; /* free list */ + TAILQ_HEAD(, mdns_buf) bp_list; /* free list */ size_t bp_defsz; /* default segment size */ int bp_lim; /* max number of segments */ bp_lock bp_lock; /* external lock function */ @@ -79,12 +79,12 @@ * Buffer consumer */ struct mdns_bufhead { - list_head(mdns_buf) bh_list; /* use list */ + TAILQ_HEAD(, mdns_buf) bh_list; /* use list */ size_t bh_size; /* number of buffer segments in list */ }; #define MDNS_BUFHEAD(bh) (bh)->bh_list -#define MDNS_BUFH(bh) list_first((bh)->bh_list) +#define MDNS_BUFH(bh) TAILQ_FIRST(&(bh)->bh_list) #define MDNS_BUFHSZ(bh) (bh)->bh_size struct mdns_buf * mdns_buf_alloc(struct mdns_bufpool *, ==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/stack_mdns.c#2 (text+ko) ==== @@ -52,8 +52,8 @@ static int mdns_tcp_close(struct mdns *, int); static int mcast_memberctl(int, int, int, int); -#define mcast_join(sock, ifidx, fam) mcast_memberctl(sock, ifidx, fam, 1) -#define mcast_leave(sock, ifidx, fam) mcast_memberctl(sock, ifidx, fam, 0) +#define mcast_join(sock, ifidx, fam) mcast_memberctl(sock, ifidx, fam, 1) +#define mcast_leave(sock, ifidx, fam) mcast_memberctl(sock, ifidx, fam, 0) /* * Create and initialize a MDNS handle required for sending and @@ -103,6 +103,7 @@ strlcpy(req.ifr_name, md->md_ifnam, IFNAMSIZ); sock = socket(IPPROTO_IP, SOCK_DGRAM, 0); error = ioctl(sock, SIOCGIFMTU, &req); + close(sock); /* * IP-header (no options) and UDP-header * XXX: Will there ever be ip-options present in multicast packets? @@ -124,7 +125,8 @@ if (md->md_maxpkgsz > len) mdns_bufpool_setsize(bp, len); - close(sock); + TAILQ_INIT(&md->md_pkglist); + MDNS_INIT_SET(md, md_magic); return (0); error: @@ -598,10 +600,10 @@ msg.msg_control = NULL; msg.msg_controllen = 0; - list_foreach(pc->pc_head, pkg, p_list) { + TAILQ_FOREACH(pkg, &pc->pc_head, p_list) { iov = malloc(sizeof(struct iovec) * MDNS_BUFHSZ(&pkg->p_buflist)); i = 0; - list_foreach(MDNS_BUFHEAD(&pkg->p_buflist), buf, b_list) { + TAILQ_FOREACH(buf, &MDNS_BUFHEAD(&pkg->p_buflist), b_list) { iov[i].iov_base = MDNS_BUF(buf); iov[i].iov_len = MDNS_BUFLEN(buf); i++; @@ -822,10 +824,10 @@ MDNS_INIT_ASSERT(md, md_magic); MDNS_INIT_ASSERT(pc, pc_magic); - list_foreach(pc->pc_head, pkg, p_list) { + TAILQ_FOREACH(pkg, &pc->pc_head, p_list) { iov = malloc(sizeof(struct iovec) * MDNS_BUFHSZ(&pkg->p_buflist)); i = 0; - list_foreach(MDNS_BUFHEAD(&pkg->p_buflist), buf, b_list) { + TAILQ_FOREACH(buf, &MDNS_BUFHEAD(&pkg->p_buflist), b_list) { iov[i].iov_base = MDNS_BUF(buf); iov[i].iov_len = MDNS_BUFLEN(buf); i++; @@ -878,7 +880,7 @@ * Merge buf segments into a continuous area. * This is quite expensive but TCP operations with mdns should be * very rare. TCP operations are only present to provide compability - * with legacy clients. + * with legacy clients. */ buf = mdns_buf_merge(md->md_bp, &pkg->p_buflist, 1); ==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/stack_packet.c#2 (text+ko) ==== @@ -89,9 +89,9 @@ bp = md->md_bp; - if (!list_empty(md->md_pkglist)) { - pkg = list_first(md->md_pkglist); - list_remove(md->md_pkglist, pkg, p_list); + if (!TAILQ_EMPTY(&md->md_pkglist)) { + pkg = TAILQ_FIRST(&md->md_pkglist); + TAILQ_REMOVE(&md->md_pkglist, pkg, p_list); md->md_pkgfree--; } else { @@ -106,7 +106,7 @@ bzero(pkg, sizeof(struct mdns_packet)); mdns_buf_alloc(bp, &pkg->p_buflist, 0, 0); - list_insert_tail(pc->pc_head, pkg, p_list); + TAILQ_INSERT_TAIL(&pc->pc_head, pkg, p_list); pc->pc_pkg = pkg; pc->pc_list_len++; pkg->p_pc = pc; @@ -146,7 +146,7 @@ pc->pc_pkg = NULL; pc->pc_list_len = 0; pc->pc_flags = flags; - list_init(pc->pc_head); + TAILQ_INIT(&pc->pc_head); MDNS_INIT_SET(pc, pc_magic); } @@ -161,9 +161,9 @@ int i; /* Return buffers allocated to this packet */ - while (!list_empty(pkg->p_buflist.bh_list)) { - buf = list_first(pkg->p_buflist.bh_list); - list_remove_head(pkg->p_buflist.bh_list, b_list); + while (!TAILQ_EMPTY(&pkg->p_buflist.bh_list)) { + buf = TAILQ_FIRST(&pkg->p_buflist.bh_list); + TAILQ_REMOVE(&pkg->p_buflist.bh_list, buf, b_list); mdns_buf_free(bp, &pkg->p_buflist, buf, 1); } @@ -193,20 +193,20 @@ MDNS_INIT_ASSERT(pc, pc_magic); - while (!list_empty(pc->pc_head)) { - pkg = list_first(pc->pc_head); - list_remove_head(pc->pc_head, p_list); + while (!TAILQ_EMPTY(&pc->pc_head)) { + pkg = TAILQ_FIRST(&pc->pc_head); + TAILQ_REMOVE(&pc->pc_head, pkg, p_list); free_pkg(pkg, md->md_bp); - list_insert_tail(md->md_pkglist, pkg, p_list); + TAILQ_INSERT_TAIL(&md->md_pkglist, pkg, p_list); md->md_pkgfree++; } i = (md->md_pkgfree - 1) / 2; for (; i > 0; i--) { - pkg = list_first(md->md_pkglist); + pkg = TAILQ_FIRST(&md->md_pkglist); if (pkg == NULL) break; - list_remove_head(md->md_pkglist, p_list); + TAILQ_REMOVE(&md->md_pkglist, pkg, p_list); free(pkg); md->md_pkgtotal--; md->md_pkgfree--; @@ -655,7 +655,7 @@ pkg->p_len += MDNS_QSET_HLEN + namlen; if (pc->pc_flags & MDNS_PC_CONT) - hpkg = list_first(pc->pc_head); + hpkg = TAILQ_FIRST(&pc->pc_head); else hpkg = pkg;