summaryrefslogtreecommitdiff
path: root/pflocal/connq.c
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1995-07-31 20:02:53 +0000
committerMiles Bader <miles@gnu.org>1995-07-31 20:02:53 +0000
commitd3cd7eb03da9459b7c5528cc9f1b70fc80481ec7 (patch)
treed0834a851f360615123227434904e01501eb56af /pflocal/connq.c
parentdc095770749d83d948f8bd294226c79a91f30256 (diff)
(connq_compress): New function.
(connq_interrupt_sock): Use connq_compress to compress the queue.
Diffstat (limited to 'pflocal/connq.c')
-rw-r--r--pflocal/connq.c40
1 files changed, 24 insertions, 16 deletions
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);