From d3cd7eb03da9459b7c5528cc9f1b70fc80481ec7 Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Mon, 31 Jul 1995 20:02:53 +0000 Subject: (connq_compress): New function. (connq_interrupt_sock): Use connq_compress to compress the queue. --- pflocal/connq.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'pflocal') diff --git a/pflocal/connq.c b/pflocal/connq.c index 8f06ba29..fc7d2700 100644 --- a/pflocal/connq.c +++ b/pflocal/connq.c @@ -250,6 +250,28 @@ debug (&req, "(req) unlock"); return err; } +/* `Compresses' CQ, by removing any NULL entries. CQ should be locked. */ +static void +connq_compress (struct connq *cq) +{ + unsigned pos; + unsigned comp_tail = cq->head; + +debug (cq, "compress queue"); + /* Now compress the queue to remove any null entries we put in. */ + for (pos = cq->head; pos != cq->tail; pos = qnext (cq, pos)) + if (cq->queue[pos] != NULL) + /* This position has a non-NULL request, so move it to the end of the + compressed queue. */ + { + cq->queue[comp_tail] = cq->queue[pos]; + comp_tail = qnext (cq, comp_tail); + } + + /* Move back tail to only include what we kept in the queue. */ + cq->tail = comp_tail; +} + /* Interrupt any threads waiting on CQ, both listeners and connectors, and make them return with EINTR. */ void @@ -286,7 +308,7 @@ debug (cq, "out"); void connq_interrupt_sock (struct connq *cq, struct sock *sock) { - unsigned pos, comp_tail; + unsigned pos; debug (cq, "in"); debug (cq, "lock"); @@ -303,21 +325,7 @@ debug (cq, "interrupt connections from: %p", sock); cq->queue[pos] = NULL; /* Mark REQ as being deleted. */ } -debug (cq, "compress queue"); - /* Now compress the queue to remove any null entries we put in. */ - for (pos = cq->head, comp_tail = cq->head; - pos != cq->tail; - pos = qnext (cq, pos)) - if (cq->queue[pos] != NULL) - /* This position has a non-NULL request, so move it to the end of the - compressed queue. */ - { - cq->queue[comp_tail] = cq->queue[pos]; - comp_tail = qnext (cq, comp_tail); - } - - /* Move back tail to only include what we kept in the queue. */ - cq->tail = comp_tail; + connq_compress (cq); debug (cq, "unlock"); mutex_unlock (&cq->lock); -- cgit v1.2.3