[master] 067662b Prepare for having more than two task queues, by turning them into an array of queues.

Poul-Henning Kamp phk at FreeBSD.org
Tue Jun 9 22:31:25 CEST 2015


commit 067662b568655de3a8e4f940322aee54d678a2fe
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Jun 9 19:59:51 2015 +0000

    Prepare for having more than two task queues, by turning them into
    an array of queues.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 890ebe2..e36d9b7 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -315,7 +315,8 @@ struct pool_task {
 
 enum task_how {
 	TASK_QUEUE_FRONT,
-	TASK_QUEUE_BACK
+	TASK_QUEUE_BACK,
+	TASK_QUEUE_END
 };
 
 /*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c
index f02e594..d3deed2 100644
--- a/bin/varnishd/cache/cache_pool.c
+++ b/bin/varnishd/cache/cache_pool.c
@@ -149,6 +149,7 @@ static struct pool *
 pool_mkpool(unsigned pool_no)
 {
 	struct pool *pp;
+	int i;
 
 	ALLOC_OBJ(pp, POOL_MAGIC);
 	if (pp == NULL)
@@ -160,8 +161,8 @@ pool_mkpool(unsigned pool_no)
 	Lck_New(&pp->mtx, lck_wq);
 
 	VTAILQ_INIT(&pp->idle_queue);
-	VTAILQ_INIT(&pp->front_queue);
-	VTAILQ_INIT(&pp->back_queue);
+	for (i = 0; i < TASK_QUEUE_END; i++)
+		VTAILQ_INIT(&pp->queues[i]);
 	AZ(pthread_cond_init(&pp->herder_cond, NULL));
 	AZ(pthread_create(&pp->herder_thr, NULL, pool_herder, pp));
 
diff --git a/bin/varnishd/cache/cache_pool.h b/bin/varnishd/cache/cache_pool.h
index ea343e6..d3b9e70 100644
--- a/bin/varnishd/cache/cache_pool.h
+++ b/bin/varnishd/cache/cache_pool.h
@@ -43,8 +43,7 @@ struct pool {
 
 	struct lock			mtx;
 	struct taskhead			idle_queue;
-	struct taskhead			front_queue;
-	struct taskhead			back_queue;
+	struct taskhead			queues[TASK_QUEUE_END];
 	unsigned			nthr;
 	unsigned			dry;
 	unsigned			lqueue;
diff --git a/bin/varnishd/cache/cache_wrk.c b/bin/varnishd/cache/cache_wrk.c
index 466b7b9..a76f02b 100644
--- a/bin/varnishd/cache/cache_wrk.c
+++ b/bin/varnishd/cache/cache_wrk.c
@@ -251,13 +251,14 @@ Pool_Task(struct pool *pp, struct pool_task *task, enum task_how how)
 			pp->ndropped++;
 			retval = -1;
 		} else {
-			VTAILQ_INSERT_TAIL(&pp->front_queue, task, list);
+			VTAILQ_INSERT_TAIL(&pp->queues[how], task, list);
 			pp->nqueued++;
 			pp->lqueue++;
 		}
 		break;
 	case TASK_QUEUE_BACK:
-		VTAILQ_INSERT_TAIL(&pp->back_queue, task, list);
+		VTAILQ_INSERT_TAIL(&pp->queues[how], task, list);
+		pp->lqueue++;
 		break;
 	default:
 		WRONG("Unknown enum task_how");
@@ -299,14 +300,13 @@ Pool_Work_Thread(struct pool *pp, struct worker *wrk)
 		WS_Reset(wrk->aws, NULL);
 		AZ(wrk->vsl);
 
-		tp = VTAILQ_FIRST(&pp->front_queue);
-		if (tp != NULL) {
-			pp->lqueue--;
-			VTAILQ_REMOVE(&pp->front_queue, tp, list);
-		} else {
-			tp = VTAILQ_FIRST(&pp->back_queue);
-			if (tp != NULL)
-				VTAILQ_REMOVE(&pp->back_queue, tp, list);
+		for (i = 0; i < TASK_QUEUE_END; i++) {
+			tp = VTAILQ_FIRST(&pp->queues[i]);
+			if (tp != NULL) {
+				pp->lqueue--;
+				VTAILQ_REMOVE(&pp->queues[i], tp, list);
+				break;
+			}
 		}
 
 		if ((tp == NULL && wrk->stats->summs > 0) ||



More information about the varnish-commit mailing list