Commit 89e55c96 authored by Mark Andrews's avatar Mark Andrews

use a pending queue

parent 8939b32f
...@@ -358,7 +358,7 @@ struct workitem { ...@@ -358,7 +358,7 @@ struct workitem {
struct workitem *next; struct workitem *next;
struct workitem *prev; struct workitem *prev;
int linked; int linked;
} link, clink, rlink, idlink; } link, clink, plink, rlink, idlink;
unsigned short id; /* the query id we are waiting for */ unsigned short id; /* the query id we are waiting for */
struct timeval when; /* when we will timeout */ struct timeval when; /* when we will timeout */
int type; /* the query type being looked up */ int type; /* the query type being looked up */
...@@ -381,6 +381,7 @@ struct workitem { ...@@ -381,6 +381,7 @@ struct workitem {
* 'work' udp qeries; * 'work' udp qeries;
* 'connecting' tcp qeries; * 'connecting' tcp qeries;
* 'reading' tcp qeries; * 'reading' tcp qeries;
* 'pending' deferred work items;
* *
* Outstanding queries by qid. * Outstanding queries by qid.
* 'ids' * 'ids'
...@@ -388,7 +389,7 @@ struct workitem { ...@@ -388,7 +389,7 @@ struct workitem {
static struct { static struct {
struct workitem *head; struct workitem *head;
struct workitem *tail; struct workitem *tail;
} work, connecting, reading, ids[0x10000]; } work, connecting, reading, pending, ids[0x10000];
static void static void
dotest(struct workitem *item); dotest(struct workitem *item);
...@@ -734,6 +735,8 @@ freeitem(struct workitem * item) { ...@@ -734,6 +735,8 @@ freeitem(struct workitem * item) {
outstanding--; outstanding--;
if (LINKED(item, link)) if (LINKED(item, link))
UNLINK(work, item, link); UNLINK(work, item, link);
if (LINKED(item, plink))
UNLINK(pending, item, plink);
if (LINKED(item, rlink)) if (LINKED(item, rlink))
UNLINK(reading, item, rlink); UNLINK(reading, item, rlink);
if (LINKED(item, clink)) if (LINKED(item, clink))
...@@ -779,8 +782,9 @@ resend(struct workitem *item) { ...@@ -779,8 +782,9 @@ resend(struct workitem *item) {
if (outstanding > maxoutstanding) { if (outstanding > maxoutstanding) {
gettimeofday(&item->when, NULL); gettimeofday(&item->when, NULL);
item->when.tv_sec += 1; item->when.tv_sec += 1;
UNLINK(work, item, link); if (LINKED(item, link))
APPEND(work, item, link); UNLINK(work, item, link);
APPEND(pending, item, plink);
return; return;
} }
...@@ -801,7 +805,8 @@ resend(struct workitem *item) { ...@@ -801,7 +805,8 @@ resend(struct workitem *item) {
gettimeofday(&item->when, NULL); gettimeofday(&item->when, NULL);
item->when.tv_sec += 1; item->when.tv_sec += 1;
item->sends++; item->sends++;
UNLINK(work, item, link); if (LINKED(item, link))
UNLINK(work, item, link);
APPEND(work, item, link); APPEND(work, item, link);
} else if (item->summary->type) { } else if (item->summary->type) {
nextserver(item); nextserver(item);
...@@ -947,7 +952,7 @@ dotest(struct workitem *item) { ...@@ -947,7 +952,7 @@ dotest(struct workitem *item) {
if (outstanding > maxoutstanding) { if (outstanding > maxoutstanding) {
gettimeofday(&item->when, NULL); gettimeofday(&item->when, NULL);
item->when.tv_sec += 1; item->when.tv_sec += 1;
APPEND(work, item, link); APPEND(pending, item, plink);
APPEND(ids[item->id], item, idlink); APPEND(ids[item->id], item, idlink);
return; return;
} }
...@@ -1168,7 +1173,7 @@ dolookup(struct workitem *item, int type) { ...@@ -1168,7 +1173,7 @@ dolookup(struct workitem *item, int type) {
if (outstanding > maxoutstanding) { if (outstanding > maxoutstanding) {
gettimeofday(&item->when, NULL); gettimeofday(&item->when, NULL);
item->when.tv_sec += 1; item->when.tv_sec += 1;
APPEND(work, item, link); APPEND(pending, item, plink);
APPEND(ids[item->id], item, idlink); APPEND(ids[item->id], item, idlink);
return; return;
} }
...@@ -2344,6 +2349,17 @@ main(int argc, char **argv) { ...@@ -2344,6 +2349,17 @@ main(int argc, char **argv) {
ritem = HEAD(reading); ritem = HEAD(reading);
} }
/*
* If we have space for pending items do them now.
*/
for (;;) {
item = HEAD(pending);
if (item == NULL || outstanding > maxoutstanding)
break;
UNLINK(pending, item, plink);
resend(item);
}
/* /*
* New items may have been added as the result of * New items may have been added as the result of
* calling freeitem when sending requests serially. * calling freeitem when sending requests serially.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment