From owner-p4-projects@FreeBSD.ORG Sun Aug 5 18:26:43 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 098BC16A419; Sun, 5 Aug 2007 18:26:43 +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 8E8BE16A420 for ; Sun, 5 Aug 2007 18:26:42 +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 89D5613C45B for ; Sun, 5 Aug 2007 18:26:42 +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 l75IQg2i040331 for ; Sun, 5 Aug 2007 18:26:42 GMT (envelope-from fli@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l75IQg3V040328 for perforce@freebsd.org; Sun, 5 Aug 2007 18:26:42 GMT (envelope-from fli@FreeBSD.org) Date: Sun, 5 Aug 2007 18:26:42 GMT Message-Id: <200708051826.l75IQg3V040328@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 124743 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: Sun, 05 Aug 2007 18:26:43 -0000 http://perforce.freebsd.org/chv.cgi?CH=124743 Change 124743 by fli@fli_nexus on 2007/08/05 18:26:22 - Fix a bug which caused the output engine to remain active after the queue had been destroyed. - Use the global object allocator to allocate queue entries. Affected files ... .. //depot/projects/soc2007/fli-mdns_sd/mdnsd/output.c#2 edit .. //depot/projects/soc2007/fli-mdns_sd/mdnsd/output.h#2 edit Differences ... ==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/output.c#2 (text+ko) ==== @@ -54,7 +54,6 @@ MDNS_INIT_SET(oq, oq_magic); oq->oq_mif = mif; TAILQ_INIT(&oq->oq_queue); - TAILQ_INIT(&oq->oq_free); oq->oq_flags = 0; MTX_INIT(oq, oq_mtx, NULL); #ifdef HAVE_PTHREAD @@ -70,7 +69,7 @@ void oq_destroy(struct oqueue *oq) { - struct oq_entry *oqe, *oqe2; + struct oq_entry *oqe; struct md_if *mif; MDNS_INIT_ASSERT(oq, oq_magic); @@ -80,28 +79,23 @@ #ifdef HAVE_PTHREAD MTX_LOCK(oq, oq_mtx); oq->oq_flags |= OQ_DRAIN; + if (oq->oq_flags & OQ_ACTIVE) { pthread_cond_signal(&oq->oq_cond); - MTX_UNLOCK(oq, oq_mtx); pthread_cond_wait(&oq->oq_cond, &oq->oq_mtx); - TAILQ_FOREACH_SAFE(oqe, &oq->oq_queue, oqe_next, oqe2) { - MDNS_INIT_ASSERT(oqe, oqe_magic); + while (!TAILQ_EMPTY(&oq->oq_queue)) { + oqe = TAILQ_FIRST(&oq->oq_queue); TAILQ_REMOVE(&oq->oq_queue, oqe, oqe_next); mdns_pkgchain_free(&oqe->oqe_pc); - free(oqe); - } - TAILQ_FOREACH_SAFE(oqe, &oq->oq_free, oqe_next, oqe2) { - MDNS_INIT_ASSERT(oqe, oqe_magic); - TAILQ_REMOVE(&oq->oq_free, oqe, oqe_next); - free(oqe); + obj_free(OBJ_OQE, oqe); } } pthread_cond_destroy(&oq->oq_cond); #endif MDNS_INIT_UNSET(oq, oq_magic); + MTX_UNLOCK(oq, oq_mtx); MTX_DESTROY(oq, oq_mtx); - MTX_UNLOCK(oq, oq_mtx); dprintf(DEBUG_SEND, "Output queue oq=%x destroyed", oq); } @@ -123,6 +117,8 @@ wq_arg arg; MDNS_INIT_ASSERT(oq, oq_magic); + if (oq->oq_flags & OQ_DRAIN) + return; oqe = obj_alloc(OBJ_OQE); oqe->oqe_fam = family; @@ -185,11 +181,16 @@ MDNS_INIT_ASSERT(oq, oq_magic); mif = oq->oq_mif; MDNS_INIT_ASSERT(mif, mif_magic) + if (oq->oq_flags & OQ_DRAIN) + return (0); + dprintf(DEBUG_SEND, "Output queue %x engine started", oq); MTX_LOCK(oq, oq_mtx); for (;;) { while (!TAILQ_EMPTY(&oq->oq_queue)) { + if (oq->oq_flags & OQ_DRAIN) + break; oqe = TAILQ_FIRST(&oq->oq_queue); TAILQ_REMOVE(&oq->oq_queue, oqe, oqe_next); @@ -207,16 +208,21 @@ mdns_pkgchain_free(&oqe->oqe_pc); obj_free(OBJ_OQE, oqe); } + if (oq->oq_flags & OQ_DRAIN) + break; clock_gettime(CLOCK_REALTIME, &ts); ts.tv_sec += 60; error = pthread_cond_timedwait(&oq->oq_cond, &oq->oq_mtx, &ts); - if (error == ETIMEDOUT || (oq->oq_flags & OQ_DRAIN)) + if (error == ETIMEDOUT) break; } oq->oq_flags &= ~OQ_ACTIVE; MTX_UNLOCK(oq, oq_mtx); + if (oq->oq_flags & OQ_DRAIN) { + pthread_cond_signal(&oq->oq_cond); + } dprintf(DEBUG_SEND, "Output queue %x engine stopped", oq); return (0); } ==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/output.h#2 (text+ko) ==== @@ -52,7 +52,6 @@ MAGIC(oq_magic); struct md_if *oq_mif; TAILQ_HEAD(, oq_entry) oq_queue; /* Entries in queue */ - TAILQ_HEAD(, oq_entry) oq_free; /* Free, pre-allocated entries */ int oq_flags; #define OQ_ACTIVE 0x01 #define OQ_DRAIN 0x02