PERFORCE change 124743 for review
Fredrik Lindberg
fli at FreeBSD.org
Sun Aug 5 11:26:43 PDT 2007
http://perforce.freebsd.org/chv.cgi?CH=124743
Change 124743 by fli at 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
More information about the p4-projects
mailing list